From 72024c566dee417c95497d7ecbad576cae7cf4f6 Mon Sep 17 00:00:00 2001 From: Don Allingham Date: Sun, 10 Oct 2004 21:16:44 +0000 Subject: [PATCH] * src/GrampsInMemDB.py: handle null handle * src/GrampsXMLDB.py: disable undo during normal read of database * src/ReadGedcom.py: handle lines shorter than 50 lines, disable undo during normal reads of the database * src/ReadXML.py: disable undo during normal read of databas * src/RelLib.py: revert Name.__cmp__ to Name.is_equal * src/docgen/HTMLDoc.py: drop deprecated gnome.ui dialogs svn: r3617 --- gramps2/ChangeLog | 9 +++++++++ gramps2/src/GrampsGEDDB.py | 9 +++++---- gramps2/src/GrampsInMemDB.py | 5 ++++- gramps2/src/GrampsXMLDB.py | 6 ++++-- gramps2/src/ReadGedcom.py | 22 ++++++++++++++-------- gramps2/src/ReadXML.py | 30 +++++++++++++++--------------- gramps2/src/RelLib.py | 24 ++++++++++++------------ gramps2/src/WriteXML.py | 1 - gramps2/src/docgen/HtmlDoc.py | 5 ++--- gramps2/src/plugins/Check.py | 3 ++- gramps2/src/plugins/WritePkg.py | 1 - 11 files changed, 67 insertions(+), 48 deletions(-) diff --git a/gramps2/ChangeLog b/gramps2/ChangeLog index 120e5745f..65e76a5dc 100644 --- a/gramps2/ChangeLog +++ b/gramps2/ChangeLog @@ -1,3 +1,12 @@ +2004-10-10 Don Allingham + * src/GrampsInMemDB.py: handle null handle + * src/GrampsXMLDB.py: disable undo during normal read of database + * src/ReadGedcom.py: handle lines shorter than 50 lines, disable undo during + normal reads of the database + * src/ReadXML.py: disable undo during normal read of databas + * src/RelLib.py: revert Name.__cmp__ to Name.is_equal + * src/docgen/HTMLDoc.py: drop deprecated gnome.ui dialogs + 2004-10-10 Eero Tamminen * TestPlan.txt: Add test for reports like in stable version diff --git a/gramps2/src/GrampsGEDDB.py b/gramps2/src/GrampsGEDDB.py index 4927cb138..3bff6ce53 100644 --- a/gramps2/src/GrampsGEDDB.py +++ b/gramps2/src/GrampsGEDDB.py @@ -41,14 +41,15 @@ class GrampsGEDDB(GrampsInMemDB): def load(self,name,callback): self.filename = name - ReadGedcom.importData(self,name) - + ReadGedcom.importData(self,name,use_trans=False) + self.bookmarks = self.metadata.get('bookmarks') if self.bookmarks == None: self.bookmarks = [] return 1 def close(self): - writer = WriteGedcom.GedcomWriter(self,self.get_default_person()) - writer.export_data(self.filename) + if len(self.undodb) > 0: + writer = WriteGedcom.GedcomWriter(self,self.get_default_person()) + writer.export_data(self.filename) diff --git a/gramps2/src/GrampsInMemDB.py b/gramps2/src/GrampsInMemDB.py index 44a722141..03cd5f612 100644 --- a/gramps2/src/GrampsInMemDB.py +++ b/gramps2/src/GrampsInMemDB.py @@ -138,7 +138,10 @@ class GrampsInMemDB(GrampsDbBase): def get_person_from_gramps_id(self,val): handle = self.id_trans.get(str(val)) - return self.person_map[handle] + if handle: + return self.person_map[handle] + else: + return None def get_family_from_gramps_id(self,val): handle = self.fid_trans.get(str(val)) diff --git a/gramps2/src/GrampsXMLDB.py b/gramps2/src/GrampsXMLDB.py index 82949362a..9d8a05076 100644 --- a/gramps2/src/GrampsXMLDB.py +++ b/gramps2/src/GrampsXMLDB.py @@ -40,9 +40,10 @@ class GrampsXMLDB(GrampsInMemDB): GrampsInMemDB.__init__(self) def load(self,name,callback): + self.filename = name self.id_trans = {} - ReadXML.importData(self,name) + ReadXML.importData(self,name,use_trans=False) self.bookmarks = self.metadata.get('bookmarks') if self.bookmarks == None: @@ -50,5 +51,6 @@ class GrampsXMLDB(GrampsInMemDB): return 1 def close(self): - WriteXML.quick_write(self,self.filename) + if len(self.undodb) > 0: + WriteXML.quick_write(self,self.filename) diff --git a/gramps2/src/ReadGedcom.py b/gramps2/src/ReadGedcom.py index 3ef7c84d1..01b56cdd4 100644 --- a/gramps2/src/ReadGedcom.py +++ b/gramps2/src/ReadGedcom.py @@ -121,7 +121,7 @@ spanRegexp = re.compile(r"\s*FROM\s+@#D([^@]+)@\s*(.*)\s+TO\s+@#D([^@]+)@\s*(.*) # # #------------------------------------------------------------------------- -def importData(database, filename, cb=None): +def importData(database, filename, cb=None, use_trans=True): global callback @@ -131,6 +131,8 @@ def importData(database, filename, cb=None): gramps = False for index in range(0,50): line = f.readline().split() + if len(line) == 0: + break if line[1] == 'CHAR' and line[2] == "ANSEL": ansel = True if line[1] == 'SOUR' and line[2] == "GRAMPS": @@ -148,10 +150,10 @@ def importData(database, filename, cb=None): dialog.destroy() else: codeset = None - import2(database, filename, cb, codeset) + import2(database, filename, cb, codeset, use_trans) -def import2(database, filename, cb, codeset): +def import2(database, filename, cb, codeset, use_trans): # add some checking here glade_file = "%s/gedcomimport.glade" % os.path.dirname(__file__) @@ -181,7 +183,7 @@ def import2(database, filename, cb, codeset): return try: - close = g.parse_gedcom_file() + close = g.parse_gedcom_file(use_trans) g.resolve_refns() except IOError,msg: Utils.destroy_passed_object(statusWindow) @@ -422,9 +424,12 @@ class GedcomParser: def backup(self): self.backoff = 1 - def parse_gedcom_file(self): - - self.trans = self.db.transaction_begin() + def parse_gedcom_file(self,use_trans=True): + + if use_trans: + self.trans = self.db.transaction_begin() + else: + self.trans = None t = time.time() self.index = 0 self.fam_count = 0 @@ -445,7 +450,8 @@ class GedcomParser: t = time.time() - t msg = _('Import Complete: %d seconds') % t - self.db.transaction_commit(self.trans,_("GEDCOM import")) + if use_trans: + self.db.transaction_commit(self.trans,_("GEDCOM import")) if self.window: self.infomsg("\n%s" % msg) diff --git a/gramps2/src/ReadXML.py b/gramps2/src/ReadXML.py index acb8d31e9..a566822d6 100644 --- a/gramps2/src/ReadXML.py +++ b/gramps2/src/ReadXML.py @@ -67,7 +67,7 @@ _FAMILY_TRANS = { # Must takes care of renaming media files according to their new IDs. # #------------------------------------------------------------------------- -def importData(database, filename, callback=None,cl=0): +def importData(database, filename, callback=None,cl=0,use_trans=True): filename = os.path.normpath(filename) basefile = os.path.dirname(filename) @@ -112,7 +112,7 @@ def importData(database, filename, callback=None,cl=0): ErrorDialog(_("%s could not be opened") % filename) return try: - parser.parse(xml_file) + parser.parse(xml_file,use_trans) except IOError,msg: if cl: print "Error reading %s" % filename @@ -435,7 +435,7 @@ class GrampsParser: person = RelLib.Person() person.set_handle(intid) person.set_gramps_id(gramps_id) - self.db.add_person(person,self.trans) + self.db.add_person(person,None) self.gid2id[gramps_id] = intid return person @@ -448,7 +448,7 @@ class GrampsParser: family = RelLib.Family() family.set_handle(intid) family.set_gramps_id(gramps_id) - self.db.add_family(family,self.trans) + self.db.add_family(family,None) self.gid2fid[gramps_id] = intid return family @@ -461,7 +461,7 @@ class GrampsParser: place = RelLib.Place() place.set_handle(intid) place.set_gramps_id(gramps_id) - self.db.add_place(place,self.trans) + self.db.add_place(place,None) self.gid2pid[gramps_id] = intid return place @@ -474,7 +474,7 @@ class GrampsParser: source = RelLib.Source() source.set_handle(intid) source.set_gramps_id(gramps_id) - self.db.add_source(source,self.trans) + self.db.add_source(source,None) self.gid2sid[gramps_id] = intid return source @@ -487,7 +487,7 @@ class GrampsParser: obj = RelLib.MediaObject() obj.set_handle(intid) obj.set_gramps_id(gramps_id) - self.db.add_object(obj,self.trans) + self.db.add_object(obj,None) self.gid2oid[gramps_id] = intid return obj @@ -531,8 +531,11 @@ class GrampsParser: self.oidswap[handle] = handle return self.oidswap[handle] - def parse(self,file): - self.trans = self.db.transaction_begin() + def parse(self,file,use_trans=True): + if use_trans: + self.trans = self.db.transaction_begin() + else: + self.trans = None p = xml.parsers.expat.ParserCreate() p.StartElementHandler = self.startElement p.EndElementHandler = self.endElement @@ -554,7 +557,8 @@ class GrampsParser: del self.func_map del self.func_list del p - self.db.transaction_commit(self.trans,_("GRAMPS XML import")) + if use_trans: + self.db.transaction_commit(self.trans,_("GRAMPS XML import")) def start_lds_ord(self,attrs): atype = attrs['type'] @@ -702,17 +706,13 @@ class GrampsParser: self.db.bookmarks.append(person.get_handle()) def start_person(self,attrs): - if self.callback != None and self.count % self.increment == 0: - self.callback(float(self.count)/float(self.entries)) - self.count = self.count + 1 - new_id = self.map_gid(attrs['id']) try: self.person = self.db.find_person_from_handle(attrs['handle'],self.trans) self.person.set_gramps_id(new_id) except KeyError: self.person = self.find_person_by_gramps_id(new_id) - + try: self.person.set_complete_flag(int(attrs['complete'])) except KeyError: diff --git a/gramps2/src/RelLib.py b/gramps2/src/RelLib.py index eef222561..60704cc9a 100644 --- a/gramps2/src/RelLib.py +++ b/gramps2/src/RelLib.py @@ -1958,38 +1958,38 @@ class Name(DataObj): else: return "%s %s, %s" % (first, self.surname.upper(), self.suffix) - def __cmp__(self,other): + def is_equal(self,other): """ compares to names to see if they are equal, return 0 if they are not """ if self.first_name != other.first_name: - return 1 + return False if self.surname != other.surname: - return 1 + return False if self.patronymic != other.patronymic: - return 1 + return False if self.prefix != other.prefix: - return 1 + return False if self.suffix != other.suffix: - return 1 + return False if self.title != other.title: - return 1 + return False if self.type != other.type: - return 1 + return False if self.private != other.private: - return 1 + return False if self.get_note() != other.get_note(): - return 1 + return False if len(self.get_source_references()) != len(other.get_source_references()): - return 1 + return False index = 0 olist = other.get_source_references() for a in self.get_source_references(): if not a.are_equal(olist[index]): return True index += 1 - return 0 + return True class Url: """Contains information related to internet Uniform Resource Locators, diff --git a/gramps2/src/WriteXML.py b/gramps2/src/WriteXML.py index 3ea5552f0..b35e60f1e 100644 --- a/gramps2/src/WriteXML.py +++ b/gramps2/src/WriteXML.py @@ -137,7 +137,6 @@ class XmlWriter: """ Write the database to the specified file. """ - base = os.path.dirname(filename) if os.path.isdir(base): if not os.access(base,os.W_OK) or not os.access(base,os.R_OK): diff --git a/gramps2/src/docgen/HtmlDoc.py b/gramps2/src/docgen/HtmlDoc.py index ab80cb2df..0ac6b966b 100644 --- a/gramps2/src/docgen/HtmlDoc.py +++ b/gramps2/src/docgen/HtmlDoc.py @@ -25,7 +25,6 @@ import string import re import time -import gnome.ui import Plugins import ImgManip import TarFile @@ -157,7 +156,7 @@ class HtmlDoc(BaseDoc.BaseDoc): if top_add == 1: mymsg = _("The marker '' was not in the template") - gnome.ui.GnomeErrorDialog(mymsg) + QuestionDialog.ErrorDialog(_("Template Error"),mymsg) def load_html(self): start = re.compile(r"") @@ -182,7 +181,7 @@ class HtmlDoc(BaseDoc.BaseDoc): if top_add == 1: mymsg = _("The marker '' was not in the template") - gnome.ui.GnomeErrorDialog(mymsg) + QuestionDilaog.ErrorDialog(_("Template Error"),mymsg) def load_template(self): if self.template: diff --git a/gramps2/src/plugins/Check.py b/gramps2/src/plugins/Check.py index c52dfa32c..d53b1145e 100644 --- a/gramps2/src/plugins/Check.py +++ b/gramps2/src/plugins/Check.py @@ -29,7 +29,6 @@ #------------------------------------------------------------------------- import os import cStringIO -import shutil from gettext import gettext as _ #------------------------------------------------------------------------- @@ -186,6 +185,8 @@ class CheckIntegrity: self.bad_photo.append(ObjectId) def fs_ok_clicked(obj): + import shutil + name = fs_top.get_filename() if os.path.isfile(name): shutil.copyfile(name,photo_name) diff --git a/gramps2/src/plugins/WritePkg.py b/gramps2/src/plugins/WritePkg.py index 613159091..935c65d68 100644 --- a/gramps2/src/plugins/WritePkg.py +++ b/gramps2/src/plugins/WritePkg.py @@ -38,7 +38,6 @@ from cStringIO import StringIO #------------------------------------------------------------------------- import gtk import gtk.glade -import gnome #------------------------------------------------------------------------- #