From 09b0beacf0c2a041ad71a1aabced5c0ad9f0a168 Mon Sep 17 00:00:00 2001 From: Don Allingham Date: Thu, 4 Oct 2001 17:23:28 +0000 Subject: [PATCH] Added package generation export filter svn: r446 --- gramps/src/KwordDoc.py | 62 +---- gramps/src/TarFile.py | 80 ++++++ gramps/src/WriteXML.py | 47 ++-- gramps/src/plugins/WritePkg.py | 129 +++++++++ gramps/src/plugins/pkgexport.glade | 432 +++++++++++++++++++++++++++++ 5 files changed, 671 insertions(+), 79 deletions(-) create mode 100644 gramps/src/TarFile.py create mode 100644 gramps/src/plugins/WritePkg.py create mode 100644 gramps/src/plugins/pkgexport.glade diff --git a/gramps/src/KwordDoc.py b/gramps/src/KwordDoc.py index 18a68cb4b..911a304d4 100644 --- a/gramps/src/KwordDoc.py +++ b/gramps/src/KwordDoc.py @@ -25,67 +25,7 @@ import time import StringIO import os import gzip - -_BLKSIZE=512 - - -nul = '\0' - -#------------------------------------------------------------------------ -# -# -# -#------------------------------------------------------------------------ -class TarFile: - def __init__(self,name): - self.name = name - self.f = gzip.open(name,"wb") - self.pos = 0 - - def add_file(self,filename,mtime,iobuf): - iobuf.seek(0,2) - length = iobuf.tell() - iobuf.seek(0) - - buf = filename - buf = buf + '\0'*(100-len(filename)) - buf = buf + "0100664" + nul - buf = buf + "0000764" + nul - buf = buf + "0000764" + nul - buf = buf + "%011o" % length + nul - buf = buf + "%011o" % mtime + nul - buf = buf + "%s" - buf = buf + "0" + '\0'*100 + 'ustar \0' - buf = buf + '\0'*32 - buf = buf + '\0'*32 - buf = buf + '\0'*183 - - chksum = 0 - blank = " " - temp = buf % (blank) - for c in temp: - chksum = chksum + ord(c) - sum = "%06o " % chksum - sum = sum + nul - buf = buf % sum - - self.pos = self.pos + len(buf) - self.f.write(buf) - - buf = iobuf.read(length) - self.f.write(buf) - self.pos = self.pos + length - rem = _BLKSIZE - (self.pos % _BLKSIZE) - if rem != 0: - self.f.write('\0' * rem) - self.pos = self.pos + rem - - - def close(self): - rem = (_BLKSIZE*20) - (self.pos % (_BLKSIZE*20)) - if rem != 0: - self.f.write('\0' * rem) - self.f.close() +from TarFile import TarFile #------------------------------------------------------------------------ # diff --git a/gramps/src/TarFile.py b/gramps/src/TarFile.py new file mode 100644 index 000000000..c72b75f8f --- /dev/null +++ b/gramps/src/TarFile.py @@ -0,0 +1,80 @@ +# +# Gramps - a GTK+/GNOME based genealogy program +# +# Copyright (C) 2000 Donald N. Allingham +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +import gzip + +_BLKSIZE=512 +nul = '\0' + +#------------------------------------------------------------------------ +# +# +# +#------------------------------------------------------------------------ +class TarFile: + def __init__(self,name): + self.name = name + self.f = gzip.open(name,"wb") + self.pos = 0 + + def add_file(self,filename,mtime,iobuf): + iobuf.seek(0,2) + length = iobuf.tell() + iobuf.seek(0) + + buf = filename + buf = buf + '\0'*(100-len(filename)) + buf = buf + "0100664" + nul + buf = buf + "0000764" + nul + buf = buf + "0000764" + nul + buf = buf + "%011o" % length + nul + buf = buf + "%011o" % mtime + nul + buf = buf + "%s" + buf = buf + "0" + '\0'*100 + 'ustar \0' + buf = buf + '\0'*32 + buf = buf + '\0'*32 + buf = buf + '\0'*183 + + chksum = 0 + blank = " " + temp = buf % (blank) + for c in temp: + chksum = chksum + ord(c) + sum = "%06o " % chksum + sum = sum + nul + buf = buf % sum + + self.pos = self.pos + len(buf) + self.f.write(buf) + + buf = iobuf.read(length) + self.f.write(buf) + self.pos = self.pos + length + rem = _BLKSIZE - (self.pos % _BLKSIZE) + if rem != 0: + self.f.write('\0' * rem) + self.pos = self.pos + rem + + + def close(self): + rem = (_BLKSIZE*20) - (self.pos % (_BLKSIZE*20)) + if rem != 0: + self.f.write('\0' * rem) + self.f.close() + diff --git a/gramps/src/WriteXML.py b/gramps/src/WriteXML.py index 8ef3e4d59..21a5aa92d 100644 --- a/gramps/src/WriteXML.py +++ b/gramps/src/WriteXML.py @@ -285,10 +285,13 @@ def write_attribute_list(g, list): def write_photo_list(g,list): for photo in list: path = photo.getPath() - l = len(fileroot) - if len(path) >= l: - if fileroot == path[0:l]: - path = path[l+1:] + if strip_photo: + path = os.path.basename(path) + else: + l = len(fileroot) + if len(path) >= l: + if fileroot == path[0:l]: + path = path[l+1:] g.write(' \n') g.write('\n') g.write("\n") @@ -511,5 +523,4 @@ def exportData(database, filename, callback): g.write(" \n") g.write("\n") - g.close() diff --git a/gramps/src/plugins/WritePkg.py b/gramps/src/plugins/WritePkg.py new file mode 100644 index 000000000..2bfe8439e --- /dev/null +++ b/gramps/src/plugins/WritePkg.py @@ -0,0 +1,129 @@ +# +# Gramps - a GTK+/GNOME based genealogy program +# +# Copyright (C) 2000 Donald N. Allingham +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# + +"Export to GRAMPS package" + +from RelLib import * + +import const +import WriteXML +import time +import os +import TarFile +import utils +import libglade + +from cStringIO import StringIO +import intl +_ = intl.gettext + +def writeData(database,person): + global db + global topDialog + global active_person + + db = database + active_person = person + + base = os.path.dirname(__file__) + glade_file = base + os.sep + "pkgexport.glade" + + dic = { + "destroy_passed_object" : utils.destroy_passed_object, + "on_ok_clicked" : on_ok_clicked + } + + topDialog = libglade.GladeXML(glade_file,"packageExport") + topDialog.signal_autoconnect(dic) + + topDialog.get_widget("packageExport").show() + +#------------------------------------------------------------------------- +# +# +# +#------------------------------------------------------------------------- +def on_ok_clicked(obj): + global db + global topDialog + + name = topDialog.get_widget("filename").get_text() + utils.destroy_passed_object(obj) + exportData(db,name) + +def callback(a): + pass + +def exportData(database, filename): + + t = TarFile.TarFile(filename) + g = StringIO() + WriteXML.write_xml_data(database,g,callback,1) + mtime = time.time() + t.add_file("data.gramps",mtime,g) + g.close() + + for f in database.getPersonMap().values(): + for p in f.getPhotoList(): + base = os.path.basename(p.getPath()) + try: + g = open(p.getPath(),"rb") + t.add_file(base,mtime,g) + g.close() + except: + pass + for f in database.getFamilyMap().values(): + for p in f.getPhotoList(): + base = os.path.basename(p.getPath()) + try: + g = open(p.getPath(),"rb") + t.add_file(base,mtime,g) + g.close() + except: + pass + for f in database.getSourceMap().values(): + for p in f.getPhotoList(): + base = os.path.basename(p.getPath()) + try: + g = open(p.getPath(),"rb") + t.add_file(base,mtime,g) + g.close() + except: + pass + for f in database.getPlaceMap().values(): + for p in f.getPhotoList(): + base = os.path.basename(p.getPath()) + try: + g = open(p.getPath(),"rb") + t.add_file(base,mtime,g) + g.close() + except: + pass + + t.close() + +#------------------------------------------------------------------------- +# +# +# +#------------------------------------------------------------------------- +from Plugins import register_export + +register_export(writeData,_("Export to GRAMPS package")) diff --git a/gramps/src/plugins/pkgexport.glade b/gramps/src/plugins/pkgexport.glade new file mode 100644 index 000000000..4c33dca16 --- /dev/null +++ b/gramps/src/plugins/pkgexport.glade @@ -0,0 +1,432 @@ + + + + + GEDCOM Export + gedcomexport + + src + pixmaps + C + True + True + + + + GnomeDialog + packageExport + Gramps - Export GRAMPS package + GTK_WINDOW_TOPLEVEL + GTK_WIN_POS_CENTER + True + False + False + False + False + False + + + GtkVBox + GnomeDialog:vbox + dialog-vbox1 + False + 8 + + 4 + True + True + + + + GtkHButtonBox + GnomeDialog:action_area + dialog-action_area1 + GTK_BUTTONBOX_END + 8 + 85 + 27 + 7 + 0 + + 0 + False + True + GTK_PACK_END + + + + GtkButton + ok + True + True + + clicked + on_ok_clicked + packageExport + Thu, 30 Nov 2000 20:58:29 GMT + + GNOME_STOCK_BUTTON_OK + + + + GtkButton + cancel + True + True + + clicked + destroy_passed_object + packageExport + Thu, 30 Nov 2000 19:30:56 GMT + + GNOME_STOCK_BUTTON_CANCEL + + + + + GtkVBox + vbox1 + False + 0 + + 0 + True + True + + + + GtkLabel + exportTitle + + GTK_JUSTIFY_CENTER + False + 0.5 + 0.5 + 0 + 0 + + 0 + False + False + + + + + GtkHSeparator + hseparator1 + + 10 + True + True + + + + + GnomeFileEntry + fileentry1 + 350 + pkgExport + 10 + Export GEDCOM + False + True + + 5 + False + False + + + + GtkEntry + GnomeEntry:entry + filename + True + True + True + 0 + + + + + + + + + GnomeDialog + exportprogress + Export GRAMPS package + GTK_WINDOW_TOPLEVEL + GTK_WIN_POS_CENTER + False + False + True + False + False + False + + + GtkVBox + GnomeDialog:vbox + dialog-vbox2 + False + 8 + + 4 + True + True + + + + GtkHButtonBox + GnomeDialog:action_area + dialog-action_area2 + GTK_BUTTONBOX_END + 8 + 85 + 27 + 7 + 0 + + 0 + False + True + GTK_PACK_END + + + + GtkButton + close + True + True + + clicked + on_close_clicked + exportprogress + Tue, 25 Sep 2001 23:46:20 GMT + + GNOME_STOCK_BUTTON_CLOSE + + + + + GtkVBox + vbox4 + False + 0 + + 0 + True + True + + + + GtkLabel + label1 + + GTK_JUSTIFY_CENTER + False + 0.5 + 0.5 + 0 + 0 + + 0 + False + False + + + + + GtkHSeparator + hseparator2 + + 5 + False + True + + + + + GtkTable + table1 + 3 + 2 + False + 0 + 0 + + 0 + True + True + + + + GtkLabel + label4 + + GTK_JUSTIFY_CENTER + False + 0 + 0.5 + 0 + 0 + + 0 + 1 + 2 + 3 + 5 + 5 + False + False + False + False + True + False + + + + + GtkLabel + label3 + + GTK_JUSTIFY_CENTER + False + 0 + 0.5 + 0 + 0 + + 0 + 1 + 1 + 2 + 5 + 5 + False + False + False + False + True + False + + + + + GtkLabel + label2 + + GTK_JUSTIFY_CENTER + False + 0 + 0.5 + 0 + 0 + + 0 + 1 + 0 + 1 + 5 + 5 + False + False + False + False + True + False + + + + + GtkProgressBar + pbar + 0 + 0 + 100 + GTK_PROGRESS_CONTINUOUS + GTK_PROGRESS_LEFT_TO_RIGHT + False + False + %P %% + 0.5 + 0.5 + + 1 + 2 + 0 + 1 + 0 + 0 + True + False + False + False + True + False + + + + + GtkProgressBar + fbar + 0 + 0 + 100 + GTK_PROGRESS_CONTINUOUS + GTK_PROGRESS_LEFT_TO_RIGHT + False + False + %P %% + 0.5 + 0.5 + + 1 + 2 + 1 + 2 + 0 + 0 + True + False + False + False + True + False + + + + + GtkProgressBar + sbar + 0 + 0 + 100 + GTK_PROGRESS_CONTINUOUS + GTK_PROGRESS_LEFT_TO_RIGHT + False + False + %P %% + 0.5 + 0.5 + + 1 + 2 + 2 + 3 + 0 + 0 + True + False + False + False + True + False + + + + + + + +