pylint on Gedcom importer and exporter

This commit is contained in:
prculley 2017-08-22 10:55:55 -05:00 committed by Nick Hall
parent 436509edf6
commit ac4ba4cb0b
2 changed files with 1029 additions and 886 deletions

View File

@ -44,12 +44,10 @@ from gramps.gen.const import GRAMPS_LOCALE as glocale
_ = glocale.translation.gettext
from gramps.gen.lib import (AttributeType, ChildRefType, Citation, Date,
EventRoleType, EventType, LdsOrd, NameType,
PlaceType, NoteType, Person, UrlType,
SrcAttributeType)
PlaceType, NoteType, Person, UrlType)
from gramps.version import VERSION
import gramps.plugins.lib.libgedcom as libgedcom
from gramps.gen.errors import DatabaseError
from gramps.gui.plug.export import WriterOptionBox
from gramps.gen.updatecallback import UpdateCallback
from gramps.gen.utils.file import media_path_full
from gramps.gen.utils.place import conv_lat_lon
@ -91,14 +89,12 @@ LDS_STATUS = {
}
LANGUAGES = {
'cs' : 'Czech', 'da' : 'Danish', 'nl' : 'Dutch',
'en' : 'English', 'eo' : 'Esperanto', 'fi' : 'Finnish',
'fr' : 'French', 'de' : 'German', 'hu' : 'Hungarian',
'it' : 'Italian', 'lt' : 'Latvian', 'lv' : 'Lithuanian',
'no' : 'Norwegian', 'po' : 'Polish', 'pt' : 'Portuguese',
'ro' : 'Romanian', 'sk' : 'Slovak', 'es' : 'Spanish',
'sv' : 'Swedish', 'ru' : 'Russian',
}
'cs' : 'Czech', 'da' : 'Danish', 'nl' : 'Dutch', 'en' : 'English',
'eo' : 'Esperanto', 'fi' : 'Finnish', 'fr' : 'French', 'de' : 'German',
'hu' : 'Hungarian', 'it' : 'Italian', 'lt' : 'Latvian',
'lv' : 'Lithuanian', 'no' : 'Norwegian', 'po' : 'Polish',
'pt' : 'Portuguese', 'ro' : 'Romanian', 'sk' : 'Slovak',
'es' : 'Spanish', 'sv' : 'Swedish', 'ru' : 'Russian', }
#-------------------------------------------------------------------------
#
@ -130,6 +126,8 @@ PEDIGREE_TYPES = {
}
NOTES_PER_PERSON = 104 # fudge factor to make progress meter a bit smoother
#-------------------------------------------------------------------------
#
# sort_handles_by_id
@ -152,6 +150,7 @@ def sort_handles_by_id(handle_list, handle_to_object):
sorted_list.sort()
return sorted_list
#-------------------------------------------------------------------------
#
# breakup
@ -170,8 +169,8 @@ def breakup(txt, limit):
# look for non-space pair to break between
# do not break within a UTF-8 byte sequence, i. e. first char >127
idx = limit
while (idx>0 and (txt[idx-1].isspace() or txt[idx].isspace()
or ord(txt[idx-1]) > 127)):
while (idx > 0 and (txt[idx - 1].isspace() or txt[idx].isspace() or
ord(txt[idx - 1]) > 127)):
idx -= 1
if idx == 0:
#no words to break on, just break at limit anyway
@ -191,6 +190,7 @@ def breakup(txt, limit):
#
#-------------------------------------------------------------------------
def event_has_subordinate_data(event, event_ref):
""" determine if event is empty or not """
if event and event_ref:
return (event.get_description().strip() or
not event.get_date_object().is_empty() or
@ -273,7 +273,7 @@ class GedcomWriter(UpdateCallback):
into multiple lines using CONC.
"""
assert(token)
assert token
if textlines:
# break the line into multiple lines if a newline is found
textlines = textlines.replace('\n\r', '\n')
@ -288,7 +288,8 @@ class GedcomWriter(UpdateCallback):
txt = prefix.join(breakup(text, limit))
else:
txt = text
self.gedcom_file.write("%d %s %s\n" % (token_level, token, txt))
self.gedcom_file.write("%d %s %s\n" %
(token_level, token, txt))
token_level = level + 1
token = "CONT"
else:
@ -551,7 +552,8 @@ class GedcomWriter(UpdateCallback):
adop_written = False
for event_ref in person.get_event_ref_list():
event = self.dbase.get_event_from_handle(event_ref.ref)
if not event: continue
if not event:
continue
self._process_person_event(person, event, event_ref)
if not adop_written:
self._adoption_records(person, adop_written)
@ -854,7 +856,8 @@ class GedcomWriter(UpdateCallback):
for cref in child_ref_list]
for gid in child_list:
if gid is None: continue
if gid is None:
continue
self._writeln(1, 'CHIL', '@%s@' % gid)
def _family_reference(self, token, person_handle):
@ -880,7 +883,8 @@ class GedcomWriter(UpdateCallback):
"""
for event_ref in family.get_event_ref_list():
event = self.dbase.get_event_from_handle(event_ref.ref)
if event is None: continue
if event is None:
continue
self._process_family_event(event, event_ref)
self._dump_event_stats(event, event_ref)
@ -973,7 +977,8 @@ class GedcomWriter(UpdateCallback):
for (source_id, handle) in sorted_list:
self.update()
source = self.dbase.get_source_from_handle(handle)
if source is None: continue
if source is None:
continue
self._writeln(0, '@%s@' % source_id, 'SOUR')
if source.get_title():
self._writeln(1, 'TITL', source.get_title())
@ -1011,7 +1016,8 @@ class GedcomWriter(UpdateCallback):
self.update()
note_cnt += 1
note = self.dbase.get_note_from_handle(note_handle)
if note is None: continue
if note is None:
continue
self._note_record(note)
def _note_record(self, note):
@ -1025,7 +1031,8 @@ class GedcomWriter(UpdateCallback):
+1 <<CHANGE_DATE>> {0:1}
"""
if note:
self._writeln(0, '@%s@' % note.get_gramps_id(), 'NOTE ' + note.get())
self._writeln(0, '@%s@' % note.get_gramps_id(),
'NOTE ' + note.get())
def _repos(self):
"""
@ -1050,7 +1057,8 @@ class GedcomWriter(UpdateCallback):
for (repo_id, handle) in sorted_list:
self.update()
repo = self.dbase.get_repository_from_handle(handle)
if repo is None: continue
if repo is None:
continue
self._writeln(0, '@%s@' % repo_id, 'REPO')
if repo.get_name():
self._writeln(1, 'NAME', repo.get_name())
@ -1138,8 +1146,7 @@ class GedcomWriter(UpdateCallback):
if int(attr.get_type()) == AttributeType.TIME]
# Not legal, but inserted by PhpGedView
if len(times) > 0:
time = times[0]
self._writeln(3, 'TIME', time)
self._writeln(3, 'TIME', times[0])
place = None
@ -1220,11 +1227,13 @@ class GedcomWriter(UpdateCallback):
family_handle = lds_ord.get_family_handle()
family = self.dbase.get_family_from_handle(family_handle)
if family:
self._writeln(index+1, 'FAMC', '@%s@' % family.get_gramps_id())
self._writeln(index + 1, 'FAMC', '@%s@' %
family.get_gramps_id())
if lds_ord.get_temple():
self._writeln(index + 1, 'TEMP', lds_ord.get_temple())
if lds_ord.get_place_handle():
place = self.dbase.get_place_from_handle(lds_ord.get_place_handle())
place = self.dbase.get_place_from_handle(
lds_ord.get_place_handle())
self._place(place, lds_ord.get_date_object(), 2)
if lds_ord.get_status() != LdsOrd.STATUS_NONE:
self._writeln(2, 'STAT', LDS_STATUS[lds_ord.get_status()])
@ -1358,7 +1367,6 @@ class GedcomWriter(UpdateCallback):
self._writeln(level + 1, 'PAGE', citation.get_page()[0:248],
limit=248)
conf = min(citation.get_confidence_level(),
Citation.CONF_VERY_HIGH)
if conf != Citation.CONF_NORMAL and conf != -1:
@ -1443,7 +1451,8 @@ class GedcomWriter(UpdateCallback):
+2 LONG <PLACE_LONGITUDE> {1:1}
+1 <<NOTE_STRUCTURE>> {0:M}
"""
if place is None: return
if place is None:
return
place_name = _pd.display(self.dbase, place, dateobj)
self._writeln(level, "PLAC", place_name.replace('\r', ' '), limit=120)
longitude = place.get_longitude()
@ -1466,7 +1475,7 @@ class GedcomWriter(UpdateCallback):
country = location.get(PlaceType.COUNTRY)
postal_code = place.get_code()
if (street or locality or city or state or postal_code or country):
if street or locality or city or state or postal_code or country:
self._writeln(level, "ADDR", street)
if street:
self._writeln(level + 1, 'ADR1', street)
@ -1535,6 +1544,7 @@ class GedcomWriter(UpdateCallback):
if addr.get_country():
self._writeln(level + 1, 'CTRY', addr.get_country())
#-------------------------------------------------------------------------
#
#

File diff suppressed because it is too large Load Diff