2006-05-01  Alex Roitman  <shura@gramps-project.org>
	* various: merge changes from gramps20.

In po:
2006-05-01  Alex Roitman  <shura@gramps-project.org>
	* POTFILES.in: Add new file.



svn: r6504
This commit is contained in:
Alex Roitman
2006-05-01 21:11:26 +00:00
parent bb9f7dc74d
commit 3fe3482efb
44 changed files with 2077 additions and 647 deletions

View File

@@ -164,6 +164,10 @@ lds_status = {
_event_family_str = _("%(event_name)s of %(family)s")
_event_person_str = _("%(event_name)s of %(person)s")
_transtable = string.maketrans('','')
_delc = _transtable[0:31]
_transtable2 = _transtable[0:128] + ('?' * 128)
#-------------------------------------------------------------------------
#
# GEDCOM events to GRAMPS events conversion
@@ -233,7 +237,7 @@ def importData(database, filename, callback=None, use_trans=False):
def import2(database, filename, callback, codeset, use_trans):
# add some checking here
try:
np = NoteParser(filename, False)
np = NoteParser(filename, False, codeset)
g = GedcomParser(database,filename, callback, codeset, np.get_map(),
np.get_lines(),np.get_persons())
except IOError,msg:
@@ -334,43 +338,73 @@ class CurrentState:
#
#-------------------------------------------------------------------------
class NoteParser:
def __init__(self, filename,broken):
self.name_map = {}
def __init__(self, filename,broken,override):
if override:
if override == 1:
self.cnv = ansel_to_utf8
elif override == 2:
self.cnv = latin_to_utf8
else:
self.cnv = nocnv
else:
f = open(filename,"rU")
for index in range(50):
line = f.readline().split()
if len(line) > 2 and line[1] == 'CHAR':
if line[2] == "ANSEL":
self.cnv = ansel_to_utf8
elif line[2] in ["UNICODE","UTF-8","UTF8"]:
self.cnv = nocnv
else:
self.cnv = latin_to_utf8
f.close()
self.count = 0
self.person_count = 0
f = open(filename,"rU")
innote = False
self.name_map = {}
self.count = 0
self.person_count = 0
f = open(filename,"rU")
innote = False
for line in f:
for line in f:
try:
text = string.translate(line,_transtable,_delc)
except:
text = line
self.count += 1
if innote:
match = contRE.match(line)
if match:
noteobj.append("\n" + match.groups()[0])
continue
try:
text = self.cnv(text)
except:
text = string.translate(text,_transtable2)
match = concRE.match(line)
if match:
if broken:
noteobj.append(" " + match.groups()[0])
else:
noteobj.append(match.groups()[0])
continue
innote = False
else:
match = noteRE.match(line)
if match:
data = match.groups()[0]
noteobj = RelLib.Note()
self.name_map["@%s@" % data] = noteobj
noteobj.append(match.groups()[1])
innote = True
elif personRE.match(line):
self.person_count += 1
f.close()
self.count += 1
if innote:
match = contRE.match(text)
if match:
noteobj.append("\n" + match.groups()[0])
continue
match = concRE.match(text)
if match:
if broken:
noteobj.append(" " + match.groups()[0])
else:
noteobj.append(match.groups()[0])
continue
# Here we have finished parsing CONT/CONC tags for the NOTE
# and ignored the rest of the tags (SOUR,CHAN,REFN,RIN).
innote = False
match = noteRE.match(text)
if match:
data = match.groups()[0]
noteobj = RelLib.Note()
self.name_map["@%s@" % data] = noteobj
noteobj.append(match.groups()[1])
innote = True
elif personRE.match(line):
self.person_count += 1
f.close()
def get_map(self):
return self.name_map
@@ -392,9 +426,6 @@ class Reader:
self.f = open(name,'rU')
self.current_list = []
self.eof = False
self.transtable = string.maketrans('','')
self.delc = self.transtable[0:31]
self.transtable2 = self.transtable[0:128] + ('?' * 128)
self.cnv = lambda s: unicode(s)
self.broken_conc = False
self.cnt = 0
@@ -426,11 +457,11 @@ class Reader:
break
line = line.split(None,2) + ['']
val = line[2].translate(self.transtable,self.delc)
val = line[2].translate(_transtable,_delc)
try:
val = self.cnv(val)
except:
val = self.cnv(val.translate(self.transtable2))
val = self.cnv(val.translate(_transtable2))
try:
level = int(line[0])
@@ -1168,23 +1199,21 @@ class GedcomParser:
del event
def parse_note_base(self,matches,obj,level,old_note,task):
note = old_note
if matches[2] and matches[2][0] == "@": # reference to a named note defined elsewhere
# reference to a named note defined elsewhere
if matches[2] and matches[2][0] == "@":
note_obj = self.note_map.get(matches[2])
if note_obj:
return note_obj.get()
new_note = note_obj.get()
else:
return u""
new_note = u""
else:
if old_note:
note = u"%s\n%s" % (old_note,matches[2])
else:
note = matches[2]
if type(note) != unicode:
print type(note),type(matches[2])
task(note)
new_note = matches[2] + self.parse_continue_data(level)
self.ignore_sub_junk(level+1)
if old_note:
note = u"%s\n%s" % (old_note,matches[2])
else:
note = new_note
task(note)
return note
def parse_note(self,matches,obj,level,old_note):
@@ -1489,7 +1518,7 @@ class GedcomParser:
event.set_cause(info)
self.parse_cause(event,level+1)
elif matches[1] in (TOKEN_NOTE,TOKEN_OFFI):
info = matches[2]
info = self.parse_note(matches,event,level+1,note)
if note == "":
note = info
else:
@@ -1548,7 +1577,7 @@ class GedcomParser:
event.set_cause(info)
self.parse_cause(event,level+1)
elif matches[1] == TOKEN_NOTE:
info = matches[2]
info = self.parse_note(matches,event,level+1,note)
if note == "":
note = info
else:
@@ -1604,7 +1633,7 @@ class GedcomParser:
elif matches[1] == TOKEN_DATE:
note = "%s\n\n" % ("Date : %s" % matches[2])
elif matches[1] == TOKEN_NOTE:
info = matches[2]
info = self.parse_note(matches,attr,level+1,note)
if note == "":
note = info
else:
@@ -1741,6 +1770,7 @@ class GedcomParser:
def parse_header_source(self):
genby = ""
note = ""
while True:
matches = self.get_next()
if int(matches[0]) < 1:
@@ -1788,7 +1818,7 @@ class GedcomParser:
date.date = matches[2]
self.def_src.set_data_item('Creation date',matches[2])
elif matches[1] == TOKEN_NOTE:
note = matches[2]
note = self.parse_note(matches,self.def_src,2,note)
elif matches[1] == TOKEN_UNKNOWN:
self.ignore_sub_junk(2)
else:
@@ -2126,7 +2156,7 @@ class GedcomParser:
state.add_to_note(self.parse_optional_note(2))
def func_person_famc(self,matches,state):
ftype,note = self.parse_famc_type(2,state.person)
ftype,famc_note = self.parse_famc_type(2,state.person)
handle = self.find_family_handle(matches[2][1:-1])
for f in self.person.get_parent_family_handle_list():

View File

@@ -325,16 +325,6 @@ def make_date(subdate,calendar,mode):
#
#
#-------------------------------------------------------------------------
def fmtline(text,limit,level,endl):
new_text = []
while len(text) > limit:
new_text.append(text[0:limit-1])
text = text[limit:]
if len(text) > 0:
new_text.append(text)
app = "%s%d CONC " % (endl,level+1)
return app.join(new_text)
#-------------------------------------------------------------------------
#
#
@@ -782,6 +772,36 @@ class GedcomWriter:
self.dump_event_stats(event)
for attr in family.get_attribute_list():
if self.private and attr.get_privacy():
continue
name = attr.get_type()
if name in ["AFN", "RFN", "_UID"]:
self.writeln("1 %s %s" % ( name, attr.get_value()))
continue
if Utils.personal_attributes.has_key(name):
val = Utils.personal_attributes[name]
else:
val = ""
value = self.cnvtxt(attr.get_value()).replace('\r',' ')
if val:
if value:
self.writeln("1 %s %s" % (val, value))
else:
self.writeln("1 %s" % val)
else:
self.writeln("1 EVEN")
if value:
self.writeln("2 TYPE %s %s" % (self.cnvtxt(name), value))
else:
self.writeln("2 TYPE %s" % self.cnvtxt(name))
if attr.get_note():
self.write_long_text("NOTE",2,self.cnvtxt(attr.get_note()))
for srcref in attr.get_source_references():
self.write_source_ref(2,srcref)
for person_handle in family.get_child_handle_list():
if not self.plist.has_key(person_handle):
continue
@@ -815,6 +835,9 @@ class GedcomWriter:
continue
self.write_photo(photo,1)
if family.get_note():
self.write_long_text("NOTE",1,self.cnvtxt(family.get_note()))
self.write_change(1,family.get_change_time())
self.update()
@@ -831,11 +854,17 @@ class GedcomWriter:
for (source_id, source) in sorted:
self.writeln("0 @%s@ SOUR" % source_id)
if source.get_title():
self.writeln("1 TITL %s" % fmtline(self.cnvtxt(source.get_title()),248,1,self.nl))
self.write_long_text('TITL',1,
"%s" % self.cnvtxt(source.get_title()))
if source.get_author():
self.writeln("1 AUTH %s" % self.cnvtxt(source.get_author()))
self.write_long_text("AUTH", 1,
"%s" % self.cnvtxt(source.get_author()))
if source.get_publication_info():
self.writeln("1 PUBL %s" % self.cnvtxt(source.get_publication_info()))
self.write_long_text("PUBL", 1,"%s" % self.cnvtxt(
source.get_publication_info()))
if source.get_abbreviation():
self.writeln("1 ABBR %s" % self.cnvtxt(source.get_abbreviation()))
if self.images:
@@ -1113,6 +1142,10 @@ class GedcomWriter:
else:
for line in textlines:
ll = len(line)
if ll == 0:
self.writeln("%s " % prefix)
prefix = "%d CONT" % (level+1)
continue
while ll > 0:
brkpt = 70
if ll > brkpt:
@@ -1142,6 +1175,10 @@ class GedcomWriter:
else:
for line in textlines:
ll = len(line)
if ll == 0:
self.writeln("%s " % prefix)
prefix = "%d CONT" % (level+1)
continue
while ll > 0:
brkpt = 70
if ll > brkpt: