Move GEDCOM date functions into libgedcom.
svn: r14125
This commit is contained in:
parent
1f4043b37a
commit
c9cb7e60c9
@ -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):
|
||||
"""
|
||||
|
@ -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
|
||||
|
@ -550,6 +550,42 @@ 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",
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
# regular expressions
|
||||
@ -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
|
@ -5,7 +5,7 @@
|
||||
# Copyright (C) 2007 Johan Gonqvist <johan.gronqvist@gmail.com>
|
||||
# Copyright (C) 2007-2009 Gary Burton <gary.burton@zen.co.uk>
|
||||
# Copyright (C) 2007-2009 Stephane Charette <stephanecharette@gmail.com>
|
||||
# Copyright (C) 2008 Brian G. Matherly
|
||||
# Copyright (C) 2008-2009 Brian G. Matherly
|
||||
# Copyright (C) 2008 Jason M. Simanek <jason@bohemianalps.com>
|
||||
# Copyright (C) 2008-2009 Rob G. Healey <robhealey1@gmail.com>
|
||||
#
|
||||
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user