diff --git a/src/gen/lib/date.py b/src/gen/lib/date.py index 3202f65fd..b00b1540e 100644 --- a/src/gen/lib/date.py +++ b/src/gen/lib/date.py @@ -1718,103 +1718,12 @@ def Today(): current_date.set_yr_mon_day(*time.localtime(time.time())[0:3]) return current_date -#------------------------------------------------------------------------- -# -# GEDCOM Date Constants -# -#------------------------------------------------------------------------- -HMONTH = [ - "", "ELUL", "TSH", "CSH", "KSL", "TVT", "SHV", "ADR", - "ADS", "NSN", "IYR", "SVN", "TMZ", "AAV", "ELL" ] - -FMONTH = [ - "", "VEND", "BRUM", "FRIM", "NIVO", "PLUV", "VENT", - "GERM", "FLOR", "PRAI", "MESS", "THER", "FRUC", "COMP"] - -MONTH = [ - "", "JAN", "FEB", "MAR", "APR", "MAY", "JUN", - "JUL", "AUG", "SEP", "OCT", "NOV", "DEC" ] - -CALENDAR_MAP = { - Date.CAL_HEBREW : (HMONTH, '@#DHEBREW@'), - Date.CAL_FRENCH : (FMONTH, '@#DFRENCH R@'), - Date.CAL_JULIAN : (MONTH, '@#DJULIAN@'), - Date.CAL_SWEDISH : (MONTH, '@#DUNKNOWN@'), - } - -DATE_MODIFIER = { - Date.MOD_ABOUT : "ABT", - Date.MOD_BEFORE : "BEF", - Date.MOD_AFTER : "AFT", - #Date.MOD_INTERPRETED : "INT", - } - -DATE_QUALITY = { - Date.QUAL_CALCULATED : "CAL", - Date.QUAL_ESTIMATED : "EST", -} - #------------------------------------------------------------------------- # # Date Functions # #------------------------------------------------------------------------- -def make_gedcom_date(subdate, calendar, mode, quality): - """ - Convert a GRAMPS date structure into a GEDCOM compatible date. - """ - retval = "" - (day, mon, year) = subdate[0:3] - (mmap, prefix) = CALENDAR_MAP.get(calendar, (MONTH, "")) - if year < 0: - year = -year - bce = " B.C." - else: - bce = "" - try: - retval = __build_date_string(day, mon, year, bce, mmap) - except IndexError: - print "Month index error - %d" % mon - retval = "%d%s" % (year, bce) - if calendar == Date.CAL_SWEDISH: - # If Swedish calendar use ISO for for date and append (swedish) - # to indicate calandar - if year and not mon and not day: - retval = "%i" % (year) - else: - retval = "%i-%02i-%02i" % (year, mon, day) - retval = retval + " (swedish)" - # Skip prefix @#DUNKNOWN@ as it seems - # not used in all other genealogy applications. - # GRAMPS can handle it on import, but not with (swedish) appended - # to explain what calendar, the unknown refer to - prefix = "" - if prefix: - retval = "%s %s" % (prefix, retval) - if mode in DATE_MODIFIER: - retval = "%s %s" % (DATE_MODIFIER[mode], retval) - if quality in DATE_QUALITY: - retval = "%s %s" % (DATE_QUALITY[quality], retval) - return retval -def __build_date_string(day, mon, year, bce, mmap): - """ - Build a date string from the supplied information. - """ - if day == 0: - if mon == 0: - retval = '%d%s' % (year, bce) - elif year == 0: - retval = '(%s)' % mmap[mon] - else: - retval = "%s %d%s" % (mmap[mon], year, bce) - elif mon == 0: - retval = '%d%s' % (year, bce) - elif year == 0: - retval = "(%d %s)" % (day, mmap[mon]) - else: - retval = "%d %s %d%s" % (day, mmap[mon], year, bce) - return retval def lookup_calendar(calendar): """ diff --git a/src/plugins/export/ExportGedcom.py b/src/plugins/export/ExportGedcom.py index 1f2547928..e6bb1621e 100644 --- a/src/plugins/export/ExportGedcom.py +++ b/src/plugins/export/ExportGedcom.py @@ -39,7 +39,6 @@ import time # #------------------------------------------------------------------------- import gen.lib -from gen.lib.date import make_gedcom_date, MONTH import const import libgedcom import Errors @@ -375,7 +374,7 @@ class GedcomWriter(UpdateCallback): """ local_time = time.localtime(time.time()) (year, mon, day, hour, minutes, sec) = local_time[0:6] - date_str = "%d %s %d" % (day, MONTH[mon], year) + date_str = "%d %s %d" % (day, libgedcom.MONTH[mon], year) time_str = "%02d:%02d:%02d" % (hour, minutes, sec) rname = self.dbase.get_researcher().get_name() @@ -1099,7 +1098,7 @@ class GedcomWriter(UpdateCallback): self.__writeln(level, 'CHAN') time_val = time.localtime(timeval) self.__writeln(level+1, 'DATE', '%d %s %d' % ( - time_val[2], MONTH[time_val[1]], time_val[0])) + time_val[2], libgedcom.MONTH[time_val[1]], time_val[0])) self.__writeln(level+2, 'TIME', '%02d:%02d:%02d' % ( time_val[3], time_val[4], time_val[5])) @@ -1208,14 +1207,16 @@ class GedcomWriter(UpdateCallback): quality = date.get_quality() if mod == gen.lib.Date.MOD_SPAN: val = "FROM %s TO %s" % ( - make_gedcom_date(start, cal, mod, quality), - make_gedcom_date(date.get_stop_date(), cal, mod, quality)) + libgedcom.make_gedcom_date(start, cal, mod, quality), + libgedcom.make_gedcom_date(date.get_stop_date(), + cal, mod, quality)) elif mod == gen.lib.Date.MOD_RANGE: val = "BET %s AND %s" % ( - make_gedcom_date(start, cal, mod, quality), - make_gedcom_date(date.get_stop_date(), cal, mod, quality)) + libgedcom.make_gedcom_date(start, cal, mod, quality), + libgedcom.make_gedcom_date(date.get_stop_date(), + cal, mod, quality)) else: - val = make_gedcom_date(start, cal, mod, quality) + val = libgedcom.make_gedcom_date(start, cal, mod, quality) self.__writeln(level, 'DATE', val) elif date.get_text(): self.__writeln(level, 'DATE', date.get_text()) @@ -1405,6 +1406,4 @@ def export_data(database, filename, option_box=None, callback=None): ErrorDialog(msg2, str(msg)) except Errors.DatabaseError, msg: ErrorDialog(_("Export failed"), str(msg)) - except: - ErrorDialog(_("Could not create %s") % filename) return ret diff --git a/src/plugins/lib/libgedcom.py b/src/plugins/lib/libgedcom.py index 7f5867a0b..86b33f3bb 100644 --- a/src/plugins/lib/libgedcom.py +++ b/src/plugins/lib/libgedcom.py @@ -549,6 +549,42 @@ GED_TO_GRAMPS_ATTR = {} for __val, __key in personalConstantAttributes.iteritems(): if __key != "": GED_TO_GRAMPS_ATTR[__key] = __val + +#------------------------------------------------------------------------- +# +# GEDCOM Date Constants +# +#------------------------------------------------------------------------- +HMONTH = [ + "", "ELUL", "TSH", "CSH", "KSL", "TVT", "SHV", "ADR", + "ADS", "NSN", "IYR", "SVN", "TMZ", "AAV", "ELL" ] + +FMONTH = [ + "", "VEND", "BRUM", "FRIM", "NIVO", "PLUV", "VENT", + "GERM", "FLOR", "PRAI", "MESS", "THER", "FRUC", "COMP"] + +MONTH = [ + "", "JAN", "FEB", "MAR", "APR", "MAY", "JUN", + "JUL", "AUG", "SEP", "OCT", "NOV", "DEC" ] + +CALENDAR_MAP = { + gen.lib.Date.CAL_HEBREW : (HMONTH, '@#DHEBREW@'), + gen.lib.Date.CAL_FRENCH : (FMONTH, '@#DFRENCH R@'), + gen.lib.Date.CAL_JULIAN : (MONTH, '@#DJULIAN@'), + gen.lib.Date.CAL_SWEDISH : (MONTH, '@#DUNKNOWN@'), + } + +DATE_MODIFIER = { + gen.lib.Date.MOD_ABOUT : "ABT", + gen.lib.Date.MOD_BEFORE : "BEF", + gen.lib.Date.MOD_AFTER : "AFT", + #Date.MOD_INTERPRETED : "INT", + } + +DATE_QUALITY = { + gen.lib.Date.QUAL_CALCULATED : "CAL", + gen.lib.Date.QUAL_ESTIMATED : "EST", +} #------------------------------------------------------------------------- # @@ -5835,3 +5871,65 @@ class GedcomStageOne(object): Return the number of lines in the file """ return self.lcnt + +#------------------------------------------------------------------------- +# +# make_gedcom_date +# +#------------------------------------------------------------------------- +def make_gedcom_date(subdate, calendar, mode, quality): + """ + Convert a GRAMPS date structure into a GEDCOM compatible date. + """ + retval = "" + (day, mon, year) = subdate[0:3] + (mmap, prefix) = CALENDAR_MAP.get(calendar, (MONTH, "")) + if year < 0: + year = -year + bce = " B.C." + else: + bce = "" + try: + retval = __build_date_string(day, mon, year, bce, mmap) + except IndexError: + print "Month index error - %d" % mon + retval = "%d%s" % (year, bce) + if calendar == gen.lib.Date.CAL_SWEDISH: + # If Swedish calendar use ISO for for date and append (swedish) + # to indicate calandar + if year and not mon and not day: + retval = "%i" % (year) + else: + retval = "%i-%02i-%02i" % (year, mon, day) + retval = retval + " (swedish)" + # Skip prefix @#DUNKNOWN@ as it seems + # not used in all other genealogy applications. + # GRAMPS can handle it on import, but not with (swedish) appended + # to explain what calendar, the unknown refer to + prefix = "" + if prefix: + retval = "%s %s" % (prefix, retval) + if mode in DATE_MODIFIER: + retval = "%s %s" % (DATE_MODIFIER[mode], retval) + if quality in DATE_QUALITY: + retval = "%s %s" % (DATE_QUALITY[quality], retval) + return retval + +def __build_date_string(day, mon, year, bce, mmap): + """ + Build a date string from the supplied information. + """ + if day == 0: + if mon == 0: + retval = '%d%s' % (year, bce) + elif year == 0: + retval = '(%s)' % mmap[mon] + else: + retval = "%s %d%s" % (mmap[mon], year, bce) + elif mon == 0: + retval = '%d%s' % (year, bce) + elif year == 0: + retval = "(%d %s)" % (day, mmap[mon]) + else: + retval = "%d %s %d%s" % (day, mmap[mon], year, bce) + return retval \ No newline at end of file diff --git a/src/plugins/webreport/NarrativeWeb.py b/src/plugins/webreport/NarrativeWeb.py index 862df4155..0f5553715 100644 --- a/src/plugins/webreport/NarrativeWeb.py +++ b/src/plugins/webreport/NarrativeWeb.py @@ -5,7 +5,7 @@ # Copyright (C) 2007 Johan Gonqvist # Copyright (C) 2007-2009 Gary Burton # Copyright (C) 2007-2009 Stephane Charette -# Copyright (C) 2008 Brian G. Matherly +# Copyright (C) 2008-2009 Brian G. Matherly # Copyright (C) 2008 Jason M. Simanek # Copyright (C) 2008-2009 Rob G. Healey # @@ -29,16 +29,6 @@ """ Narrative Web Page generator. """ - -#------------------------------------------------------------------------ -# -# Suggested pylint usage: -# --max-line-length=100 Yes, I know PEP8 suggest 80, but this has longer lines -# --argument-rgx='[a-z_][a-z0-9_]{1,30}$' Several identifiers are two characters -# --variable-rgx='[a-z_][a-z0-9_]{1,30}$' Several identifiers are two characters -# -#------------------------------------------------------------------------ - #------------------------------------------------------------------------ # # python modules @@ -59,8 +49,6 @@ import shutil import codecs import tarfile import tempfile -import operator -from gen.ggettext import sgettext as _ from cStringIO import StringIO from textwrap import TextWrapper from unicodedata import normalize @@ -77,10 +65,10 @@ log = logging.getLogger(".WebPage") #------------------------------------------------------------------------ # GRAMPS module #------------------------------------------------------------------------ +from gen.ggettext import sgettext as _ import gen.lib from gen.lib import UrlType, EventType, Person, date, Date, ChildRefType, \ FamilyRelType, NameType, Name -from gen.lib.date import make_gedcom_date import const import Sort from gen.plug.menu import PersonOption, NumberOption, StringOption, \ @@ -107,6 +95,8 @@ from libhtml import Html # src/plugins/lib/libhtmlbackend.py from libhtmlbackend import HtmlBackend +from libgedcom import make_gedcom_date + #------------------------------------------------------------------------ # # constants