diff --git a/ChangeLog b/ChangeLog index 720e6cb54..1baf02c78 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,4 +1,12 @@ 2006-02-28 Alex Roitman + * src/plugins/WritePkg.py (PackageWriter.export): Add existing + image filenames to the archive. + * src/GrampsDb/_WriteXML.py: Improve callback use, add another + strip_photo option. + * src/ViewManager.py: Typos. + * src/Exporter.py: Start for callback support. + * src/GrampsDb/_WriteGedcom.py: Callback support. + * src/ViewManager.py (ViewManager.import_data): Properly process non-native (plugin) imports; (_do_import): factor common code into the new method. diff --git a/src/Exporter.py b/src/Exporter.py index a3fea9082..1e60fca1a 100644 --- a/src/Exporter.py +++ b/src/Exporter.py @@ -67,7 +67,7 @@ class Exporter: name. """ - def __init__(self,dbstate,uistate): + def __init__(self,dbstate,uistate,callback=None): """ Set up the window, the druid, and build all the druid's pages. Some page elements are left empty, since their contents depends @@ -75,6 +75,7 @@ class Exporter: """ self.dbstate = dbstate self.uistate = uistate + self.callback = callback if self.dbstate.active: self.person = self.dbstate.active else: @@ -165,10 +166,12 @@ class Exporter: if self.exports[ix][3]: success = self.exports[ix][0](self.dbstate.db, filename,self.person, - self.option_box_instance) + self.option_box_instance, + self.callback) else: success = self.exports[ix][0](self.dbstate.db, - filename,self.person) + filename,self.person, + self.callback) return success def build_conclusion(self,success): diff --git a/src/GrampsDb/_WriteGedcom.py b/src/GrampsDb/_WriteGedcom.py index 19b24e4a2..78afffe6d 100644 --- a/src/GrampsDb/_WriteGedcom.py +++ b/src/GrampsDb/_WriteGedcom.py @@ -1318,7 +1318,7 @@ class GedcomWriter: # # #------------------------------------------------------------------------- -def exportData(database,filename,person,option_box): +def exportData(database,filename,person,option_box,callback=None): ret = 0 try: gw = GedcomWriter(database,person,0,filename,option_box) diff --git a/src/GrampsDb/_WriteXML.py b/src/GrampsDb/_WriteXML.py index 277958d62..8bc8c41c9 100644 --- a/src/GrampsDb/_WriteXML.py +++ b/src/GrampsDb/_WriteXML.py @@ -131,12 +131,19 @@ class XmlWriter: db - database to write callback - function to provide progress indication - strip_photos - remove full paths off of media object paths + strip_photos - remove paths off of media object paths + 0: do not touch the paths + 1: remove everything expect the filename + 2: remove leading slash compress - attempt to compress the database """ self.compress = compress self.db = db self.callback = callback + if '__call__' in dir(self.callback): # callback is really callable + self.update = self.update_real + else: + self.update = self.update_empty self.strip_photos = strip_photos def write(self,filename): @@ -212,8 +219,10 @@ class XmlWriter: repo_len = len(self.db.get_repository_handles()) obj_len = len(self.db.get_media_object_handles()) - total = person_len + family_len + event_len + place_len + \ - source_len + obj_len + repo_len + self.total = person_len + family_len + event_len + place_len + \ + source_len + obj_len + repo_len + self.count = 0 + self.oldval = 0 self.g.write('\n') self.g.write('\n") self.g.write(" \n") - count = 0 - delta = max(int(total/50),1) - if event_len > 0: self.g.write(" \n") sorted_keys = self.db.get_gramps_ids(EVENT_KEY) @@ -249,9 +255,7 @@ class XmlWriter: for gramps_id in sorted_keys: event = self.db.get_event_from_gramps_id(gramps_id) self.write_event(event,2) - if self.callback and count % delta == 0: - self.callback(float(count)/float(total)) - count = count + 1 + self.update() self.g.write(" \n") if person_len > 0: @@ -268,9 +272,7 @@ class XmlWriter: for gramps_id in sorted_keys: person = self.db.get_person_from_gramps_id(gramps_id) self.write_person(person,2) - if self.callback and count % delta == 0: - self.callback(float(count)/float(total)) - count += 1 + self.update() self.g.write(" \n") if family_len > 0: @@ -280,9 +282,7 @@ class XmlWriter: for gramps_id in sorted_keys: family = self.db.get_family_from_gramps_id(gramps_id) self.write_family(family,2) - if self.callback and count % delta == 0: - self.callback(float(count)/float(total)) - count = count + 1 + self.update() self.g.write(" \n") if source_len > 0: @@ -292,9 +292,6 @@ class XmlWriter: for key in keys: source = self.db.get_source_from_gramps_id(key) self.write_source(source,2) - if self.callback and count % delta == 0: - self.callback(float(count)/float(total)) - count = count + 1 self.g.write(" \n") if place_len > 0: @@ -305,11 +302,7 @@ class XmlWriter: # try: place = self.db.get_place_from_gramps_id(key) self.write_place_obj(place,2) - if self.callback and count % delta == 0: - self.callback(float(count)/float(total)) - # except: - # print "Could not find place %s" % key - count = count + 1 + self.update() self.g.write(" \n") if obj_len > 0: @@ -319,9 +312,7 @@ class XmlWriter: for gramps_id in sorted_keys: obj = self.db.get_object_from_gramps_id(gramps_id) self.write_object(obj,2) - if self.callback and count % delta == 0: - self.callback(float(count)/float(total)) - count += 1 + self.update() self.g.write(" \n") if repo_len > 0: @@ -331,9 +322,7 @@ class XmlWriter: for key in keys: repo = self.db.get_repository_from_gramps_id(key) self.write_repository(repo,2) - if self.callback and count % delta == 0: - self.callback(float(count)/float(total)) - count += 1 + self.update() self.g.write(" \n") if len(self.db.get_bookmarks()) > 0: @@ -351,6 +340,16 @@ class XmlWriter: self.g.write("\n") + def update_empty(self): + pass + + def update_real(self): + self.count += 1 + newval = int(100*self.count/self.total) + if newval != self.oldval: + self.callback(newval) + self.oldval = newval + def fix(self,line): l = line.strip() l = l.replace('&','&') @@ -950,8 +949,11 @@ class XmlWriter: desc_text = ' description="%s"' % self.fix(desc) else: desc_text = '' - if self.strip_photos: + if self.strip_photos == 1: path = os.path.basename(path) + elif self.strip_photos == 2 and path[0] == '/': + path = path[1:] + self.g.write('%s\n' % (" "*(index+1),path,mime_type,desc_text)) self.write_attribute_list(obj.get_attribute_list()) diff --git a/src/ViewManager.py b/src/ViewManager.py index e0ef0491f..6c0d9daa6 100644 --- a/src/ViewManager.py +++ b/src/ViewManager.py @@ -870,7 +870,7 @@ class ViewManager: def export_data(self,obj): import Exporter - Exporter.Exporter(self.state,self.uistate) + Exporter.Exporter(self.state,self.uistate,self.pulse_progressbar) def import_data(self,obj): choose = gtk.FileChooserDialog(_('GRAMPS: Import database'), @@ -930,9 +930,12 @@ class ViewManager: return False # First we try our best formats - if filetype in format_list: + if filetype in (const.app_gramps, + const.app_gramps_xml, + const.app_gedcom): self._do_import(choose, - GrampsDb.gramps_db_reader_factory(filetype)) + GrampsDb.gramps_db_reader_factory(filetype), + filename) return True # Then we try all the known plugins @@ -941,7 +944,7 @@ class ViewManager: for (importData,mime_filter,mime_type, native_format,format_name) in PluginMgr.import_list: if filetype == mime_type or the_file == mime_type: - self._do_import(choose,importData) + self._do_import(choose,importData,filename) return True # Finally, we give up and declare this an unknown format @@ -954,12 +957,11 @@ class ViewManager: choose.destroy() return False - def _do_import(self,dialog,importer): + def _do_import(self,dialog,importer,filename): dialog.destroy() self.window.window.set_cursor(gtk.gdk.Cursor(gtk.gdk.WATCH)) self.progress.show() - GrampsDb.gramps_db_reader_factory(filetype)( - self.state.db,filename,self.pulse_progressbar) + importer(self.state.db,filename,self.pulse_progressbar) self.uistate.clear_history() self.progress.hide() self.window.window.set_cursor(None) diff --git a/src/plugins/WritePkg.py b/src/plugins/WritePkg.py index 9c4363395..ce46fbd41 100644 --- a/src/plugins/WritePkg.py +++ b/src/plugins/WritePkg.py @@ -140,9 +140,7 @@ class PackageWriter: def fs_ok_clicked(obj): name = fs_top.get_filename() if os.path.isfile(name): - ti = tf.gettarinfo(name,base) - ti.mtime = time.time() - tf.addfile(ti) + archive.add(name) fs_top = gtk.FileSelection("%s - GRAMPS" % _("Select file")) fs_top.hide_fileop_buttons() @@ -158,21 +156,21 @@ class PackageWriter: # during the process (i.e. when removing object) for m_id in self.db.get_media_object_handles(): mobject = self.db.get_object_from_handle(m_id) - oldfile = mobject.get_path() - base = os.path.basename(oldfile) - if os.path.isfile(oldfile): - tarinfo = archive.gettarinfo(oldfile,base) - tarinfo.mtime = int(time.time()) - archive.addfile(tarinfo,file(oldfile)) + filename = mobject.get_path() + if os.path.isfile(filename): + archive.add(filename) else: # File is lost => ask what to do if missmedia_action == 0: - mmd = MissingMediaDialog(_("Media object could not be found"), - _("%(file_name)s is referenced in the database, but no longer exists. " - "The file may have been deleted or moved to a different location. " - "You may choose to either remove the reference from the database, " - "keep the reference to the missing file, or select a new file." - ) % { 'file_name' : oldfile }, + mmd = MissingMediaDialog( + _("Media object could not be found"), + _("%(file_name)s is referenced in the database, " + "but no longer exists. The file may have been " + "deleted or moved to a different location. " + "You may choose to either remove the reference " + "from the database, keep the reference to the " + "missing file, or select a new file." + ) % { 'file_name' : filename }, remove_clicked, leave_clicked, select_clicked) missmedia_action = mmd.default_action elif missmedia_action == 1: @@ -183,13 +181,9 @@ class PackageWriter: select_clicked() # Write XML now - # import tempfile - # tempdir = tempfile.mkdtemp('.tmp','gramps-', - # os.path.dirname(self.filename)) - # new_xml_file = os.path.join(tempdir,'data.gramps') g = StringIO() - gfile = XmlWriter(self.db,None,1) - gfile.write_handle(g) #write(new_xml_file) #write_handle(g) + gfile = XmlWriter(self.db,None,2) + gfile.write_handle(g) tarinfo = tarfile.TarInfo('data.gramps') tarinfo.size = len(g.getvalue()) tarinfo.mtime = time.time()