2007-02-18 Don Allingham <don@gramps-project.org>

* src/GrampsDbUtils/_GedcomUtils.py: Add IdMapper class
	* src/GrampsDbUtils/_GedcomParser.py: refactoring



svn: r8167
This commit is contained in:
Don Allingham 2007-02-19 05:22:29 +00:00
parent f53f1abc21
commit 358b537986
3 changed files with 608 additions and 518 deletions

View File

@ -1,3 +1,7 @@
2007-02-18 Don Allingham <don@gramps-project.org>
* src/GrampsDbUtils/_GedcomUtils.py: Add IdMapper class
* src/GrampsDbUtils/_GedcomParser.py: refactoring
2007-02-18 Brian Matherly <brian@gramps-project.org>
* src/ReportBase/_PaperMenu.py: rename PaperStyle to PaperSize
* src/docgen/HtmlDoc.py: rename PaperStyle to PaperSize

File diff suppressed because it is too large Load Diff

View File

@ -102,7 +102,6 @@ class PlaceParser:
self.pf[index](loc, item)
index += 1
class IdFinder:
"""
Provides method of finding the next available ID.
@ -131,6 +130,39 @@ class IdFinder:
self.index += 1
return index
class IdMapper:
def __init__(self, trans, find_next, translate):
if translate:
self.__getitem__ = self.get_translate
else:
self.__getitem__ = self.no_translate
self.trans = trans
self.find_next = find_next
self.swap = {}
def clean(self, gid):
temp = gid.strip()
if temp[0] == '@' and temp[-1] == '@':
temp = temp[1:-1]
return temp
def no_translate(self, gid):
return self.clean(gid)
def get_translate(self, id):
gid = self.clean(gid)
new_id = self.swap.has_key(gid)
if new_id:
return new_id
else:
if self.trans.get(str(gid)):
new_val = self.find_next()
else:
new_val = gid
self.swap[gid] = new_val
return new_val
#------------------------------------------------------------------------
#
# Support functions