From 42cfd52db43ba7f8a79f10023bed231352f389fc Mon Sep 17 00:00:00 2001 From: Don Allingham Date: Wed, 27 Feb 2002 01:18:49 +0000 Subject: [PATCH] REFN changes for GEDCOM import svn: r802 --- gramps/src/Makefile.in | 1 + gramps/src/RelLib.py | 4 +-- gramps/src/docgen/OpenOfficeDoc.py | 2 -- gramps/src/gramps_main.py | 10 ++++++- gramps/src/plugins/ReadGedcom.py | 47 +++++++++++++++++++++++++++--- 5 files changed, 55 insertions(+), 9 deletions(-) diff --git a/gramps/src/Makefile.in b/gramps/src/Makefile.in index 97be2975d..47b1e6a6b 100644 --- a/gramps/src/Makefile.in +++ b/gramps/src/Makefile.in @@ -34,6 +34,7 @@ intl22.so: intl.c install: ${INSTALL} -d ${datadir} + (cd ${datadir} ;rm -f *.py *.pyo *.pyc *.glade *.xpm *.so) ${INSTALL} *.py *.jpg *.pyo *.png *.glade *.xpm *.so ${datadir} ${INSTALL} -d ${prefix}/share/pixmaps ${INSTALL} gramps.png ${prefix}/share/pixmaps diff --git a/gramps/src/RelLib.py b/gramps/src/RelLib.py index d52f5c72f..2304432f0 100644 --- a/gramps/src/RelLib.py +++ b/gramps/src/RelLib.py @@ -1701,8 +1701,8 @@ class GrampsDB: for p in self.personMap.values(): p.MainFamily = None - p.AltFamilyList = None - p.FamilyList = None + p.AltFamilyList = [] + p.FamilyList = [] self.personMap = {} self.sourceMap = {} diff --git a/gramps/src/docgen/OpenOfficeDoc.py b/gramps/src/docgen/OpenOfficeDoc.py index 21010c211..38bf0fc20 100644 --- a/gramps/src/docgen/OpenOfficeDoc.py +++ b/gramps/src/docgen/OpenOfficeDoc.py @@ -229,8 +229,6 @@ class OpenOfficeDoc(TextDoc): image = ImgManip.ImgManip(name) (x,y) = image.size() - aspect_ratio = float(x)/float(y) - ratio = float(x_cm)*float(y)/(float(y_cm)*float(x)) if ratio < 1: diff --git a/gramps/src/gramps_main.py b/gramps/src/gramps_main.py index 84b780d78..ab481c066 100755 --- a/gramps/src/gramps_main.py +++ b/gramps/src/gramps_main.py @@ -520,7 +520,7 @@ class Gramps: if val == 1: return self.clear_database() - DbPrompter.DbPrompter(self.database,1) + DbPrompter.DbPrompter(self,1) def clear_database(self): """Clear out the database if permission was granted""" @@ -1146,6 +1146,14 @@ class Gramps: file = self.database.getSavePath() self.database.new() + self.active_person = None + self.active_father = None + self.active_family = None + self.active_mother = None + self.active_child = None + self.active_spouse = None + self.id2col = {} + self.alt2col = {} self.read_file(file) Utils.clearModified() Utils.clear_timer() diff --git a/gramps/src/plugins/ReadGedcom.py b/gramps/src/plugins/ReadGedcom.py index 97f731fcd..1bc8d2381 100644 --- a/gramps/src/plugins/ReadGedcom.py +++ b/gramps/src/plugins/ReadGedcom.py @@ -67,6 +67,7 @@ for val in const.familyConstantEvents.keys(): if key != "": ged2fam[key] = val +intRE = re.compile(r"\s*(\d+)\s*$") lineRE = re.compile(r"\s*(\d+)\s+(\S+)\s*(.*)$") headRE = re.compile(r"\s*(\d+)\s+HEAD") nameRegexp= re.compile(r"/?([^/]*)(/([^/]*)(/([^/]*))?)?") @@ -108,6 +109,7 @@ def importData(database, filename): return g.parse_gedcom_file() + g.resolve_refns() statusTop.get_widget("close").set_sensitive(1) @@ -142,6 +144,8 @@ class GedcomParser: self.fmap = {} self.smap = {} self.nmap = {} + self.refn = {} + self.added = [] self.gedmap = GedcomInfoDB() self.gedsource = None self.dir_path = os.path.dirname(file) @@ -367,6 +371,7 @@ class GedcomParser: self.update(self.people_obj,str(self.indi_count)) self.indi_count = self.indi_count + 1 self.person = self.db.findPerson(matches[1],self.pmap) + self.added.append(self.person) self.parse_individual() elif matches[2] in ["SUBM","SUBN"]: self.ignore_sub_junk(1) @@ -701,10 +706,8 @@ class GedcomParser: self.parse_source_reference(source_ref,2) self.person.getPrimaryName().addSourceRef(source_ref) elif matches[1] == "REFN": - attr = Attribute() - attr.setType("Reference Number") - attr.setValue(matches[2]) - self.person.addAttribute(attr) + if intRE.match(matches[2]): + self.refn[self.person] = int(matches[2]) elif matches[1] in ["AFN","CHAN","REFN","ASSO"]: self.ignore_sub_junk(2) elif matches[1] in ["ANCI","DESI","RIN","RFN"]: @@ -1635,6 +1638,42 @@ class GedcomParser: return dateobj + def resolve_refns(self): + prefix = self.db.iprefix + pmap = self.db.getPersonMap() + renamed = [] + new_pmax = self.db.pmapIndex + for person in self.added: + if self.refn.has_key(person): + val = self.refn[person] + new_key = prefix % val + new_pmax = max(new_pmax,val) + + # new ID is not used + if not pmap.has_key(new_key): + del pmap[person.getId()] + pmap[new_key] = person + person.setId(new_key) + else: + tp = pmap[new_key] + # same person, just change it + if person == tp: + del pmap[person.getId()] + pmap[new_key] = person + person.setId(new_key) + # person currently using it was just added, change it + elif tp in self.added: + if not self.refn.has_key(tp): + renamed.append(tp) + del pmap[person.getId()] + pmap[new_key] = person + person.setId(new_key) + + self.db.pmapIndex = new_pmax + for person in renamed: + del pmap[person] + self.db.addPerson(person) + #------------------------------------------------------------------------- # #