def export(self): # missmedia_action = 0 #-------------------------------------------------------------- # def remove_clicked(): # # File is lost => remove all references and the object itself # for p_id in self.db.iter_family_handles(): # p = self.db.get_family_from_handle(p_id) # nl = p.get_media_list() # for o in nl: # if o.get_reference_handle() == m_id: # nl.remove(o) # p.set_media_list(nl) # self.db.commit_family(p,None) # for key in self.db.iter_person_handles(): # p = self.db.get_person_from_handle(key) # nl = p.get_media_list() # for o in nl: # if o.get_reference_handle() == m_id: # nl.remove(o) # p.set_media_list(nl) # self.db.commit_person(p,None) # for key in self.db.get_source_handles(): # p = self.db.get_source_from_handle(key) # nl = p.get_media_list() # for o in nl: # if o.get_reference_handle() == m_id: # nl.remove(o) # p.set_media_list(nl) # self.db.commit_source(p,None) # for key in self.db.get_place_handles(): # p = self.db.get_place_from_handle(key) # nl = p.get_media_list() # for o in nl: # if o.get_reference_handle() == m_id: # nl.remove(o) # p.set_media_list(nl) # self.db.commit_place(p,None) # for key in self.db.get_event_handles(): # p = self.db.get_event_from_handle(key) # nl = p.get_media_list() # for o in nl: # if o.get_reference_handle() == m_id: # nl.remove(o) # p.set_media_list(nl) # self.db.commit_event(p,None) # self.db.remove_object(m_id,None) # def leave_clicked(): # # File is lost => do nothing, leave as is # pass # def select_clicked(): # # File is lost => select a file to replace the lost one # def fs_close_window(obj): # pass # def fs_ok_clicked(obj): # name = conv_to_unicode(fs_top.get_filename()) # if os.path.isfile(name): # archive.add(name) # fs_top = gtk.FileChooserDialog("%s - GRAMPS" % _("Select file"), # buttons=(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, # gtk.STOCK_OK, Gtk.ResponseType.OK) # ) # response = fs_top.run() # if response == Gtk.ResponseType.OK: # fs_ok_clicked(fs_top) # elif response == gtk.RESPONSE_CANCEL: # fs_close_window(fs_top) # fs_top.destroy() #--------------------------------------------------------------- try: archive = tarfile.open(self.filename, 'w:gz') except EnvironmentError as msg: log.warn(str(msg)) self.user.notify_error( _('Failure writing %s') % self.filename, str(msg)) return 0 # Write media files first, since the database may be modified # during the process (i.e. when removing object) for m_id in self.db.get_media_object_handles(sort_handles=True): mobject = self.db.get_object_from_handle(m_id) filename = media_path_full(self.db, mobject.get_path()) archname = str(mobject.get_path()) if os.path.isfile(filename) and os.access(filename, os.R_OK): archive.add(filename, archname) # 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' : filename }, # remove_clicked, leave_clicked, select_clicked) # missmedia_action = mmd.default_action # elif missmedia_action == 1: # remove_clicked() # elif missmedia_action == 2: # leave_clicked() # elif missmedia_action == 3: # select_clicked() # Write XML now g = BytesIO() gfile = XmlWriter(self.db, self.user, 2) gfile.write_handle(g) tarinfo = tarfile.TarInfo('data.gramps') tarinfo.size = len(g.getvalue()) tarinfo.mtime = time.time() if not win(): tarinfo.uid = os.getuid() tarinfo.gid = os.getgid() g.seek(0) archive.addfile(tarinfo, g) archive.close() g.close() return True
def export(self): # missmedia_action = 0 #-------------------------------------------------------------- # def remove_clicked(): # # File is lost => remove all references and the object itself # for p_id in self.db.iter_family_handles(): # p = self.db.get_family_from_handle(p_id) # nl = p.get_media_list() # for o in nl: # if o.get_reference_handle() == m_id: # nl.remove(o) # p.set_media_list(nl) # self.db.commit_family(p,None) # for key in self.db.iter_person_handles(): # p = self.db.get_person_from_handle(key) # nl = p.get_media_list() # for o in nl: # if o.get_reference_handle() == m_id: # nl.remove(o) # p.set_media_list(nl) # self.db.commit_person(p,None) # for key in self.db.get_source_handles(): # p = self.db.get_source_from_handle(key) # nl = p.get_media_list() # for o in nl: # if o.get_reference_handle() == m_id: # nl.remove(o) # p.set_media_list(nl) # self.db.commit_source(p,None) # for key in self.db.get_place_handles(): # p = self.db.get_place_from_handle(key) # nl = p.get_media_list() # for o in nl: # if o.get_reference_handle() == m_id: # nl.remove(o) # p.set_media_list(nl) # self.db.commit_place(p,None) # for key in self.db.get_event_handles(): # p = self.db.get_event_from_handle(key) # nl = p.get_media_list() # for o in nl: # if o.get_reference_handle() == m_id: # nl.remove(o) # p.set_media_list(nl) # self.db.commit_event(p,None) # self.db.remove_media(m_id,None) # def leave_clicked(): # # File is lost => do nothing, leave as is # pass # def select_clicked(): # # File is lost => select a file to replace the lost one # def fs_close_window(obj): # pass # def fs_ok_clicked(obj): # name = fs_top.get_filename() # if os.path.isfile(name): # archive.add(name) # fs_top = gtk.FileChooserDialog("%s - GRAMPS" % _("Select file"), # buttons=(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, # gtk.STOCK_OK, Gtk.ResponseType.OK) # ) # response = fs_top.run() # if response == Gtk.ResponseType.OK: # fs_ok_clicked(fs_top) # elif response == gtk.RESPONSE_CANCEL: # fs_close_window(fs_top) # fs_top.destroy() #--------------------------------------------------------------- try: archive = tarfile.open(self.filename, 'w:gz') except EnvironmentError as msg: log.warning(str(msg)) self.user.notify_error( _('Failure writing %s') % self.filename, str(msg)) return 0 # Write media files first, since the database may be modified # during the process (i.e. when removing object) for m_id in self.db.get_media_handles(sort_handles=True): mobject = self.db.get_media_from_handle(m_id) filename = media_path_full(self.db, mobject.get_path()) archname = str(mobject.get_path()) if os.path.isfile(filename) and os.access(filename, os.R_OK): archive.add(filename, archname) # Write XML now g = BytesIO() gfile = XmlWriter(self.db, self.user, 2) gfile.write_handle(g) tarinfo = tarfile.TarInfo('data.gramps') tarinfo.size = len(g.getvalue()) tarinfo.mtime = time.time() if not win(): tarinfo.uid = os.getuid() tarinfo.gid = os.getgid() g.seek(0) archive.addfile(tarinfo, g) archive.close() g.close() return True
def export(self): # missmedia_action = 0 #-------------------------------------------------------------- # def remove_clicked(): # # File is lost => remove all references and the object itself # for p_id in self.db.iter_family_handles(): # p = self.db.get_family_from_handle(p_id) # nl = p.get_media_list() # for o in nl: # if o.get_reference_handle() == m_id: # nl.remove(o) # p.set_media_list(nl) # self.db.commit_family(p,None) # for key in self.db.iter_person_handles(): # p = self.db.get_person_from_handle(key) # nl = p.get_media_list() # for o in nl: # if o.get_reference_handle() == m_id: # nl.remove(o) # p.set_media_list(nl) # self.db.commit_person(p,None) # for key in self.db.get_source_handles(): # p = self.db.get_source_from_handle(key) # nl = p.get_media_list() # for o in nl: # if o.get_reference_handle() == m_id: # nl.remove(o) # p.set_media_list(nl) # self.db.commit_source(p,None) # for key in self.db.get_place_handles(): # p = self.db.get_place_from_handle(key) # nl = p.get_media_list() # for o in nl: # if o.get_reference_handle() == m_id: # nl.remove(o) # p.set_media_list(nl) # self.db.commit_place(p,None) # for key in self.db.get_event_handles(): # p = self.db.get_event_from_handle(key) # nl = p.get_media_list() # for o in nl: # if o.get_reference_handle() == m_id: # nl.remove(o) # p.set_media_list(nl) # self.db.commit_event(p,None) # self.db.remove_object(m_id,None) # def leave_clicked(): # # File is lost => do nothing, leave as is # pass # def select_clicked(): # # File is lost => select a file to replace the lost one # def fs_close_window(obj): # pass # def fs_ok_clicked(obj): # name = conv_to_unicode(fs_top.get_filename()) # if os.path.isfile(name): # archive.add(name) # fs_top = gtk.FileChooserDialog("%s - GRAMPS" % _("Select file"), # buttons=(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, # gtk.STOCK_OK, Gtk.ResponseType.OK) # ) # response = fs_top.run() # if response == Gtk.ResponseType.OK: # fs_ok_clicked(fs_top) # elif response == gtk.RESPONSE_CANCEL: # fs_close_window(fs_top) # fs_top.destroy() #--------------------------------------------------------------- try: archive = tarfile.open(self.filename,'w:gz') except EnvironmentError as msg: log.warn(str(msg)) self.user.notify_error(_('Failure writing %s') % self.filename, str(msg)) return 0 # Write media files first, since the database may be modified # during the process (i.e. when removing object) for m_id in self.db.get_media_object_handles(sort_handles=True): mobject = self.db.get_object_from_handle(m_id) filename = media_path_full(self.db, mobject.get_path()) archname = str(mobject.get_path()) if os.path.isfile(filename) and os.access(filename, os.R_OK): archive.add(filename, archname) # 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' : filename }, # remove_clicked, leave_clicked, select_clicked) # missmedia_action = mmd.default_action # elif missmedia_action == 1: # remove_clicked() # elif missmedia_action == 2: # leave_clicked() # elif missmedia_action == 3: # select_clicked() # Write XML now g = BytesIO() gfile = XmlWriter(self.db, self.user, 2) gfile.write_handle(g) tarinfo = tarfile.TarInfo('data.gramps') tarinfo.size = len(g.getvalue()) tarinfo.mtime = time.time() if not win(): tarinfo.uid = os.getuid() tarinfo.gid = os.getgid() g.seek(0) archive.addfile(tarinfo, g) archive.close() g.close() return True
def export(self): # missmedia_action = 0 #-------------------------------------------------------------- # def remove_clicked(): # # File is lost => remove all references and the object itself # for p_id in self.db.iter_family_handles(): # p = self.db.get_family_from_handle(p_id) # nl = p.get_media_list() # for o in nl: # if o.get_reference_handle() == m_id: # nl.remove(o) # p.set_media_list(nl) # self.db.commit_family(p,None) # for key in self.db.iter_person_handles(): # p = self.db.get_person_from_handle(key) # nl = p.get_media_list() # for o in nl: # if o.get_reference_handle() == m_id: # nl.remove(o) # p.set_media_list(nl) # self.db.commit_person(p,None) # for key in self.db.get_source_handles(): # p = self.db.get_source_from_handle(key) # nl = p.get_media_list() # for o in nl: # if o.get_reference_handle() == m_id: # nl.remove(o) # p.set_media_list(nl) # self.db.commit_source(p,None) # for key in self.db.get_place_handles(): # p = self.db.get_place_from_handle(key) # nl = p.get_media_list() # for o in nl: # if o.get_reference_handle() == m_id: # nl.remove(o) # p.set_media_list(nl) # self.db.commit_place(p,None) # for key in self.db.get_event_handles(): # p = self.db.get_event_from_handle(key) # nl = p.get_media_list() # for o in nl: # if o.get_reference_handle() == m_id: # nl.remove(o) # p.set_media_list(nl) # self.db.commit_event(p,None) # self.db.remove_media(m_id,None) # def leave_clicked(): # # File is lost => do nothing, leave as is # pass # def select_clicked(): # # File is lost => select a file to replace the lost one # def fs_close_window(obj): # pass # def fs_ok_clicked(obj): # name = fs_top.get_filename() # if os.path.isfile(name): # archive.add(name) # fs_top = gtk.FileChooserDialog("%s - GRAMPS" % _("Select file"), # buttons=(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, # gtk.STOCK_OK, Gtk.ResponseType.OK) # ) # response = fs_top.run() # if response == Gtk.ResponseType.OK: # fs_ok_clicked(fs_top) # elif response == gtk.RESPONSE_CANCEL: # fs_close_window(fs_top) # fs_top.destroy() #--------------------------------------------------------------- try: archive = tarfile.open(self.filename,'w:gz') except EnvironmentError as msg: log.warning(str(msg)) self.user.notify_error(_('Failure writing %s') % self.filename, str(msg)) return 0 # Write media files first, since the database may be modified # during the process (i.e. when removing object) for m_id in self.db.get_media_handles(sort_handles=True): mobject = self.db.get_media_from_handle(m_id) filename = media_path_full(self.db, mobject.get_path()) archname = str(mobject.get_path()) if os.path.isfile(filename) and os.access(filename, os.R_OK): archive.add(filename, archname) # Write XML now g = BytesIO() gfile = XmlWriter(self.db, self.user, 2) gfile.write_handle(g) tarinfo = tarfile.TarInfo('data.gramps') tarinfo.size = len(g.getvalue()) tarinfo.mtime = time.time() if not win(): tarinfo.uid = os.getuid() tarinfo.gid = os.getgid() g.seek(0) archive.addfile(tarinfo, g) archive.close() g.close() return True