Refinements on previous commit; new filter by name 'media by size'

svn: r10190
This commit is contained in:
Doug Blank 2008-03-05 04:34:28 +00:00
parent e63589a044
commit 671891b816
3 changed files with 25 additions and 7 deletions

View File

@ -174,7 +174,7 @@ class SimpleTable:
# FIXME: add better text representations of these objects
if type(item) in [str, unicode]:
retval.append(item)
elif type(item) in [int, float]:
elif type(item) in [int, float, long]:
retval.append(item)
self.row_sort_val(col, item)
elif isinstance(item, gen.lib.Person):

View File

@ -19,6 +19,7 @@
import sys
import re
import urllib
import posixpath
import gen.lib
from DataViews import register, Gramplet
@ -550,6 +551,7 @@ class PedigreeGramplet(Gramplet):
class StatsGramplet(Gramplet):
def init(self):
self.set_text(_("No Family Tree loaded."))
self.tooltip = _("Double-click item to see matches")
def db_changed(self):
self.dbstate.db.connect('person-add', self.update)
@ -674,12 +676,14 @@ class StatsGramplet(Gramplet):
'Filter', 'unique media')
self.append_text(" %s" % pobjects)
self.append_text("\n")
self.append_text("%s: %d %s\n" % (_("Total size of media objects"),
bytes,
_("bytes")))
self.link("%s:" % _("Total size of media objects"),
'Filter', 'media by size')
self.append_text(" %d %s" % (bytes, _("bytes")))
self.append_text("\n")
self.link("%s:" % _("Missing Media Objects"),
'Filter', 'missing media')
self.append_text(" %s\n" % total_photos)
self.append_text(" %s\n" % len(notfound))
self.append_text("", scroll_to="begin")
class PythonGramplet(Gramplet):

View File

@ -24,13 +24,15 @@ Display filtered data
"""
from Simple import SimpleAccess, SimpleDoc, SimpleTable
from gettext import gettext as _
from PluginUtils import register_quick_report
from Utils import media_path_full
from QuickReports import run_quick_report_by_name_direct
from gen.lib import Person
import DateHandler
import posixpath
from gettext import gettext as _
def run(database, document, filter_name):
"""
Loops through the families that the person is a child in, and display
@ -182,10 +184,22 @@ def run(database, document, filter_name):
photo = database.get_object_from_handle(photo_id)
fullname = media_path_full(database, photo.get_path())
try:
bytes = bytes + posixpath.getsize(fullname)
posixpath.getsize(fullname)
except:
stab.row(fullname)
matches += 1
elif (filter_name == 'media by size'):
stab.columns(_("Media"), _("Size in bytes"))
pobjects = database.get_media_object_handles()
for photo_id in database.get_media_object_handles():
photo = database.get_object_from_handle(photo_id)
fullname = media_path_full(database, photo.get_path())
try:
bytes = posixpath.getsize(fullname)
stab.row(fullname, bytes)
matches += 1
except:
pass
else:
raise AttributeError, ("invalid filter name: '%s'" % filter_name)
sdoc.paragraph(_("Filter matched %d records.") % matches)