diff --git a/gramps/plugins/docgen/htmldoc.py b/gramps/plugins/docgen/htmldoc.py index 4a46d5afc..b946cc758 100644 --- a/gramps/plugins/docgen/htmldoc.py +++ b/gramps/plugins/docgen/htmldoc.py @@ -168,7 +168,7 @@ class HtmlDoc(BaseDoc, TextDoc): text = [] - for sname in styles.get_cell_style_names(): + for sname in sorted(styles.get_cell_style_names()): style = styles.get_cell_style(sname) pad = "%.3fcm" % style.get_padding() top = bottom = left = right = 'none' @@ -188,7 +188,7 @@ class HtmlDoc(BaseDoc, TextDoc): left, right)) - for style_name in styles.get_paragraph_style_names(): + for style_name in sorted(styles.get_paragraph_style_names()): style = styles.get_paragraph_style(style_name) font = style.get_font() font_size = font.get_size() diff --git a/gramps/plugins/webreport/narrativeweb.py b/gramps/plugins/webreport/narrativeweb.py index 7560244b4..3d0888de1 100644 --- a/gramps/plugins/webreport/narrativeweb.py +++ b/gramps/plugins/webreport/narrativeweb.py @@ -12,7 +12,7 @@ # Copyright (C) 2008-2011 Rob G. Healey # Copyright (C) 2010 Doug Blank # Copyright (C) 2010 Jakim Friant -# Copyright (C) 2010 Serge Noiraud +# Copyright (C) 2010,2015 Serge Noiraud # Copyright (C) 2011 Tim G L Lyons # Copyright (C) 2013 Benny Malengier # @@ -543,11 +543,12 @@ def copy_thumbnail(report, handle, photo, region=None): ) if photo.get_mime_type(): - from_path = get_thumbnail_path(media_path_full( - report.database, - photo.get_path()), - photo.get_mime_type(), - region) + full_path = media_path_full(report.database, photo.get_path()) + from_path = get_thumbnail_path(full_path, + photo.get_mime_type(), + region) + mtime = os.stat(full_path).st_mtime + os.utime(from_path, (mtime, mtime)) if not os.path.isfile(from_path): from_path = CSS["Document"]["filename"] else: @@ -1573,7 +1574,7 @@ class BasePage(object): self.dump_attribute(attr) for attr in attrlist ) - def write_footer(self): + def write_footer(self, date): """ Will create and display the footer section of each page... @@ -1602,6 +1603,10 @@ class BasePage(object): 'html_end' : '' , 'version' : VERSION , 'date' : _dd.display(Today()) } + if date is not None: + msg += "
" + last_modif = datetime.datetime.fromtimestamp(date).strftime('%Y-%m-%d %H:%M:%S') + msg += _('Last change was the %(date)s') % { 'date' : last_modif } # optional "link-home" feature; see bug report #2736 if self.report.options['linkhome']: @@ -2831,7 +2836,7 @@ class BasePage(object): # --------------------------------------------------------------------------------------- # # Web Page Fortmatter and writer # --------------------------------------------------------------------------------------- - def XHTMLWriter(self, htmlinstance, of, sio): + def XHTMLWriter(self, htmlinstance, of, sio, date): """ Will format, write, and close the file @@ -2843,7 +2848,7 @@ class BasePage(object): htmlinstance.write(partial(print, file=of)) # closes the file - self.report.close_file(of, sio) + self.report.close_file(of, sio, date) ################################################# # @@ -2871,6 +2876,7 @@ class SurnamePage(BasePage): of, sio = self.report.create_file(name_to_md5(surname), "srn") self.up = True surnamepage, head, body = self.write_header("%s - %s" % (_("Surname"), surname)) + ldatec = 0 # begin SurnameDetail division with Html("div", class_ = "content", id = "SurnameDetail") as surnamedetail: @@ -2918,6 +2924,7 @@ class SurnamePage(BasePage): for person_handle in ppl_handle_list: person = self.dbase_.get_person_from_handle(person_handle) + if person.get_change_time() > ldatec: ldatec = person.get_change_time() trow = Html("tr") tbody += trow @@ -3003,12 +3010,12 @@ class SurnamePage(BasePage): # add clearline for proper styling # add footer section - footer = self.write_footer() + footer = self.write_footer(ldatec) body += (fullclear, footer) # send page out for processing # and close the file - self.XHTMLWriter(surnamepage, of, sio) + self.XHTMLWriter(surnamepage, of, sio, ldatec) ################################################# # @@ -3057,6 +3064,7 @@ class FamilyPages(BasePage): of, sio = self.report.create_file("families") familiesListPage, head, body = self.write_header(_("Families")) + ldatec = 0 # begin Family Division with Html("div", class_ ="content", id ="Relationships") as relationlist: @@ -3079,6 +3087,7 @@ class FamilyPages(BasePage): for family_handle in fam_list: family = self.dbase_.get_family_from_handle(family_handle) if family: + if family.get_change_time() > ldatec: ldatec = family.get_change_time() husband_handle = family.get_father_handle() spouse_handle = family.get_mother_handle() if husband_handle: @@ -3200,12 +3209,13 @@ class FamilyPages(BasePage): # add clearline for proper styling # add footer section - footer = self.write_footer() + if ldatec == 0: date = None + footer = self.write_footer(ldatec) body += (fullclear, footer) # send page out for processing # and close the file - self.XHTMLWriter(familiesListPage, of, sio) + self.XHTMLWriter(familiesListPage, of, sio, ldatec) def FamilyPage(self, report, title, family_handle): self.dbase_ = report.database @@ -3213,6 +3223,7 @@ class FamilyPages(BasePage): if not family: return BasePage.__init__(self, report, title, family.get_gramps_id()) + ldatec = family.get_change_time() self.bibli = Bibliography() self.up = True @@ -3283,12 +3294,12 @@ class FamilyPages(BasePage): # add clearline for proper styling # add footer section - footer = self.write_footer() + footer = self.write_footer(ldatec) body += (fullclear, footer) # send page out for processing # and close the file - self.XHTMLWriter(familydetailpage, of, sio) + self.XHTMLWriter(familydetailpage, of, sio, ldatec) ###################################################### # # @@ -3338,6 +3349,7 @@ class PlacePages(BasePage): of, sio = self.report.create_file("places") placelistpage, head, body = self.write_header(_("Places")) + ldatec = 0 # begin places division with Html("div", class_ = "content", id = "Places") as placelist: @@ -3389,6 +3401,7 @@ class PlacePages(BasePage): for place_handle in handle_list: place = self.dbase_.get_place_from_handle(place_handle) if place: + if place.get_change_time() > ldatec: ldatec = place.get_change_time() place_title = _pd.display(self.dbase_, place) ml = get_main_location(self.dbase_, place) @@ -3440,12 +3453,12 @@ class PlacePages(BasePage): # add clearline for proper styling # add footer section - footer = self.write_footer() + footer = self.write_footer(ldatec) body += (fullclear, footer) # send page out for processing # and close the file - self.XHTMLWriter(placelistpage, of, sio) + self.XHTMLWriter(placelistpage, of, sio, ldatec) def PlacePage(self, report, title, place_handle): self.bibli = Bibliography() @@ -3453,6 +3466,7 @@ class PlacePages(BasePage): place = self.dbase_.get_place_from_handle(place_handle) if not place: return None + ldatec = place.get_change_time() BasePage.__init__(self, report, title, place.get_gramps_id()) of, sio = self.report.create_file(place_handle, "plc") @@ -3561,12 +3575,12 @@ class PlacePages(BasePage): # add clearline for proper styling # add footer section - footer = self.write_footer() + footer = self.write_footer(ldatec) body += (fullclear, footer) # send page out for processing # and close the file - self.XHTMLWriter(placepage, of, sio) + self.XHTMLWriter(placepage, of, sio, ldatec) ################################################# # @@ -3624,6 +3638,7 @@ class EventPages(BasePage): """ self.dbase_ = report.database BasePage.__init__(self, report, title) + ldatec = 0 of, sio = self.report.create_file("events") eventslistpage, head, body = self.write_header(_("Events")) @@ -3681,6 +3696,7 @@ class EventPages(BasePage): event = self.dbase_.get_event_from_handle(event_handle) _type = event.get_type() gid = event.get_gramps_id() + if event.get_change_time() > ldatec: ldatec = event.get_change_time() # check to see if we have listed this gramps_id yet? if gid not in _EVENT_DISPLAYED: @@ -3761,12 +3777,13 @@ class EventPages(BasePage): # add clearline for proper styling # add footer section - footer = self.write_footer() + if ldatec == 0: ldatec = None + footer = self.write_footer(ldatec) body += (fullclear, footer) # send page ut for processing # and close the file - self.XHTMLWriter(eventslistpage, of, sio) + self.XHTMLWriter(eventslistpage, of, sio, ldatec) def _getEventDate(self, event_handle): event_date = Date.EMPTY @@ -3804,6 +3821,7 @@ class EventPages(BasePage): if not event: return None + ldatec = event.get_change_time() event_media_list = event.get_media_list() BasePage.__init__(self, report, title, event.get_gramps_id()) @@ -3887,12 +3905,12 @@ class EventPages(BasePage): # add clearline for proper styling # add footer section - footer = self.write_footer() + footer = self.write_footer(ldatec) body += (fullclear, footer) # send page out for processing # and close the page - self.XHTMLWriter(eventpage, of, sio) + self.XHTMLWriter(eventpage, of, sio, ldatec) ################################################# # @@ -4021,12 +4039,12 @@ class SurnameListPage(BasePage): # create footer section # add clearline for proper styling - footer = self.write_footer() + footer = self.write_footer(None) body += (fullclear, footer) # send page out for processing # and close the file - self.XHTMLWriter(surnamelistpage, of, sio) + self.XHTMLWriter(surnamelistpage, of, sio, None) # None => current date modification def surname_link(self, fname, name, opt_val = None, up = False): url = self.report.build_url_fname_html(fname, "srn", up) @@ -4041,6 +4059,7 @@ class IntroductionPage(BasePage): def __init__(self, report, title): self.dbase_ = report.database BasePage.__init__(self, report, title) + ldatec = None of, sio = self.report.create_file(report.intro_fname) intropage, head, body = self.write_header(_('Introduction')) @@ -4061,19 +4080,23 @@ class IntroductionPage(BasePage): # attach note section += note_text + # last modification of this note + ldatec = note.get_change_time() + # add clearline for proper styling # create footer section - footer = self.write_footer() + footer = self.write_footer(ldatec) body += (fullclear, footer) # send page out for processing # and close the file - self.XHTMLWriter(intropage, of, sio) + self.XHTMLWriter(intropage, of, sio, ldatec) class HomePage(BasePage): def __init__(self, report, title): self.dbase_ = report.database BasePage.__init__(self, report, title) + ldatec = None of, sio = self.report.create_file("index") homepage, head, body = self.write_header(_('Home')) @@ -4094,14 +4117,17 @@ class HomePage(BasePage): # attach note section += note_text + # last modification of this note + ldatec = note.get_change_time() + # create clear line for proper styling # create footer section - footer = self.write_footer() + footer = self.write_footer(ldatec) body += (fullclear, footer) # send page out for processing # and close the file - self.XHTMLWriter(homepage, of, sio) + self.XHTMLWriter(homepage, of, sio, ldatec) ################################################# # @@ -4231,12 +4257,12 @@ class SourcePages(BasePage): # add clearline for proper styling # add footer section - footer = self.write_footer() + footer = self.write_footer(None) body += (fullclear, footer) # send page out for processing # and close the file - self.XHTMLWriter(sourcelistpage, of, sio) + self.XHTMLWriter(sourcelistpage, of, sio, None) def SourcePage(self, report, title, source_handle): """ @@ -4262,6 +4288,7 @@ class SourcePages(BasePage): sourcepage, head, body = self.write_header("%s - %s" % (_('Sources'), self.page_title)) + ldatec = None # begin source detail division with Html("div", class_ = "content", id = "SourceDetail") as sourcedetail: body += sourcedetail @@ -4286,6 +4313,9 @@ class SourcePages(BasePage): if not self.noid and self.gid: source_gid = source.get_gramps_id() + # last modification of this source + ldatec = source.get_change_time() + for (label, value) in [ (_("Gramps ID"), source_gid), (_("Author"), source.get_author()), @@ -4327,12 +4357,12 @@ class SourcePages(BasePage): # add clearline for proper styling # add footer section - footer = self.write_footer() + footer = self.write_footer(ldatec) body += (fullclear, footer) # send page out for processing # and close the file - self.XHTMLWriter(sourcepage, of, sio) + self.XHTMLWriter(sourcepage, of, sio, ldatec) ################################################# # @@ -4398,6 +4428,7 @@ class MediaPages(BasePage): of, sio = self.report.create_file("media") medialistpage, head, body = self.write_header(_('Media')) + ldatec = 0 # begin gallery division with Html("div", class_ = "content", id = "Gallery") as medialist: body += medialist @@ -4440,6 +4471,7 @@ class MediaPages(BasePage): for media_handle in sorted_media_handles: media = self.dbase_.get_object_from_handle(media_handle) if media: + if media.get_change_time() > ldatec: ldatec = media.get_change_time() title = media.get_description() or "[untitled]" trow = Html("tr") @@ -4459,12 +4491,13 @@ class MediaPages(BasePage): # add footer section # add clearline for proper styling - footer = self.write_footer() + if ldatec == 0: ldatec = None + footer = self.write_footer(ldatec) body += (fullclear, footer) # send page out for processing # and close the file - self.XHTMLWriter(medialistpage, of, sio) + self.XHTMLWriter(medialistpage, of, sio, ldatec) def media_ref_link(self, handle, name, up = False): @@ -4497,6 +4530,7 @@ class MediaPages(BasePage): media = self.dbase_.get_object_from_handle(media_handle) BasePage.__init__(self, report, title, media.gramps_id) + ldatec = media.get_change_time() # get media rectangles _region_items = self.media_ref_rect_regions(media_handle) @@ -4571,6 +4605,7 @@ class MediaPages(BasePage): # have to await a large download unnecessarily. Either way, set # the display image size as requested. orig_image_path = media_path_full(self.dbase_, media.get_path()) + mtime = os.stat(orig_image_path).st_mtime (width, height) = image_size(orig_image_path) max_width = self.report.options['maxinitialimagewidth'] max_height = self.report.options['maxinitialimageheight'] @@ -4596,12 +4631,15 @@ class MediaPages(BasePage): filed, dest = tempfile.mkstemp() os.write(filed, initial_image_data) os.close(filed) + os.utime(dest, (mtime, mtime)) self.report.archive.add(dest, initial_image_path) os.unlink(dest) else: - filed = open(os.path.join(self.html_dir, initial_image_path), 'wb') + file_path_init = os.path.join(self.html_dir, initial_image_path) + filed = open(file_path_init, 'wb') filed.write(initial_image_data) filed.close() + os.utime(file_path_init, (mtime, mtime)) else: # not worth actually making a smaller image initial_image_path = newpath @@ -4730,12 +4768,12 @@ class MediaPages(BasePage): # add clearline for proper styling # add footer section - footer = self.write_footer() + footer = self.write_footer(ldatec) body += (fullclear, footer) # send page out for processing # and close the file - self.XHTMLWriter(mediapage, of, sio) + self.XHTMLWriter(mediapage, of, sio, ldatec) def media_nav_link(self, handle, name, up = False): """ @@ -4765,14 +4803,16 @@ class MediaPages(BasePage): _WRONGMEDIAPATH.append([ photo.get_gramps_id(), fullpath]) return None try: + mtime = os.stat(fullpath).st_mtime if self.report.archive: self.report.archive.add(fullpath, str(newpath)) else: to_dir = os.path.join(self.html_dir, to_dir) if not os.path.isdir(to_dir): os.makedirs(to_dir) - shutil.copyfile(fullpath, - os.path.join(self.html_dir, newpath)) + new_file = os.path.join(self.html_dir, newpath) + shutil.copyfile(fullpath, new_file) + os.utime(new_file, (mtime, mtime)) return newpath except (IOError, OSError) as msg: error = _("Missing media object:") + \ @@ -4925,12 +4965,12 @@ class ThumbnailPreviewPage(BasePage): # add footer section # add clearline for proper styling - footer = self.write_footer() + footer = self.write_footer(None) body += (fullclear, footer) # send page out for processing # and close the file - self.XHTMLWriter(thumbnailpage, of, sio) + self.XHTMLWriter(thumbnailpage, of, sio, None) def thumbnail_link(self, name, index): """ @@ -5075,12 +5115,12 @@ class DownloadPage(BasePage): # clear line for proper styling # create footer section - footer = self.write_footer() + footer = self.write_footer(None) body += (fullclear, footer) # send page out for processing # and close the file - self.XHTMLWriter(downloadpage, of, sio) + self.XHTMLWriter(downloadpage, of, sio, None) class ContactPage(BasePage): def __init__(self, report, title): @@ -5141,12 +5181,12 @@ class ContactPage(BasePage): # add clearline for proper styling # add footer section - footer = self.write_footer() + footer = self.write_footer(None) body += (fullclear, footer) # send page out for porcessing # and close the file - self.XHTMLWriter(contactpage, of, sio) + self.XHTMLWriter(contactpage, of, sio, None) ################################################# # @@ -5205,6 +5245,7 @@ class PersonPages(BasePage): of, sio = self.report.create_file("individuals") indlistpage, head, body = self.write_header(_("Individuals")) + date = 0 # begin Individuals division with Html("div", class_ = "content", id = "Individuals") as individuallist: @@ -5265,6 +5306,7 @@ class PersonPages(BasePage): first_surname = True for person_handle in handle_list: person = self.dbase_.get_person_from_handle(person_handle) + if person.get_change_time() > date: date = person.get_change_time() # surname column trow = Html("tr") @@ -5388,12 +5430,13 @@ class PersonPages(BasePage): # create clear line for proper styling # create footer section - footer = self.write_footer() + if date == 0: date = None + footer = self.write_footer(date) body += (fullclear, footer) # send page out for processing # and close the file - self.XHTMLWriter(indlistpage, of, sio) + self.XHTMLWriter(indlistpage, of, sio, date) ################################################# # @@ -5416,6 +5459,8 @@ class PersonPages(BasePage): self.sort_name = self.get_name(person) self.name = self.get_name(person) + date = self.person.get_change_time() + # to be used in the Family Map Pages... self.familymappages = self.report.options['familymappages'] self.placemappages = self.report.options['placemappages'] @@ -5555,12 +5600,12 @@ class PersonPages(BasePage): # add clearline for proper styling # create footer section - footer = self.write_footer() + footer = self.write_footer(date) body += (fullclear, footer) # send page out for processing # and close the file - self.XHTMLWriter(indivdetpage, of, sio) + self.XHTMLWriter(indivdetpage, of, sio, date) def __create_family_map(self, person, place_lat_long): """ @@ -5819,12 +5864,12 @@ class PersonPages(BasePage): # add clearline for proper styling # add footer section - footer = self.write_footer() + footer = self.write_footer(None) body += (fullclear, footer) # send page out for processing # and close the file - self.XHTMLWriter(familymappage, of, sio) + self.XHTMLWriter(familymappage, of, sio, None) def __display_family_map(self, person, place_lat_long): """ @@ -6595,6 +6640,7 @@ class RepositoryPages(BasePage): of, sio = self.report.create_file("repositories") repolistpage, head, body = self.write_header(_("Repositories")) + ldatec = 0 # begin RepositoryList division with Html("div", class_ = "content", id = "RepositoryList") as repositorylist: body += repositorylist @@ -6641,22 +6687,25 @@ class RepositoryPages(BasePage): if repo.get_name(): trow += Html("td", self.repository_link(handle, repo.get_name(), repo.get_gramps_id(), self.up), class_ = "ColumnName") + ldatec = repo.get_change_time() else: trow += Html("td", "[ untitled ]", class_ = "ColumnName") # add clearline for proper styling # add footer section - footer = self.write_footer() + if ldatec == 0: ldatec = None + footer = self.write_footer(ldatec) body += (fullclear, footer) # send page out for processing # and close the file - self.XHTMLWriter(repolistpage, of, sio) + self.XHTMLWriter(repolistpage, of, sio, ldatec) def RepositoryPage(self, report, title, repo, handle): gid = repo.get_gramps_id() BasePage.__init__(self, report, title, gid) self.dbase_ = report.database + ldatec = repo.get_change_time() of, sio = self.report.create_file(handle, 'repo') self.up = True @@ -6711,12 +6760,12 @@ class RepositoryPages(BasePage): # add clearline for proper styling # add footer section - footer = self.write_footer() + footer = self.write_footer(ldatec) body += (fullclear, footer) # send page out for processing # and close the file - self.XHTMLWriter(repositorypage, of, sio) + self.XHTMLWriter(repositorypage, of, sio, ldatec) class AddressBookListPage(BasePage): def __init__(self, report, title, has_url_addr_res): @@ -6803,12 +6852,12 @@ class AddressBookListPage(BasePage): index += 1 # Add footer and clearline - footer = self.write_footer() + footer = self.write_footer(None) body += (fullclear, footer) # send the page out for processing # and close the file - self.XHTMLWriter(addressbooklistpage, of, sio) + self.XHTMLWriter(addressbooklistpage, of, sio, None) class AddressBookPage(BasePage): def __init__(self, report, title, person_handle, has_add, has_res, has_url): @@ -6847,12 +6896,12 @@ class AddressBookPage(BasePage): # add fullclear for proper styling # and footer section to page - footer = self.write_footer() + footer = self.write_footer(None) body += (fullclear, footer) # send page out for processing # and close the file - self.XHTMLWriter(addressbookpage, of, sio) + self.XHTMLWriter(addressbookpage, of, sio, None) class NavWebReport(Report): @@ -7621,7 +7670,7 @@ class NavWebReport(Report): self.write_gendex(gendex_io, person) else: self.write_gendex(fp_gendex, person) - self.close_file(fp_gendex, gendex_io) + self.close_file(fp_gendex, gendex_io, date) def write_gendex(self, fp, person): """ @@ -7883,7 +7932,7 @@ class NavWebReport(Report): errors='xmlcharrefreplace') return (of, string_io) - def close_file(self, of, string_io): + def close_file(self, of, string_io, date): """ will close any file passed to it """ @@ -7892,7 +7941,7 @@ class NavWebReport(Report): of.flush() tarinfo = tarfile.TarInfo(self.cur_fname) tarinfo.size = len(string_io.getvalue()) - tarinfo.mtime = time.time() + tarinfo.mtime = date if date is not None else time.time() if not win(): tarinfo.uid = os.getuid() tarinfo.gid = os.getgid() @@ -7901,6 +7950,8 @@ class NavWebReport(Report): of.close() else: of.close() + if date is not None: + os.utime(of.name, (date, date)) def prepare_copy_media(self, photo): """ @@ -7925,8 +7976,10 @@ class NavWebReport(Report): be prepended before 'to_fname'. """ # log.debug("copying '%s' to '%s/%s'" % (from_fname, to_dir, to_fname)) + mtime = os.stat(from_fname).st_mtime if self.archive: dest = os.path.join(to_dir, to_fname) + os.utime(from_fname, (mtime, mtime)) self.archive.add(from_fname, dest) else: dest = os.path.join(self.html_dir, to_dir, to_fname) @@ -7938,6 +7991,7 @@ class NavWebReport(Report): if from_fname != dest: try: shutil.copyfile(from_fname, dest) + os.utime(dest, (mtime, mtime)) except: print("Copying error: %s" % sys.exc_info()[1]) print("Continuing...")