NarrativeWeb : bug #0005537 : Bug creating archive with the option Include Family Map with all places

svn: r18951
This commit is contained in:
Serge Noiraud 2012-02-22 20:27:01 +00:00
parent 212c752202
commit 58afe3dfe9

View File

@ -2703,7 +2703,7 @@ class BasePage(object):
# ---------------------------------------------------------------------------------------
# # Web Page Fortmatter and writer
# ---------------------------------------------------------------------------------------
def XHTMLWriter(self, htmlinstance, of):
def XHTMLWriter(self, htmlinstance, of, sio):
"""
Will format, write, and close the file
@ -2715,7 +2715,8 @@ class BasePage(object):
htmlinstance.write(partial(print, file=of))
# closes the file
self.report.close_file(of)
self.report.close_file(of, sio)
#################################################
#
# creates the Individual List Page
@ -2732,7 +2733,7 @@ class IndividualListPage(BasePage):
showpartner = report.options['showpartner']
showparents = report.options['showparents']
of = self.report.create_file("individuals")
of, sio = self.report.create_file("individuals")
indlistpage, head, body = self.write_header(_("Individuals"))
# begin Individuals division
@ -2907,7 +2908,7 @@ class IndividualListPage(BasePage):
# send page out for processing
# and close the file
self.XHTMLWriter(indlistpage, of)
self.XHTMLWriter(indlistpage, of, sio)
#################################################
#
@ -2929,7 +2930,7 @@ class SurnamePage(BasePage):
showpartner = report.options['showpartner']
showparents = report.options['showparents']
of = self.report.create_file(name_to_md5(surname), "srn")
of, sio = self.report.create_file(name_to_md5(surname), "srn")
self.up = True
surnamepage, head, body = self.write_header("%s - %s" % (_("Surname"), surname))
@ -3073,14 +3074,14 @@ class SurnamePage(BasePage):
# send page out for processing
# and close the file
self.XHTMLWriter(surnamepage, of)
self.XHTMLWriter(surnamepage, of, sio)
class FamilyListPage(BasePage):
def __init__(self, report, title, ind_list, db_family_handles):
self.dbase_ = report.database
BasePage.__init__(self, report, title)
of = self.report.create_file("families")
of, sio = self.report.create_file("families")
familiesListPage, head, body = self.write_header(_("Families"))
# begin Family Division
@ -3228,7 +3229,7 @@ class FamilyListPage(BasePage):
# send page out for processing
# and close the file
self.XHTMLWriter(familiesListPage, of)
self.XHTMLWriter(familiesListPage, of, sio)
class FamilyPage(BasePage):
def __init__(self, report, title, family_handle, place_list, ppl_handle_list, place_lat_long):
@ -3245,7 +3246,7 @@ class FamilyPage(BasePage):
birthorder = report.options["birthorder"]
self.familymappages = report.options["familymappages"]
of = self.report.create_file(family.get_handle(), "fam")
of, sio = self.report.create_file(family.get_handle(), "fam")
familydetailpage, head, body = self.write_header(_("Family/ Relationship"))
# begin FamilyDetaill division
@ -3323,14 +3324,14 @@ class FamilyPage(BasePage):
# send page out for processing
# and close the file
self.XHTMLWriter(familydetailpage, of)
self.XHTMLWriter(familydetailpage, of, sio)
class PlaceListPage(BasePage):
def __init__(self, report, title, place_handles, db_place_handles):
self.dbase_ = report.database
BasePage.__init__(self, report, title)
of = self.report.create_file("places")
of, sio = self.report.create_file("places")
placelistpage, head, body = self.write_header(_("Places"))
# begin places division
@ -3436,7 +3437,7 @@ class PlaceListPage(BasePage):
# send page out for processing
# and close the file
self.XHTMLWriter(placelistpage, of)
self.XHTMLWriter(placelistpage, of, sio)
######################################################
# #
@ -3452,7 +3453,7 @@ class PlacePage(BasePage):
return None
BasePage.__init__(self, report, title, place.get_gramps_id())
of = self.report.create_file(place_handle, "plc")
of, sio = self.report.create_file(place_handle, "plc")
self.src_list = src_list
self.up = True
self.page_title = place.get_title()
@ -3568,7 +3569,7 @@ class PlacePage(BasePage):
# send page out for processing
# and close the file
self.XHTMLWriter(placepage, of)
self.XHTMLWriter(placepage, of, sio)
class EventListPage(BasePage):
def __init__(self, report, title, event_types, event_handle_list, ppl_handle_list, db_event_handles):
@ -3581,7 +3582,7 @@ class EventListPage(BasePage):
self.dbase_ = report.database
BasePage.__init__(self, report, title)
of = self.report.create_file("events")
of, sio = self.report.create_file("events")
eventslistpage, head, body = self.write_header(_("Events"))
# begin events list division
@ -3724,7 +3725,7 @@ class EventListPage(BasePage):
# send page ut for processing
# and close the file
self.XHTMLWriter(eventslistpage, of)
self.XHTMLWriter(eventslistpage, of, sio)
def _getEventDate(self, event_handle):
event_date = gen.lib.Date.EMPTY
@ -3770,7 +3771,7 @@ class EventPage(BasePage):
subdirs = True
self.bibli = Bibliography()
of = self.report.create_file(event_handle, "evt")
of, sio = self.report.create_file(event_handle, "evt")
eventpage, head, body = self.write_header(_("Events"))
# start event detail division
@ -3862,7 +3863,7 @@ class EventPage(BasePage):
# send page out for processing
# and close the page
self.XHTMLWriter(eventpage, of)
self.XHTMLWriter(eventpage, of, sio)
class MediaPage(BasePage):
def __init__(self, report, title, handle, src_list, my_media_list, info):
@ -3876,7 +3877,7 @@ class MediaPage(BasePage):
# get media rectangles
_region_items = self.media_ref_rect_regions(handle)
of = self.report.create_file(handle, "img")
of, sio = self.report.create_file(handle, "img")
self.up = True
self.src_list = src_list
@ -4104,7 +4105,7 @@ class MediaPage(BasePage):
# send page out for processing
# and close the file
self.XHTMLWriter(mediapage, of)
self.XHTMLWriter(mediapage, of, sio)
def media_nav_link(self, handle, name, up = False):
"""
@ -4164,10 +4165,10 @@ class SurnameListPage(BasePage):
BasePage.__init__(self, report, title)
if order_by == self.ORDER_BY_NAME:
of = self.report.create_file(filename)
of, sio = self.report.create_file(filename)
surnamelistpage, head, body = self.write_header(_('Surnames'))
else:
of = self.report.create_file("surnames_count")
of, sio = self.report.create_file("surnames_count")
surnamelistpage, head, body = self.write_header(_('Surnames by person count'))
# begin surnames division
@ -4276,7 +4277,7 @@ class SurnameListPage(BasePage):
# send page out for processing
# and close the file
self.XHTMLWriter(surnamelistpage, of)
self.XHTMLWriter(surnamelistpage, of, sio)
def surname_link(self, fname, name, opt_val = None, up = False):
url = self.report.build_url_fname_html(fname, "srn", up)
@ -4292,7 +4293,7 @@ class IntroductionPage(BasePage):
self.dbase_ = report.database
BasePage.__init__(self, report, title)
of = self.report.create_file(report.intro_fname)
of, sio = self.report.create_file(report.intro_fname)
intropage, head, body = self.write_header(_('Introduction'))
# begin Introduction division
@ -4318,14 +4319,14 @@ class IntroductionPage(BasePage):
# send page out for processing
# and close the file
self.XHTMLWriter(intropage, of)
self.XHTMLWriter(intropage, of, sio)
class HomePage(BasePage):
def __init__(self, report, title):
self.dbase_ = report.database
BasePage.__init__(self, report, title)
of = self.report.create_file("index")
of, sio = self.report.create_file("index")
homepage, head, body = self.write_header(_('Home'))
# begin home division
@ -4351,7 +4352,7 @@ class HomePage(BasePage):
# send page out for processing
# and close the file
self.XHTMLWriter(homepage, of)
self.XHTMLWriter(homepage, of, sio)
class SourceListPage(BasePage):
def __init__(self, report, title, handle_set):
@ -4361,7 +4362,7 @@ class SourceListPage(BasePage):
handle_list = list(handle_set)
source_dict = {}
of = self.report.create_file("sources")
of, sio = self.report.create_file("sources")
sourcelistpage, head, body = self.write_header(_("Sources"))
# begin source list division
@ -4422,7 +4423,7 @@ class SourceListPage(BasePage):
# send page out for processing
# and close the file
self.XHTMLWriter(sourcelistpage, of)
self.XHTMLWriter(sourcelistpage, of, sio)
"""
#
@ -4449,7 +4450,7 @@ class SourcePage(BasePage):
inc_repositories = self.report.options["inc_repository"]
self.navigation = self.report.options["navigation"]
of = self.report.create_file(src_handle, "src")
of, sio = self.report.create_file(src_handle, "src")
self.up = True
sourcepage, head, body = self.write_header(_('Sources'))
@ -4816,14 +4817,14 @@ class SourcePage(BasePage):
# send page out for processing
# and close the file
self.XHTMLWriter(sourcepage, of)
self.XHTMLWriter(sourcepage, of, sio)
class MediaListPage(BasePage):
def __init__(self, report, title, db_media_handles):
self.dbase_ = report.database
BasePage.__init__(self, report, title)
of = self.report.create_file("media")
of, sio = self.report.create_file("media")
media_listpage, head, body = self.write_header(_('Media'))
# begin gallery division
@ -4895,7 +4896,7 @@ class MediaListPage(BasePage):
# send page out for processing
# and close the file
self.XHTMLWriter(media_listpage, of)
self.XHTMLWriter(media_listpage, of, sio)
def media_ref_link(self, handle, name, up = False):
@ -4937,7 +4938,7 @@ class ThumbnailPreviewPage(BasePage):
media_list.sort()
# reate thumbnail preview page...
of = self.report.create_file("thumbnails")
of, sio = self.report.create_file("thumbnails")
thumbnailpage, head, body = self.write_header(_("Thumbnails"))
with Html("div", class_ ="content", id ="Preview") as previewpage:
@ -5058,7 +5059,7 @@ class ThumbnailPreviewPage(BasePage):
# send page out for processing
# and close the file
self.XHTMLWriter(thumbnailpage, of)
self.XHTMLWriter(thumbnailpage, of, sio)
def thumbnail_link(self, name, index):
"""
@ -5111,7 +5112,7 @@ class DownloadPage(BasePage):
# if no filenames at all, return???
if dlfname1 or dlfname2:
of = self.report.create_file("download")
of, sio = self.report.create_file("download")
downloadpage, head, body = self.write_header(_('Download'))
# begin download page and table
@ -5204,14 +5205,14 @@ class DownloadPage(BasePage):
# send page out for processing
# and close the file
self.XHTMLWriter(downloadpage, of)
self.XHTMLWriter(downloadpage, of, sio)
class ContactPage(BasePage):
def __init__(self, report, title):
self.dbase_ = report.database
BasePage.__init__(self, report, title)
of = self.report.create_file("contact")
of, sio = self.report.create_file("contact")
contactpage, head, body = self.write_header(_('Contact'))
# begin contact division
@ -5270,7 +5271,7 @@ class ContactPage(BasePage):
# send page out for porcessing
# and close the file
self.XHTMLWriter(contactpage, of)
self.XHTMLWriter(contactpage, of, sio)
"""
#
@ -5309,7 +5310,7 @@ class IndividualPage(BasePage):
# bio, half, step- siblings for use in display_ind_parents() ...
self.rel_class = rel_class
of = self.report.create_file(person.get_handle(), "ppl")
of, sio = self.report.create_file(person.get_handle(), "ppl")
self.up = True
indivdetpage, head, body = self.write_header(self.sort_name)
@ -5407,7 +5408,15 @@ class IndividualPage(BasePage):
# for use in family map pages...
if len(place_lat_long):
if self.report.options["familymappages"]:
# save of, string_io and cur_fname before creating a new page
sof = of
sstring_io = sio
sfname = self.report.cur_fname
individualdetail += self.__display_family_map(person, place_lat_long)
# restore of, string_io and cur_fname after creating a new page
of = sof
sio = sstring_io
self.report.cur_fname = sfname
# display pedigree
sect13 = self.display_ind_pedigree()
@ -5432,7 +5441,7 @@ class IndividualPage(BasePage):
# send page out for processing
# and close the file
self.XHTMLWriter(indivdetpage, of)
self.XHTMLWriter(indivdetpage, of, sio)
def __create_family_map(self, person, place_lat_long):
"""
@ -5444,7 +5453,7 @@ class IndividualPage(BasePage):
if not place_lat_long:
return
of = self.report.create_file(person.get_handle(), "maps")
of, sio = self.report.create_file(person.get_handle(), "maps")
self.up = True
familymappage, head, body = self.write_header(_("Family Map"))
@ -5674,7 +5683,7 @@ class IndividualPage(BasePage):
# send page out for processing
# and close the file
self.XHTMLWriter(familymappage, of)
self.XHTMLWriter(familymappage, of, sio)
def __display_family_map(self, person, place_lat_long):
"""
@ -6486,7 +6495,7 @@ class RepositoryListPage(BasePage):
BasePage.__init__(self, report, title)
inc_repos = self.report.options["inc_repository"]
of = self.report.create_file("repositories")
of, sio = self.report.create_file("repositories")
repolistpage, head, body = self.write_header(_("Repositories"))
# begin RepositoryList division
@ -6544,7 +6553,7 @@ class RepositoryListPage(BasePage):
# send page out for processing
# and close the file
self.XHTMLWriter(repolistpage, of)
self.XHTMLWriter(repolistpage, of, sio)
#-----------------------------------------------------
#
@ -6557,7 +6566,7 @@ class RepositoryPage(BasePage):
BasePage.__init__(self, report, title, gid)
self.dbase_ = report.database
of = self.report.create_file(handle, 'repo')
of, sio = self.report.create_file(handle, 'repo')
self.up = True
repositorypage, head, body = self.write_header(_('Repositories'))
@ -6613,7 +6622,7 @@ class RepositoryPage(BasePage):
# send page out for processing
# and close the file
self.XHTMLWriter(repositorypage, of)
self.XHTMLWriter(repositorypage, of, sio)
def __write_referenced_sources(self, handle, source_list):
"""
@ -6662,7 +6671,7 @@ class AddressBookListPage(BasePage):
BasePage.__init__(self, report, title)
# Name the file, and create it
of = self.report.create_file("addressbook")
of, sio = self.report.create_file("addressbook")
# Add xml, doctype, meta and stylesheets
addressbooklistpage, head, body = self.write_header(_("Address Book"))
@ -6746,7 +6755,7 @@ class AddressBookListPage(BasePage):
# send the page out for processing
# and close the file
self.XHTMLWriter(addressbooklistpage, of)
self.XHTMLWriter(addressbooklistpage, of, sio)
class AddressBookPage(BasePage):
def __init__(self, report, title, person_handle, has_add, has_res, has_url):
@ -6758,7 +6767,7 @@ class AddressBookPage(BasePage):
self.up = True
# set the file name and open file
of = self.report.create_file(person_handle, "addr")
of, sio = self.report.create_file(person_handle, "addr")
addressbookpage, head, body = self.write_header(_("Address Book"))
# begin address book page division and section title
@ -6790,7 +6799,7 @@ class AddressBookPage(BasePage):
# send page out for processing
# and close the file
self.XHTMLWriter(addressbookpage, of)
self.XHTMLWriter(addressbookpage, of, sio)
class NavWebReport(Report):
@ -7155,12 +7164,15 @@ class NavWebReport(Report):
if self.inc_gendex:
self.user.begin_progress(_("Narrated Web Site Report"),
_('Creating GENDEX file'), len(ind_list))
fp_gendex = self.create_file("gendex", ext=".txt")
fp_gendex, gendex_io = self.create_file("gendex", ext=".txt")
for person_handle in ind_list:
self.user.step_progress()
person = self.database.get_person_from_handle(person_handle)
self.write_gendex(fp_gendex, person)
self.close_file(fp_gendex)
if self.archive:
self.write_gendex(gendex_io, person)
else:
self.write_gendex(fp_gendex, person)
self.user.end_progress()
def write_gendex(self, fp, person):
@ -7532,10 +7544,11 @@ class NavWebReport(Report):
else:
self.cur_fname = fname + ext
if self.archive:
self.string_io = StringIO()
of = codecs.EncodedFile(self.string_io, 'utf-8',
string_io = StringIO()
of = codecs.EncodedFile(string_io, 'utf-8',
self.encoding, 'xmlcharrefreplace')
else:
string_io = None
if subdir:
subdir = os.path.join(self.html_dir, subdir)
if not os.path.isdir(subdir):
@ -7543,27 +7556,25 @@ class NavWebReport(Report):
fname = os.path.join(self.html_dir, self.cur_fname)
of = codecs.EncodedFile(open(fname, "w"), 'utf-8',
self.encoding, 'xmlcharrefreplace')
return of
return (of, string_io)
def close_file(self, of):
def close_file(self, of, string_io):
"""
will close any file passed to it
"""
if self.archive:
tarinfo = tarfile.TarInfo(self.cur_fname)
tarinfo.size = len(self.string_io.getvalue())
tarinfo.size = len(string_io.getvalue())
tarinfo.mtime = time.time()
if not constfunc.win():
tarinfo.uid = os.getuid()
tarinfo.gid = os.getgid()
self.string_io.seek(0)
self.archive.addfile(tarinfo, self.string_io)
self.string_io = None
string_io.seek(0)
self.archive.addfile(tarinfo, string_io)
of.close()
else:
of.close()
self.cur_fname = None
def add_lnkref_to_photo(self, photo, lnkref):
"""