From 44884e924474f08d1d3e50fb0a7708822aa88aed Mon Sep 17 00:00:00 2001 From: Alex Roitman Date: Fri, 21 Apr 2006 00:03:27 +0000 Subject: [PATCH] * src/GrampsDb/_GrampsBSDDB.py: Upgrade to new types. * src/GrampsDb/_ReadGedcom.py: Adapt to new types. * src/RelLib/_Event.py: Properly set type. * src/RelLib/_EventRef.py: Properly set type. * src/RelLib/_Family.py: Properly set type. * src/RelLib/_Name.py: Properly set type. * src/RelLib/_Person.py: Properly set type. * src/RelLib/_PrimaryObject.py: Properly set type. * src/RelLib/_RepoRef.py: Properly set type. * src/RelLib/_Repository.py: Properly set type. * src/RelLib/_Url.py: Properly set type. svn: r6386 --- ChangeLog | 13 ++++++ src/GrampsDb/_GrampsBSDDB.py | 88 ++++++++---------------------------- src/GrampsDb/_ReadGedcom.py | 16 +++---- src/RelLib/_Event.py | 5 +- src/RelLib/_EventRef.py | 5 +- src/RelLib/_Family.py | 7 +-- src/RelLib/_Name.py | 5 +- src/RelLib/_Person.py | 1 - src/RelLib/_PrimaryObject.py | 5 +- src/RelLib/_RepoRef.py | 5 +- src/RelLib/_Repository.py | 5 +- src/RelLib/_Url.py | 7 +-- 12 files changed, 46 insertions(+), 116 deletions(-) diff --git a/ChangeLog b/ChangeLog index b43490558..8fa44995a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,16 @@ +2006-04-20 Alex Roitman + * src/GrampsDb/_GrampsBSDDB.py: Upgrade to new types. + * src/GrampsDb/_ReadGedcom.py: Adapt to new types. + * src/RelLib/_Event.py: Properly set type. + * src/RelLib/_EventRef.py: Properly set type. + * src/RelLib/_Family.py: Properly set type. + * src/RelLib/_Name.py: Properly set type. + * src/RelLib/_Person.py: Properly set type. + * src/RelLib/_PrimaryObject.py: Properly set type. + * src/RelLib/_RepoRef.py: Properly set type. + * src/RelLib/_Repository.py: Properly set type. + * src/RelLib/_Url.py: Properly set type. + 2006-04-20 Brian Matherly * src/docgen/ODFDoc.py: Fix space at begining of paragraph diff --git a/src/GrampsDb/_GrampsBSDDB.py b/src/GrampsDb/_GrampsBSDDB.py index 0c92ce30d..6111d9eaf 100644 --- a/src/GrampsDb/_GrampsBSDDB.py +++ b/src/GrampsDb/_GrampsBSDDB.py @@ -1317,7 +1317,7 @@ class GrampsBSDDB(GrampsDbBase): family.handle = handle # Restore data from dbversion 8 (gramps 2.0.9) (junk_handle, family.gramps_id, family.father_handle, - family.mother_handle, child_list, family.type, + family.mother_handle, child_list, the_type, event_list, family.media_list, family.attribute_list, lds_seal, complete, family.source_list, family.note, family.change) = info @@ -1339,7 +1339,7 @@ class GrampsBSDDB(GrampsDbBase): family.child_ref_list.append(child_ref) # Change relationship type from int to tuple - family.type = (family.type,'') + family.type.set(the_type) # In all Attributes, convert type from string to a tuple for attribute in family.attribute_list: @@ -1369,7 +1369,7 @@ class GrampsBSDDB(GrampsDbBase): death_handle, birth_handle, event_list, person.family_list, parent_family_list, person.media_list, person.address_list, person.attribute_list, - person.urls, lds_bapt, lds_endow, lds_seal, + urls, lds_bapt, lds_endow, lds_seal, complete, person.source_list, person.note, person.change, person.private) = (info + (False,))[0:23] @@ -1435,8 +1435,7 @@ class GrampsBSDDB(GrampsDbBase): convert_mediaref_9(media_ref) # In all Urls, add type attribute - for url in person.urls: - convert_url_9(url) + person.urls = [convert_url_9(url) for url in urls] # Switch from fixed lds ords to a list person.lds_ord_list = [item for item @@ -1447,55 +1446,6 @@ class GrampsBSDDB(GrampsDbBase): self.update(100*current/length) # Event upgrade - event_conversion = { - "Alternate Marriage" : (EventType.MARR_ALT,""), - "Annulment" : (EventType.ANNULMENT,""), - "Divorce" : (EventType.DIVORCE,""), - "Engagement" : (EventType.ENGAGEMENT,""), - "Marriage Banns" : (EventType.MARR_BANNS,""), - "Marriage Contract" : (EventType.MARR_CONTR,""), - "Marriage License" : (EventType.MARR_LIC,""), - "Marriage Settlement" : (EventType.MARR_SETTL,""), - "Marriage" : (EventType.MARRIAGE,""), - "Adopted" : (EventType.ADOPT,""), - "Birth" : (EventType.BIRTH,""), - "Alternate Birth" : (EventType.BIRTH,""), - "Death" : (EventType.DEATH,""), - "Alternate Death" : (EventType.DEATH,""), - "Adult Christening" : (EventType.ADULT_CHRISTEN,""), - "Baptism" : (EventType.BAPTISM,""), - "Bar Mitzvah" : (EventType.BAR_MITZVAH,""), - "Bas Mitzvah" : (EventType.BAS_MITZVAH,""), - "Blessing" : (EventType.BLESS,""), - "Burial" : (EventType.BURIAL,""), - "Cause Of Death" : (EventType.CAUSE_DEATH,""), - "Census" : (EventType.CENSUS,""), - "Christening" : (EventType.CHRISTEN,""), - "Confirmation" : (EventType.CONFIRMATION,""), - "Cremation" : (EventType.CREMATION,""), - "Degree" : (EventType.DEGREE,""), - "Divorce Filing" : (EventType.DIV_FILING,""), - "Education" : (EventType.EDUCATION,""), - "Elected" : (EventType.ELECTED,""), - "Emigration" : (EventType.EMIGRATION,""), - "First Communion" : (EventType.FIRST_COMMUN,""), - "Immigration" : (EventType.IMMIGRATION,""), - "Graduation" : (EventType.GRADUATION,""), - "Medical Information" : (EventType.MED_INFO,""), - "Military Service" : (EventType.MILITARY_SERV,""), - "Naturalization" : (EventType.NATURALIZATION,""), - "Nobility Title" : (EventType.NOB_TITLE,""), - "Number of Marriages" : (EventType.NUM_MARRIAGES,""), - "Occupation" : (EventType.OCCUPATION,""), - "Ordination" : (EventType.ORDINATION,""), - "Probate" : (EventType.PROBATE,""), - "Property" : (EventType.PROPERTY,""), - "Religion" : (EventType.RELIGION,""), - "Residence" : (EventType.RESIDENCE,""), - "Retirement" : (EventType.RETIREMENT,""), - "Will" : (EventType.WILL,""), - } - # Turns out that a lof ot events have duplicate gramps IDs # We need to fix this table_flags = self.open_flags() @@ -1519,14 +1469,7 @@ class GrampsBSDDB(GrampsDbBase): if event.gramps_id in dup_ids: event.gramps_id = self.find_next_event_gramps_id() - if old_type: - if event_conversion.has_key(old_type): - new_type = event_conversion[old_type] - else: - new_type = (EventType.CUSTOM,old_type) - else: - new_type = (EventType.UNKNOWN,"") - event.type = new_type + event.type.set_from_xml_str(old_type) # Cover attributes contained in MediaRefs for media_ref in event.media_list: @@ -1568,7 +1511,7 @@ class GrampsBSDDB(GrampsDbBase): place = Place() place.handle = handle (junk_handle, place.gramps_id, place.title, place.long, place.lat, - place.main_loc, place.alt_loc, place.urls, place.media_list, + place.main_loc, place.alt_loc, urls, place.media_list, place.source_list, place.note, place.change) = info # Cover attributes contained in MediaRefs @@ -1576,8 +1519,7 @@ class GrampsBSDDB(GrampsDbBase): convert_mediaref_9(media_ref) # In all Urls, add type attribute - for url in place.urls: - convert_url_9(url) + place.urls = [convert_url_9(url) for url in urls] self.commit_place(place,trans) current += 1 @@ -1640,14 +1582,20 @@ def convert_mediaref_9(media_ref): def convert_url_9(url): path = url.path.strip() - if path.find('mailto:') == 0 or url.path.find('@') != -1: - url.type = (Url.EMAIL,'') + if (path.find('mailto:') == 0) or (url.path.find('@') != -1): + new_type = UrlType.EMAIL elif path.find('http://') == 0: - url.type = (Url.WEB_HOME,'') + new_type = UrlType.WEB_HOME elif path.find('ftp://') == 0: - url.type = (Url.WEB_FTP,'') + new_type = UrlType.WEB_FTP else: - url.type = (Url.CUSTOM,'') + new_type = UrlType.CUSTOM + new_url = Url() + new_url.type.set(new_type) + new_url.path = url.path + new_url.desc = url.desc + new_url.private = url.private + return new_url def low_level_9(the_db): """ diff --git a/src/GrampsDb/_ReadGedcom.py b/src/GrampsDb/_ReadGedcom.py index 79a7c25c7..e92bf69db 100644 --- a/src/GrampsDb/_ReadGedcom.py +++ b/src/GrampsDb/_ReadGedcom.py @@ -69,7 +69,6 @@ from DateHandler import DateParser import NameDisplay import Utils import Mime -import _ConstXML from ansel_utf8 import ansel_to_utf8 from bsddb import db @@ -1031,9 +1030,7 @@ class GedcomParser: self.backup() return elif matches[1] == TOKEN_MEDI: - media_type = _ConstXML.tuple_from_xml( - _ConstXML.source_media_types,matches[2]) - reporef.set_media_type(media_type) + reporef.media_type.set(matches[2]) else: self.barf(1) @@ -1154,11 +1151,11 @@ class GedcomParser: event.set_description(matches[2]) self.parse_family_event(event,2) if int(event.get_type()) == RelLib.EventType.MARRIAGE: - self.family.set_relationship((RelLib.Family.MARRIED,'')) + self.family.type.set(RelLib.FamilyRelType.MARRIED) if int(event.get_type()) != RelLib.EventType.CUSTOM: if not event.get_description(): text = _event_family_str % { - 'event_name' : Utils.family_events[event.get_type()[0]], + 'event_name' : str(event.get_type()), 'family' : Utils.family_name(self.family,self.db), } event.set_description(text) @@ -2197,7 +2194,7 @@ class GedcomParser: event.set_gramps_id(self.emapper.find_next()) if matches[2]: event.set_description(matches[2]) - event.set_type(RelLib.EventTypeType.DEATH) + event.type.set(RelLib.EventType.DEATH) self.parse_person_event(event,2) person_event_name(event,state.person) @@ -2217,8 +2214,9 @@ class GedcomParser: if matches[2]: event.set_description(matches[2]) self.parse_person_event(event,2) - (t,n) = event.get_type() - if t == RelLib.EventType.CUSTOM and n in self.attrs: + the_type = event.get_type() + if int(the_type) == RelLib.EventType.CUSTOM \ + and str(the_type) in self.attrs: attr = RelLib.Attribute() attr.set_type((RelLib.EventType.CUSTOM,self.gedattr[n])) attr.set_value(event.get_description()) diff --git a/src/RelLib/_Event.py b/src/RelLib/_Event.py index 6c9326f6e..de3b4f6cd 100644 --- a/src/RelLib/_Event.py +++ b/src/RelLib/_Event.py @@ -245,10 +245,7 @@ class Event(PrimaryObject,SourceBase,NoteBase,MediaBase,DateBase,PlaceBase): @param the_type: Type to assign to the Event @type the_type: tuple """ - if type(the_type) == tuple: - self.type = EventType(the_type) - else: - self.type = the_type + self.type.set(the_type) def get_type(self): """ diff --git a/src/RelLib/_EventRef.py b/src/RelLib/_EventRef.py index 6af6adb63..86b806209 100644 --- a/src/RelLib/_EventRef.py +++ b/src/RelLib/_EventRef.py @@ -127,7 +127,4 @@ class EventRef(BaseObject,PrivacyBase,NoteBase,RefBase): """ Sets the role according to the given argument. """ - if type(role) == tuple: - self.role = EventRoleType(role) - else: - self.role = role + self.role.set(role) diff --git a/src/RelLib/_Family.py b/src/RelLib/_Family.py index 0fd4a20bd..eb9514d88 100644 --- a/src/RelLib/_Family.py +++ b/src/RelLib/_Family.py @@ -45,7 +45,6 @@ from _EventRef import EventRef from _LdsOrdBase import LdsOrdBase from _ChildRef import ChildRef from _FamilyRelType import FamilyRelType -from _MarkerType import MarkerType #------------------------------------------------------------------------- # @@ -298,11 +297,7 @@ class Family(PrimaryObject,SourceBase,NoteBase,MediaBase,AttributeBase, between the father and mother of the relationship. @type relationship_type: tuple """ - if type(relationship_type) == tuple: - self.type = FamilyRelType(relationship_type) - else: - self.type = relationship_type - return + self.type.set(relationship_type) def get_relationship(self): """ diff --git a/src/RelLib/_Name.py b/src/RelLib/_Name.py index edba844c5..9de30eb3e 100644 --- a/src/RelLib/_Name.py +++ b/src/RelLib/_Name.py @@ -234,10 +234,7 @@ class Name(BaseObject,PrivacyBase,SourceBase,NoteBase,DateBase): def set_type(self,the_type): """sets the type of the Name instance""" - if type(the_type) == tuple: - self.type = NameType(the_type) - else: - self.type = the_type + self.type(the_type) def get_type(self): """returns the type of the Name instance""" diff --git a/src/RelLib/_Person.py b/src/RelLib/_Person.py index 16d0ea550..e2d6969e6 100644 --- a/src/RelLib/_Person.py +++ b/src/RelLib/_Person.py @@ -45,7 +45,6 @@ from _AddressBase import AddressBase from _LdsOrdBase import LdsOrdBase from _UrlBase import UrlBase from _Name import Name -from _NameType import NameType from _EventRef import EventRef from _LdsOrd import LdsOrd from _PersonRef import PersonRef diff --git a/src/RelLib/_PrimaryObject.py b/src/RelLib/_PrimaryObject.py index ed2966cd7..cd2e9892e 100644 --- a/src/RelLib/_PrimaryObject.py +++ b/src/RelLib/_PrimaryObject.py @@ -210,10 +210,7 @@ class PrimaryObject(BaseObject,PrivacyBase): pass def set_marker(self,marker): - if type(marker) == tuple: - self.marker = MarkerType(marker) - else: - self.marker = marker + self.marker.set(marker) def get_marker(self): return self.marker diff --git a/src/RelLib/_RepoRef.py b/src/RelLib/_RepoRef.py index 4125a3098..9aeed657a 100644 --- a/src/RelLib/_RepoRef.py +++ b/src/RelLib/_RepoRef.py @@ -111,7 +111,4 @@ class RepoRef(BaseObject,NoteBase,RefBase): return self.media_type def set_media_type(self,media_type): - if type(media_type) == tuple: - self.media_type = SourceMediaType(media_type) - else: - self.media_type = media_type + self.media_type.set(media_type) diff --git a/src/RelLib/_Repository.py b/src/RelLib/_Repository.py index 7a33d4786..9be96809e 100644 --- a/src/RelLib/_Repository.py +++ b/src/RelLib/_Repository.py @@ -140,10 +140,7 @@ class Repository(PrimaryObject,NoteBase,AddressBase,UrlBase): @param type: descriptive type of the Repository @type type: str """ - if type(the_type) == tuple: - self.type = RepositoryType(the_type) - else: - self.type = the_type + self.type.set(the_type) def get_type(self): """ diff --git a/src/RelLib/_Url.py b/src/RelLib/_Url.py index 4cb281f31..ad767914c 100644 --- a/src/RelLib/_Url.py +++ b/src/RelLib/_Url.py @@ -100,12 +100,7 @@ class Url(BaseObject,PrivacyBase): @param type: descriptive type of the Url @type type: str """ - if type(the_type) == tuple: - self.type = UrlType(the_type) - else: - print the_type - assert(isinstance(the_type,UrlType)) - self.type = the_type + self.type.set(the_type) def get_type(self): """