2006-06-05 Don Allingham <don@gramps-project.org>

* src/Mime/_PythonMime.py (_type_map): register .gpkg for non-linux
	platforms 



svn: r6862
This commit is contained in:
Don Allingham 2006-06-05 18:49:31 +00:00
parent 47914d99f8
commit 6a1b76786c
3 changed files with 153 additions and 91 deletions

View File

@ -1,3 +1,7 @@
2006-06-05 Don Allingham <don@gramps-project.org>
* src/Mime/_PythonMime.py (_type_map): register .gpkg for non-linux
platforms
2006-06-04 Alex Roitman <shura@gramps-project.org> 2006-06-04 Alex Roitman <shura@gramps-project.org>
* configure.in: Set up for the next release. * configure.in: Set up for the next release.
* src/Filters/Rules/Person/_RegExpName.py (RegExpName.labels): Typo. * src/Filters/Rules/Person/_RegExpName.py (RegExpName.labels): Typo.
@ -10,7 +14,6 @@
* src/plugins/WriteCD.py: fail gracefully without Gnome * src/plugins/WriteCD.py: fail gracefully without Gnome
2006-06-04 Don Allingham <don@gramps-project.org> 2006-06-04 Don Allingham <don@gramps-project.org>
* src/plugins/Makefile.am (pkgdata_PYTHON): remove FilterEditor.py * src/plugins/Makefile.am (pkgdata_PYTHON): remove FilterEditor.py
2006-06-04 Alex Roitman <shura@gramps-project.org> 2006-06-04 Alex Roitman <shura@gramps-project.org>

View File

@ -77,16 +77,15 @@ from QuestionDialog import ErrorDialog, WarningDialog
from _GrampsDbBase import EVENT_KEY from _GrampsDbBase import EVENT_KEY
from BasicUtils import UpdateCallback from BasicUtils import UpdateCallback
#-------------------------------------------------------------------------
#
# Address/Place constants
#
#-------------------------------------------------------------------------
addr_re = re.compile('(.+)([\n\r]+)(.+)\s*,(.+)\s+(\d+)\s*(.*)') addr_re = re.compile('(.+)([\n\r]+)(.+)\s*,(.+)\s+(\d+)\s*(.*)')
addr2_re = re.compile('(.+)([\n\r]+)(.+)\s*,(.+)\s+(\d+)') addr2_re = re.compile('(.+)([\n\r]+)(.+)\s*,(.+)\s+(\d+)')
addr3_re = re.compile('(.+)([\n\r]+)(.+)\s*,(.+)') addr3_re = re.compile('(.+)([\n\r]+)(.+)\s*,(.+)')
#-------------------------------------------------------------------------
#
# latin/utf8 conversions
#
#-------------------------------------------------------------------------
_place_field = [] _place_field = []
_place_match = { _place_match = {
'city' : RelLib.Location.set_city, 'city' : RelLib.Location.set_city,
@ -95,6 +94,12 @@ _place_match = {
'state' : RelLib.Location.set_state, 'state' : RelLib.Location.set_state,
} }
#-------------------------------------------------------------------------
#
# latin/utf8 conversions
#
#-------------------------------------------------------------------------
def _empty_func(a,b): def _empty_func(a,b):
return return
@ -600,23 +605,8 @@ class GedcomParser(UpdateCallback):
self.gedattr = {} self.gedattr = {}
for val in amap.keys(): for val in amap.keys():
self.gedattr[amap[val]] = val self.gedattr[amap[val]] = val
self.search_paths = [] self.search_paths = []
try:
mypaths = []
f = open("/proc/mounts","r")
for line in f:
paths = line.split()
ftype = paths[2].upper()
if ftype in file_systems.keys():
mypaths.append((paths[1],file_systems[ftype]))
self.search_paths.append(paths[1])
f.close()
except:
pass
def errmsg(self,msg): def errmsg(self,msg):
log.warning(msg) log.warning(msg)
@ -650,6 +640,39 @@ class GedcomParser(UpdateCallback):
else: else:
return (0,tries) return (0,tries)
def level_is_finished(self, text, level):
"""
Check to see if the level has been completed, indicated by finding
a level indiciated by the passed level value. If the level is finished,
then make sure to call self.backup to reset the text pointer.
"""
done = int(text[0]) < level
if done:
self.backup()
return True
return False
def parse_name_personal(self, text):
name = RelLib.Name()
# parse the substrings into a format of (Given, Surname, Suffix)
m = snameRegexp.match(text)
if m:
names = m.groups()
name.set_first_name(names[2].strip())
name.set_surname(names[0].strip())
else:
try:
names = nameRegexp.match(text).groups()
name.set_first_name(names[0].strip())
name.set_surname(names[2].strip())
name.set_suffix(names[4].strip())
except:
name.set_first_name(text.strip())
return name
def get_next(self): def get_next(self):
if not self.backoff: if not self.backoff:
self.groups = self.lexer.read() self.groups = self.lexer.read()
@ -823,18 +846,7 @@ class GedcomParser(UpdateCallback):
self.db.commit_family(self.family, self.trans) self.db.commit_family(self.family, self.trans)
del self.family del self.family
elif matches[2] == "INDI": elif matches[2] == "INDI":
self.indi_count = self.indi_count + 1 self.parse_INDI(matches)
gid = matches[3]
gid = gid[1:-1]
self.person = self.find_or_create_person(self.map_gid(gid))
self.added.add(self.person.handle)
self.parse_individual(self.person)
if len(self.person.get_source_references()) == 0:
sref = RelLib.SourceRef()
sref.set_reference_handle(self.def_src.handle)
self.person.add_source_reference(sref)
self.db.commit_person(self.person, self.trans)
del self.person
elif matches[2] == "REPO": elif matches[2] == "REPO":
self.repo_count = self.repo_count + 1 self.repo_count = self.repo_count + 1
self.repo = self.find_or_create_repository(matches[3][1:-1]) self.repo = self.find_or_create_repository(matches[3][1:-1])
@ -1190,18 +1202,55 @@ class GedcomParser(UpdateCallback):
def parse_comment(self,matches,obj,level,old_note): def parse_comment(self,matches,obj,level,old_note):
return self.parse_note_base(matches,obj,level,old_note,obj.set_note) return self.parse_note_base(matches,obj,level,old_note,obj.set_note)
def extract_gramps_id(self, value):
"""
Extracts a value to use for the GRAMPS ID value from the GEDCOM
reference token. The value should be in the form of @XXX@, and the
returned value will be XXX
"""
return value[1:-1]
def parse_INDI(self, matches):
"""
Handling of the GEDCOM INDI tag. The maintenence stuff is handled here,
which that actual parsing is done by self.parse_individual
"""
# find the person
self.indi_count += 1
gid = self.extract_gramps_id(matches[3])
self.person = self.find_or_create_person(self.map_gid(gid))
self.added.add(self.person.handle)
# do the actual parsing
self.parse_individual(self.person)
# Add the default reference if no source has found
if len(self.person.get_source_references()) == 0:
sref = RelLib.SourceRef()
sref.set_reference_handle(self.def_src.handle)
self.person.add_source_reference(sref)
# commit the person to the database
self.db.commit_person(self.person, self.trans)
del self.person
def parse_individual(self,person): def parse_individual(self,person):
"""
Parse the individual. When we are no longer handling level 1,
then we are finished parsing this level.
"""
state = CurrentState() state = CurrentState()
state.person = person state.person = person
while True: while True:
matches = self.get_next() matches = self.get_next()
if int(matches[0]) < 1: if self.level_is_finished(matches, 1):
self.backup()
if state.get_text(): if state.get_text():
state.person.set_note(state.get_text()) state.person.set_note(state.get_text())
return break
else: else:
func = self.person_func.get(matches[1], self.func_person_event) func = self.person_func.get(matches[1], self.func_person_event)
func(matches, state) func(matches, state)
@ -1211,8 +1260,7 @@ class GedcomParser(UpdateCallback):
while True: while True:
matches = self.get_next() matches = self.get_next()
if int(matches[0]) < level: if self.level_is_finished(matches, level):
self.backup()
return note return note
elif matches[1] == TOKEN_NOTE: elif matches[1] == TOKEN_NOTE:
if not matches[2].strip() or matches[2] and matches[2][0] != "@": if not matches[2].strip() or matches[2] and matches[2][0] != "@":
@ -2021,36 +2069,65 @@ class GedcomParser(UpdateCallback):
# #
#-------------------------------------------------------------------- #--------------------------------------------------------------------
def func_person_name(self,matches,state): def func_person_name(self,matches,state):
name = RelLib.Name() """
m = snameRegexp.match(matches[2]) Parsers the NAME token in a GEDCOM file. The text is in the format
if m: of (according to the GEDCOM Spec):
(n,n2) = m.groups() <TEXT>|/<TEXT>/|<TEXT>/<TEXT>/|/<TEXT>/<TEXT>|<TEXT>/<TEXT>/<TEXT>
names = (n2,'',n,'','') We have encountered some variations that use:
else: <TEXT>/
try: """
names = nameRegexp.match(matches[2]).groups()
except: # build a RelLib.Name structure from the text
names = (matches[2],"","","","")
if names[0]: name = self.parse_name_personal(matches[2])
name.set_first_name(names[0].strip())
if names[2]: # Add the name as the primary name if this is the first one that
name.set_surname(names[2].strip()) # we have encountered for this person. Assume that if this is the
if names[4]: # first name, that it is a birth name. Otherwise, label it as an
name.set_suffix(names[4].strip()) # "Also Known As (AKA)". GEDCOM does not seem to have the concept
# of different name types
if state.name_cnt == 0: if state.name_cnt == 0:
name.set_type(RelLib.set_type(RelLib.NameType.BIRTH)
state.person.set_primary_name(name) state.person.set_primary_name(name)
else: else:
name.set_type(RelLib.set_type(RelLib.NameType.AKA)
state.person.add_alternate_name(name) state.person.add_alternate_name(name)
state.name_cnt += 1 state.name_cnt += 1
self.parse_name(name,2,state)
#
# Create a new state, and parse the remainder of the NAME level
sub_state = CurrentState()
sub_state.person = state.person
sub_state.name = name
sub_state.level = 2
while True:
matches = self.get_next()
if self.level_is_finished(matches,2):
name.set_note(sub_state.get_text())
break
else:
func = self.name_func.get(matches[1],self.func_name_undefined)
func(matches,sub_state)
def func_person_asso(self, matches, state): def func_person_asso(self, matches, state):
gid = matches[2] """
handle = self.find_person_handle(self.map_gid(gid[1:-1])) Parse the ASSO tag, add the the referenced person to the person we
are currently parsing.
"""
# find the id and person that we are referencing
gid = self.extract_gramps_id(matches[2])
handle = self.find_person_handle(self.map_gid(gid))
# create a new PersonRef, and assign the handle, add the
# PersonRef to the active person
ref = RelLib.PersonRef() ref = RelLib.PersonRef()
ref.ref = handle ref.ref = handle
self.person.add_person_ref(ref) state.person.add_person_ref(ref)
while True: while True:
matches = self.get_next() matches = self.get_next()
@ -2069,18 +2146,16 @@ class GedcomParser(UpdateCallback):
self.barf(2) self.barf(2)
def func_person_alt_name(self,matches,state): def func_person_alt_name(self,matches,state):
aka = RelLib.Name() """
try: Parse a altername name, usually indicated by a AKA or _AKA
names = nameRegexp.match(matches[2]).groups() tag. This is not valid GEDCOM, but several programs will add
except: this just to make life interesting. Odd, since GEDCOM supports
names = (matches[2],"","","","") multiple NAME indicators, which is the correct way of handling
if names[0]: multiple names.
aka.set_first_name(names[0]) """
if names[2]: name = self.parse_name_personal(matches[2])
aka.set_surname(names[2]) name.set_type(RelLib.set_type(RelLib.NameType.AKA)
if names[4]: state.person.add_alternate_name(name)
aka.set_suffix(names[4])
state.person.add_alternate_name(aka)
def func_person_object(self,matches,state): def func_person_object(self,matches,state):
if matches[2] and matches[2][0] == '@': if matches[2] and matches[2][0] == '@':
@ -2286,24 +2361,6 @@ class GedcomParser(UpdateCallback):
# #
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
def parse_name(self,name,level,state):
"""Parses the person's name information"""
sub_state = CurrentState()
sub_state.person = state.person
sub_state.name = name
sub_state.level = level
while True:
matches = self.get_next()
if int(matches[0]) < level:
name.set_note(sub_state.get_text())
self.backup()
return
else:
func = self.name_func.get(matches[1],self.func_name_undefined)
func(matches,sub_state)
def func_name_undefined(self,matches,state): def func_name_undefined(self,matches,state):
self.barf(state.level+1) self.barf(state.level+1)

View File

@ -39,6 +39,8 @@ mimetypes.add_type('application/x-gramps-xml','.gramps')
mimetypes.add_type('application/x-gramps-xml','.GRAMPS') mimetypes.add_type('application/x-gramps-xml','.GRAMPS')
mimetypes.add_type('application/x-gedcom','.ged') mimetypes.add_type('application/x-gedcom','.ged')
mimetypes.add_type('application/x-gedcom','.GED') mimetypes.add_type('application/x-gedcom','.GED')
mimetypes.add_type('application/x-gramps-package','.gpkg')
mimetypes.add_type('application/x-gramps-package','.GPKG')
def get_application(mime_type): def get_application(mime_type):
"""Returns the application command and application name of the """Returns the application command and application name of the