svn: r4550
This commit is contained in:
Alex Roitman 2005-05-11 14:27:32 +00:00
parent 2a77676b36
commit ed5c7adc82
4 changed files with 50 additions and 23 deletions

View File

@ -254,6 +254,7 @@ class GedcomParser:
self.dp = GedcomDateParser() self.dp = GedcomDateParser()
self.db = dbase self.db = dbase
self.person = None self.person = None
self.inline_srcs = {}
self.media_map = {} self.media_map = {}
self.fmap = {} self.fmap = {}
self.smap = {} self.smap = {}
@ -262,7 +263,7 @@ class GedcomParser:
self.refn = {} self.refn = {}
self.added = {} self.added = {}
self.gedmap = GedcomInfoDB() self.gedmap = GedcomInfoDB()
self.gedsource = None self.gedsource = self.gedmap.get_from_source_tag('GEDCOM 5.5')
self.def_src = RelLib.Source() self.def_src = RelLib.Source()
fname = os.path.basename(filename).split('\\')[-1] fname = os.path.basename(filename).split('\\')[-1]
self.def_src.set_title(_("Import from %s") % unicode(fname)) self.def_src.set_title(_("Import from %s") % unicode(fname))
@ -493,6 +494,16 @@ class GedcomParser:
if self.window: if self.window:
self.update(self.families_obj,str(self.fam_count)) self.update(self.families_obj,str(self.fam_count))
self.update(self.people_obj,str(self.indi_count)) self.update(self.people_obj,str(self.indi_count))
for value in self.inline_srcs.keys():
title,note = value
handle = self.inline_srcs[value]
src = RelLib.Source()
src.set_handle(handle)
src.set_title(title)
if note:
src.set_note(note)
self.db.add_source(src,self.trans)
self.break_note_links() self.break_note_links()
t = time.time() - t t = time.time() - t
@ -1944,16 +1955,15 @@ class GedcomParser:
def handle_source(self,matches,level): def handle_source(self,matches,level):
source_ref = RelLib.SourceRef() source_ref = RelLib.SourceRef()
if matches[2] and matches[2][0] != "@": if matches[2] and matches[2][0] != "@":
self.localref = self.localref + 1 title = matches[2]
ref = "gsr%d" % self.localref note = self.parse_continue_data(level)
s = self.find_or_create_source(ref) handle = self.inline_srcs.get((title,note),Utils.create_id())
source_ref.set_base_handle(s.get_handle()) self.inline_srcs[(title,note)] = handle
s.set_title('Imported Source #%d' % self.localref)
s.set_note(matches[2] + self.parse_continue_data(level))
self.ignore_sub_junk(level+1) self.ignore_sub_junk(level+1)
else: else:
source_ref.set_base_handle(self.find_or_create_source(matches[2][1:-1]).get_handle()) handle = self.find_or_create_source(matches[2][1:-1]).get_handle()
self.parse_source_reference(source_ref,level) self.parse_source_reference(source_ref,level)
source_ref.set_base_handle(handle)
return source_ref return source_ref
def resolve_refns(self): def resolve_refns(self):

View File

@ -325,9 +325,8 @@ class GrampsParser:
self.media_file_map = {} self.media_file_map = {}
self.callback = callback self.callback = callback
self.entries = 0
self.count = 0 self.count = 0
self.increment = 100 self.increment = 500
self.event = None self.event = None
self.name = None self.name = None
self.tempDefault = None self.tempDefault = None
@ -362,7 +361,7 @@ class GrampsParser:
"comment" : (None, self.stop_comment), "comment" : (None, self.stop_comment),
"created" : (self.start_created, None), "created" : (self.start_created, None),
"ref" : (None, self.stop_ref), "ref" : (None, self.stop_ref),
"database" : (None, None), "database" : (None, self.stop_database),
"phone" : (None, self.stop_phone), "phone" : (None, self.stop_phone),
"date" : (None, self.stop_date), "date" : (None, self.stop_date),
"cause" : (None, self.stop_cause), "cause" : (None, self.stop_cause),
@ -617,10 +616,9 @@ class GrampsParser:
title = attrs['id'] title = attrs['id']
self.placeobj.set_title(title) self.placeobj.set_title(title)
self.locations = 0 self.locations = 0
if self.num_places > 0: if self.callback != None and self.count % self.increment == 0:
if self.callback != None and self.count % self.increment == 0: self.callback(True)
self.callback(float(self.count)/float(self.entries)) self.count += 1
self.count = self.count + 1
def start_location(self,attrs): def start_location(self,attrs):
"""Bypass the function calls for this one, since it appears to """Bypass the function calls for this one, since it appears to
@ -649,6 +647,7 @@ class GrampsParser:
def start_witness(self,attrs): def start_witness(self,attrs):
self.in_witness = 1 self.in_witness = 1
self.witness_comment = ""
if attrs.has_key('hlink'): if attrs.has_key('hlink'):
self.witness = RelLib.Witness(RelLib.Event.ID,attrs['hlink']) self.witness = RelLib.Witness(RelLib.Event.ID,attrs['hlink'])
elif attrs.has_key('ref'): elif attrs.has_key('ref'):
@ -716,6 +715,8 @@ class GrampsParser:
self.db.bookmarks.append(person.get_handle()) self.db.bookmarks.append(person.get_handle())
def start_person(self,attrs): def start_person(self,attrs):
if self.callback != None and self.count % self.increment == 0:
self.callback(True)
new_id = self.map_gid(attrs['id']) new_id = self.map_gid(attrs['id'])
try: try:
self.person = self.db.find_person_from_handle(attrs['handle'],self.trans) self.person = self.db.find_person_from_handle(attrs['handle'],self.trans)
@ -778,7 +779,7 @@ class GrampsParser:
def start_family(self,attrs): def start_family(self,attrs):
if self.callback != None and self.count % self.increment == 0: if self.callback != None and self.count % self.increment == 0:
self.callback(float(self.count)/float(self.entries)) self.callback(True)
self.count = self.count + 1 self.count = self.count + 1
handle = self.map_fid(attrs["id"]) handle = self.map_fid(attrs["id"])
try: try:
@ -941,6 +942,10 @@ class GrampsParser:
def stop_people(self,*tag): def stop_people(self,*tag):
pass pass
def stop_database(self,*tag):
if self.callback:
self.callback(False)
def stop_object(self,*tag): def stop_object(self,*tag):
self.db.commit_media_object(self.object,self.trans,self.change) self.db.commit_media_object(self.object,self.trans,self.change)
self.object = None self.object = None
@ -1054,7 +1059,6 @@ class GrampsParser:
bc = -1 bc = -1
val = val[1:] val = val[1:]
start = val.split('-') start = val.split('-')
try: try:
y = int(start[0])*bc y = int(start[0])*bc
except: except:
@ -1071,7 +1075,7 @@ class GrampsParser:
d = 0 d = 0
if attrs.has_key("cformat"): if attrs.has_key("cformat"):
cal = Date.Date.calendar_names.index(attrs['calendar']) cal = Date.Date.calendar_names.index(attrs['cformat'])
else: else:
cal = Date.CAL_GREGORIAN cal = Date.CAL_GREGORIAN
@ -1113,8 +1117,6 @@ class GrampsParser:
self.num_places = int(attrs['places']) self.num_places = int(attrs['places'])
else: else:
self.num_places = 0 self.num_places = 0
self.entries = int(attrs["people"]) + int(attrs["families"]) + \
self.num_places + self.num_srcs
def start_pos(self,attrs): def start_pos(self,attrs):
self.person.position = (int(attrs["x"]), int(attrs["y"])) self.person.position = (int(attrs["x"]), int(attrs["y"]))

View File

@ -34,6 +34,7 @@ from gettext import gettext as _
import os import os
import time import time
import re import re
import locale
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
@ -48,13 +49,20 @@ import DateHandler
# Confidence levels # Confidence levels
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
CONF_VERY_HIGH = 4 CONF_VERY_HIGH = 4
CONF_HIGH = 3 CONF_HIGH = 3
CONF_NORMAL = 2 CONF_NORMAL = 2
CONF_LOW = 1 CONF_LOW = 1
CONF_VERY_LOW = 0 CONF_VERY_LOW = 0
#-------------------------------------------------------------------------
#
# Localized constants
#
#-------------------------------------------------------------------------
_date_format = locale.nl_langinfo(locale.D_T_FMT)
_codeset = locale.nl_langinfo(locale.CODESET)
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
# Base classes # Base classes
@ -231,7 +239,9 @@ class PrimaryObject(BaseObject):
""" """
if self.change: if self.change:
return time.asctime(time.localtime(self.change)) return unicode(time.strftime(_date_format,
time.localtime(self.change)),
_codeset)
else: else:
return '' return ''

View File

@ -908,6 +908,11 @@ def married_str(database,person,spouse,event,endnotes=None,
def married_rel_str(database,person,family,is_first=True): def married_rel_str(database,person,family,is_first=True):
spouse_handle = find_spouse(person,family) spouse_handle = find_spouse(person,family)
spouse = database.get_person_from_handle(spouse_handle) spouse = database.get_person_from_handle(spouse_handle)
# not all families have a spouse.
if not spouse_handle or not spouse:
return u""
spouse_name = _nd.display(spouse) spouse_name = _nd.display(spouse)
if is_first: if is_first:
@ -1796,6 +1801,6 @@ def old_calc_age(database,person):
age = age - 1 age = age - 1
units = 2 # month units = 2 # month
if age == 0: if age == 0:
age = death.get-day() + 31 - birth.get_day() # calc age in days age = death.get_day() + 31 - birth.get_day() # calc age in days
units = 3 # day units = 3 # day
return (age,units) return (age,units)