4331: Display Media size before quick backup, in stats gramplet, and summary report

svn: r16247
This commit is contained in:
Doug Blank 2010-12-05 05:54:33 +00:00
parent 79f6646555
commit 915dfc3913
3 changed files with 42 additions and 15 deletions

View File

@ -43,6 +43,7 @@ from gen.ggettext import ngettext
from cStringIO import StringIO from cStringIO import StringIO
from collections import defaultdict from collections import defaultdict
import sys import sys
import posixpath
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
@ -1444,12 +1445,26 @@ class ViewManager(CLIManager):
hbox.pack_end(file_entry, True) hbox.pack_end(file_entry, True)
vbox.pack_start(hbox, False) vbox.pack_start(hbox, False)
hbox = gtk.HBox() hbox = gtk.HBox()
bytes = 0
mbytes = "0"
for media in self.dbstate.db.iter_media_objects():
fullname = Utils.media_path_full(self.dbstate.db, media.get_path())
try:
bytes += posixpath.getsize(fullname)
length = len(str(bytes))
if bytes <= 99999:
mbytes = "< 1"
else:
mbytes = str(bytes)[:(length-6)]
label = gtk.Label(_("Media:"))
except OSError:
label = gtk.Label(_("Media:")) label = gtk.Label(_("Media:"))
label.set_justify(gtk.JUSTIFY_LEFT) label.set_justify(gtk.JUSTIFY_LEFT)
label.set_size_request(90, -1) label.set_size_request(90, -1)
label.set_alignment(0, .5) label.set_alignment(0, .5)
hbox.pack_start(label, False) hbox.pack_start(label, False)
include = gtk.RadioButton(None, _("Include")) include = gtk.RadioButton(None, "%s (%s %s)" % (_("Include"),
mbytes, _("MB")))
exclude = gtk.RadioButton(include, _("Exclude")) exclude = gtk.RadioButton(include, _("Exclude"))
include.connect("toggled", lambda widget: self.media_toggle(widget, file_entry)) include.connect("toggled", lambda widget: self.media_toggle(widget, file_entry))
hbox.pack_start(include, True) hbox.pack_start(include, True)

View File

@ -71,8 +71,8 @@ class StatsGramplet(Gramplet):
database = self.dbstate.db database = self.dbstate.db
personList = database.iter_people() personList = database.iter_people()
with_photos = 0 with_media = 0
total_photos = 0 total_media = 0
incomp_names = 0 incomp_names = 0
disconnected = 0 disconnected = 0
missing_bday = 0 missing_bday = 0
@ -83,19 +83,25 @@ class StatsGramplet(Gramplet):
namelist = [] namelist = []
notfound = [] notfound = []
pobjects = database.get_number_of_media_objects() mobjects = database.get_number_of_media_objects()
for photo in database.iter_media_objects(): mbytes = "0"
fullname = media_path_full(database, photo.get_path()) for media in database.iter_media_objects():
fullname = media_path_full(database, media.get_path())
try: try:
bytes += posixpath.getsize(fullname) bytes += posixpath.getsize(fullname)
length = len(str(bytes))
if bytes <= 99999:
mbytes = "less than 1"
else:
mbytes = str(bytes)[:(length-6)]
except OSError: except OSError:
notfound.append(photo.get_path()) notfound.append(media.get_path())
for cnt, person in enumerate(personList): for cnt, person in enumerate(personList):
length = len(person.get_media_list()) length = len(person.get_media_list())
if length > 0: if length > 0:
with_photos += 1 with_media += 1
total_photos += length total_media += length
names = [person.get_primary_name()] + person.get_alternate_names() names = [person.get_primary_name()] + person.get_alternate_names()
for name in names: for name in names:
@ -168,20 +174,20 @@ class StatsGramplet(Gramplet):
self.append_text("----------------------------\n") self.append_text("----------------------------\n")
self.link("%s:" % _("Individuals with media objects"), self.link("%s:" % _("Individuals with media objects"),
'Filter', 'people with media') 'Filter', 'people with media')
self.append_text(" %s" % with_photos) self.append_text(" %s" % with_media)
self.append_text("\n") self.append_text("\n")
self.link("%s:" % _("Total number of media object references"), self.link("%s:" % _("Total number of media object references"),
'Filter', 'media references') 'Filter', 'media references')
self.append_text(" %s" % total_photos) self.append_text(" %s" % total_media)
self.append_text("\n") self.append_text("\n")
self.link("%s:" % _("Number of unique media objects"), self.link("%s:" % _("Number of unique media objects"),
'Filter', 'unique media') 'Filter', 'unique media')
self.append_text(" %s" % pobjects) self.append_text(" %s" % mobjects)
self.append_text("\n") self.append_text("\n")
self.link("%s:" % _("Total size of media objects"), self.link("%s:" % _("Total size of media objects"),
'Filter', 'media by size') 'Filter', 'media by size')
self.append_text(" %d %s" % (bytes, _("bytes"))) self.append_text(" %s %s" % (mbytes, _("MB")))
self.append_text("\n") self.append_text("\n")
self.link("%s:" % _("Missing Media Objects"), self.link("%s:" % _("Missing Media Objects"),
'Filter', 'missing media') 'Filter', 'missing media')

View File

@ -206,11 +206,17 @@ class SummaryReport(Report):
self.doc.end_paragraph() self.doc.end_paragraph()
total_media = len(self.__db.get_media_object_handles()) total_media = len(self.__db.get_media_object_handles())
mbytes = "0"
for media_id in self.__db.get_media_object_handles(): for media_id in self.__db.get_media_object_handles():
media = self.__db.get_object_from_handle(media_id) media = self.__db.get_object_from_handle(media_id)
try: try:
size_in_bytes += posixpath.getsize( size_in_bytes += posixpath.getsize(
media_path_full(self.__db, media.get_path())) media_path_full(self.__db, media.get_path()))
length = len(str(size_in_bytes))
if size_in_bytes <= 99999:
mbytes = "less than 1"
else:
mbytes = str(size_in_bytes)[:(length-6)]
except: except:
notfound.append(media.get_path()) notfound.append(media.get_path())
@ -220,7 +226,7 @@ class SummaryReport(Report):
self.doc.end_paragraph() self.doc.end_paragraph()
self.doc.start_paragraph("SR-Normal") self.doc.start_paragraph("SR-Normal")
self.doc.write_text(_("Total size of media objects: %d bytes") % size_in_bytes) self.doc.write_text(_("Total size of media objects: %s MB") % mbytes)
self.doc.end_paragraph() self.doc.end_paragraph()
if len(notfound) > 0: if len(notfound) > 0: