# # Gramps - a GTK+/GNOME based genealogy program # # Copyright (C) 2000-2005 Donald N. Allingham # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Pubilc License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # # $Id$ """ Narrative Web Page generator. """ #------------------------------------------------------------------------ # # python modules # #------------------------------------------------------------------------ import os import md5 import time import locale import shutil import codecs import sets import tarfile from gettext import gettext as _ from cStringIO import StringIO #------------------------------------------------------------------------ # # GNOME/gtk # #------------------------------------------------------------------------ import gtk #------------------------------------------------------------------------ # # GRAMPS module # #------------------------------------------------------------------------ import RelLib import const from GrampsCfg import get_researcher import GenericFilter import Sort import Report import Errors import Utils import ReportOptions import ReportUtils import ImgManip import GrampsLocale from QuestionDialog import ErrorDialog, WarningDialog from NameDisplay import displayer as _nd from DateHandler import displayer as _dd #------------------------------------------------------------------------ # # constants # #------------------------------------------------------------------------ _NARRATIVE = "narrative.css" _NAME_COL = 3 WIDTH=160 HEIGHT=50 VGAP=10 HGAP=30 SHADOW=5 XOFFSET=5 _css_files = [ [_("Modern"), 'main1.css'], [_("Business"), 'main2.css'], [_("Certificate"), 'main3.css'], [_("Antique"), 'main4.css'], [_("Tranquil"), 'main5.css'], [_("Sharp"), 'main6.css'], [_("No style sheet"), ''], ] _character_sets = [ [_('Unicode (recommended)'), 'utf-8'], ['ISO-8859-1', 'iso-8859-1' ], ['ISO-8859-2', 'iso-8859-2' ], ['ISO-8859-3', 'iso-8859-3' ], ['ISO-8859-4', 'iso-8859-4' ], ['ISO-8859-5', 'iso-8859-5' ], ['ISO-8859-6', 'iso-8859-6' ], ['ISO-8859-7', 'iso-8859-7' ], ['ISO-8859-8', 'iso-8859-8' ], ['ISO-8859-9', 'iso-8859-9' ], ['ISO-8859-10', 'iso-8859-10' ], ['ISO-8859-13', 'iso-8859-13' ], ['ISO-8859-14', 'iso-8859-14' ], ['ISO-8859-15', 'iso-8859-15' ], ['koi8_r', 'koi8_r', ], ] _cc = [ '', '', '', '', '', '', ] class BasePage: def __init__(self, title, options, archive, photo_list, gid): self.title_str = title self.gid = gid self.inc_download = options.handler.options_dict['NWEBdownload'] self.html_dir = options.handler.options_dict['NWEBod'] self.copyright = options.handler.options_dict['NWEBcopyright'] self.options = options self.archive = archive self.ext = options.handler.options_dict['NWEBext'] self.encoding = options.handler.options_dict['NWEBencoding'] self.css = options.handler.options_dict['NWEBcss'] self.noid = options.handler.options_dict['NWEBnoid'] self.use_intro = options.handler.options_dict['NWEBintronote'] != u"" self.use_contact = options.handler.options_dict['NWEBcontact'] != u"" self.use_gallery = options.handler.options_dict['NWEBgallery'] self.header = options.handler.options_dict['NWEBheader'] self.footer = options.handler.options_dict['NWEBfooter'] self.photo_list = photo_list self.exclude_private = not options.handler.options_dict['NWEBincpriv'] self.usegraph = options.handler.options_dict['NWEBgraph'] self.use_home = self.options.handler.options_dict['NWEBhomenote'] != "" def store_file(self,archive,html_dir,from_path,to_path): if archive: archive.add(from_path,to_path) else: dest = os.path.join(html_dir,to_path) dirname = os.path.dirname(dest) if not os.path.isdir(dirname): os.makedirs(dirname) shutil.copyfile(from_path,dest) def copy_media(self,photo,store_ref=True): handle = photo.get_handle() if store_ref: lnk = (self.cur_name,self.page_title,self.gid) if self.photo_list.has_key(handle): if lnk not in self.photo_list[handle]: self.photo_list[handle].append(lnk) else: self.photo_list[handle] = [lnk] ext = os.path.splitext(photo.get_path())[1] real_path = "%s/%s" % (self.build_path(handle,'images'),handle+ext) thumb_path = "%s/%s.png" % (self.build_path(handle,'thumb'),handle) return (real_path,thumb_path) def create_file(self,name): self.cur_name = self.build_name("",name) if self.archive: self.string_io = StringIO() of = codecs.EncodedFile(self.string_io,'utf-8',self.encoding, 'xmlcharrefreplace') else: page_name = os.path.join(self.html_dir,self.cur_name) of = codecs.EncodedFile(open(page_name, "w"),'utf-8', self.encoding,'xmlcharrefreplace') return of def link_path(self,name,path): base = self.build_name("",name) return os.path.join(path,name[0],name[1],base) def create_link_file(self,name,path): self.cur_name = self.link_path(name,path) if self.archive: self.string_io = StringIO() of = codecs.EncodedFile(self.string_io,'utf-8', self.encoding,'xmlcharrefreplace') else: dirname = os.path.join(self.html_dir,path,name[0],name[1]) if not os.path.isdir(dirname): os.makedirs(dirname) page_name = self.build_name(dirname,name) of = codecs.EncodedFile(open(page_name, "w"),'utf-8', self.encoding,'xmlcharrefreplace') return of def close_file(self,of): if self.archive: tarinfo = tarfile.TarInfo(self.cur_name) tarinfo.size = len(self.string_io.getvalue()) tarinfo.mtime = time.time() tarinfo.uid = os.getuid() tarinfo.gid = os.getgid() self.string_io.seek(0) self.archive.addfile(tarinfo,self.string_io) of.close() else: of.close() def lnkfmt(self,text): return md5.new(text).hexdigest() def display_footer(self,of,db): of.write('\n') of.write('
\n') if self.footer: obj = db.get_object_from_handle(self.footer) if obj: of.write(' \n') of.write('