Added package generation export filter

svn: r446
This commit is contained in:
Don Allingham 2001-10-04 17:23:28 +00:00
parent 299ebdf15c
commit 09b0beacf0
5 changed files with 671 additions and 79 deletions

View File

@ -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
#------------------------------------------------------------------------
#

80
gramps/src/TarFile.py Normal file
View File

@ -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()

View File

@ -285,6 +285,9 @@ def write_attribute_list(g, list):
def write_photo_list(g,list):
for photo in list:
path = photo.getPath()
if strip_photo:
path = os.path.basename(path)
else:
l = len(fileroot)
if len(path) >= l:
if fileroot == path[0:l]:
@ -335,21 +338,9 @@ def write_place_obj(g,place):
#-------------------------------------------------------------------------
def exportData(database, filename, callback):
global fileroot
date = string.split(time.ctime(time.time()))
fileroot = os.path.dirname(filename)
owner = database.getResearcher()
personList = database.getPersonMap().values()
personList.sort(sortById)
familyList = database.getFamilyMap().values()
familyList.sort(sortById)
sourceList = database.getSourceMap().values()
placeList = database.getPlaceMap().values()
placeList.sort(sortById)
total = len(personList) + len(familyList)
if os.path.isfile(filename):
shutil.copy(filename, filename + ".bak")
@ -361,6 +352,27 @@ def exportData(database, filename, callback):
else:
g = open(filename,"w")
write_xml_data(database, g, callback, 0)
g.close()
def write_xml_data(database, g, callback, sp):
global strip_photo
strip_photo = sp
date = string.split(time.ctime(time.time()))
owner = database.getResearcher()
personList = database.getPersonMap().values()
personList.sort(sortById)
familyList = database.getFamilyMap().values()
familyList.sort(sortById)
sourceList = database.getSourceMap().values()
placeList = database.getPlaceMap().values()
placeList.sort(sortById)
total = len(personList) + len(familyList)
g.write('<?xml version="1.0" encoding="iso-8859-1"?>\n')
g.write('<!DOCTYPE database SYSTEM "gramps.dtd" []>\n')
g.write("<database>\n")
@ -511,5 +523,4 @@ def exportData(database, filename, callback):
g.write(" </bookmarks>\n")
g.write("</database>\n")
g.close()

View File

@ -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"))

View File

@ -0,0 +1,432 @@
<?xml version="1.0"?>
<GTK-Interface>
<project>
<name>GEDCOM Export</name>
<program_name>gedcomexport</program_name>
<directory></directory>
<source_directory>src</source_directory>
<pixmaps_directory>pixmaps</pixmaps_directory>
<language>C</language>
<gnome_support>True</gnome_support>
<gettext_support>True</gettext_support>
</project>
<widget>
<class>GnomeDialog</class>
<name>packageExport</name>
<title>Gramps - Export GRAMPS package</title>
<type>GTK_WINDOW_TOPLEVEL</type>
<position>GTK_WIN_POS_CENTER</position>
<modal>True</modal>
<allow_shrink>False</allow_shrink>
<allow_grow>False</allow_grow>
<auto_shrink>False</auto_shrink>
<auto_close>False</auto_close>
<hide_on_close>False</hide_on_close>
<widget>
<class>GtkVBox</class>
<child_name>GnomeDialog:vbox</child_name>
<name>dialog-vbox1</name>
<homogeneous>False</homogeneous>
<spacing>8</spacing>
<child>
<padding>4</padding>
<expand>True</expand>
<fill>True</fill>
</child>
<widget>
<class>GtkHButtonBox</class>
<child_name>GnomeDialog:action_area</child_name>
<name>dialog-action_area1</name>
<layout_style>GTK_BUTTONBOX_END</layout_style>
<spacing>8</spacing>
<child_min_width>85</child_min_width>
<child_min_height>27</child_min_height>
<child_ipad_x>7</child_ipad_x>
<child_ipad_y>0</child_ipad_y>
<child>
<padding>0</padding>
<expand>False</expand>
<fill>True</fill>
<pack>GTK_PACK_END</pack>
</child>
<widget>
<class>GtkButton</class>
<name>ok</name>
<can_default>True</can_default>
<can_focus>True</can_focus>
<signal>
<name>clicked</name>
<handler>on_ok_clicked</handler>
<object>packageExport</object>
<last_modification_time>Thu, 30 Nov 2000 20:58:29 GMT</last_modification_time>
</signal>
<stock_button>GNOME_STOCK_BUTTON_OK</stock_button>
</widget>
<widget>
<class>GtkButton</class>
<name>cancel</name>
<can_default>True</can_default>
<can_focus>True</can_focus>
<signal>
<name>clicked</name>
<handler>destroy_passed_object</handler>
<object>packageExport</object>
<last_modification_time>Thu, 30 Nov 2000 19:30:56 GMT</last_modification_time>
</signal>
<stock_button>GNOME_STOCK_BUTTON_CANCEL</stock_button>
</widget>
</widget>
<widget>
<class>GtkVBox</class>
<name>vbox1</name>
<homogeneous>False</homogeneous>
<spacing>0</spacing>
<child>
<padding>0</padding>
<expand>True</expand>
<fill>True</fill>
</child>
<widget>
<class>GtkLabel</class>
<name>exportTitle</name>
<label>GRAMPS package export</label>
<justify>GTK_JUSTIFY_CENTER</justify>
<wrap>False</wrap>
<xalign>0.5</xalign>
<yalign>0.5</yalign>
<xpad>0</xpad>
<ypad>0</ypad>
<child>
<padding>0</padding>
<expand>False</expand>
<fill>False</fill>
</child>
</widget>
<widget>
<class>GtkHSeparator</class>
<name>hseparator1</name>
<child>
<padding>10</padding>
<expand>True</expand>
<fill>True</fill>
</child>
</widget>
<widget>
<class>GnomeFileEntry</class>
<name>fileentry1</name>
<width>350</width>
<history_id>pkgExport</history_id>
<max_saved>10</max_saved>
<title>Export GEDCOM</title>
<directory>False</directory>
<modal>True</modal>
<child>
<padding>5</padding>
<expand>False</expand>
<fill>False</fill>
</child>
<widget>
<class>GtkEntry</class>
<child_name>GnomeEntry:entry</child_name>
<name>filename</name>
<can_focus>True</can_focus>
<editable>True</editable>
<text_visible>True</text_visible>
<text_max_length>0</text_max_length>
<text></text>
</widget>
</widget>
</widget>
</widget>
</widget>
<widget>
<class>GnomeDialog</class>
<name>exportprogress</name>
<title>Export GRAMPS package</title>
<type>GTK_WINDOW_TOPLEVEL</type>
<position>GTK_WIN_POS_CENTER</position>
<modal>False</modal>
<allow_shrink>False</allow_shrink>
<allow_grow>True</allow_grow>
<auto_shrink>False</auto_shrink>
<auto_close>False</auto_close>
<hide_on_close>False</hide_on_close>
<widget>
<class>GtkVBox</class>
<child_name>GnomeDialog:vbox</child_name>
<name>dialog-vbox2</name>
<homogeneous>False</homogeneous>
<spacing>8</spacing>
<child>
<padding>4</padding>
<expand>True</expand>
<fill>True</fill>
</child>
<widget>
<class>GtkHButtonBox</class>
<child_name>GnomeDialog:action_area</child_name>
<name>dialog-action_area2</name>
<layout_style>GTK_BUTTONBOX_END</layout_style>
<spacing>8</spacing>
<child_min_width>85</child_min_width>
<child_min_height>27</child_min_height>
<child_ipad_x>7</child_ipad_x>
<child_ipad_y>0</child_ipad_y>
<child>
<padding>0</padding>
<expand>False</expand>
<fill>True</fill>
<pack>GTK_PACK_END</pack>
</child>
<widget>
<class>GtkButton</class>
<name>close</name>
<can_default>True</can_default>
<can_focus>True</can_focus>
<signal>
<name>clicked</name>
<handler>on_close_clicked</handler>
<object>exportprogress</object>
<last_modification_time>Tue, 25 Sep 2001 23:46:20 GMT</last_modification_time>
</signal>
<stock_button>GNOME_STOCK_BUTTON_CLOSE</stock_button>
</widget>
</widget>
<widget>
<class>GtkVBox</class>
<name>vbox4</name>
<homogeneous>False</homogeneous>
<spacing>0</spacing>
<child>
<padding>0</padding>
<expand>True</expand>
<fill>True</fill>
</child>
<widget>
<class>GtkLabel</class>
<name>label1</name>
<label>GEDCOM Export</label>
<justify>GTK_JUSTIFY_CENTER</justify>
<wrap>False</wrap>
<xalign>0.5</xalign>
<yalign>0.5</yalign>
<xpad>0</xpad>
<ypad>0</ypad>
<child>
<padding>0</padding>
<expand>False</expand>
<fill>False</fill>
</child>
</widget>
<widget>
<class>GtkHSeparator</class>
<name>hseparator2</name>
<child>
<padding>5</padding>
<expand>False</expand>
<fill>True</fill>
</child>
</widget>
<widget>
<class>GtkTable</class>
<name>table1</name>
<rows>3</rows>
<columns>2</columns>
<homogeneous>False</homogeneous>
<row_spacing>0</row_spacing>
<column_spacing>0</column_spacing>
<child>
<padding>0</padding>
<expand>True</expand>
<fill>True</fill>
</child>
<widget>
<class>GtkLabel</class>
<name>label4</name>
<label>Sources</label>
<justify>GTK_JUSTIFY_CENTER</justify>
<wrap>False</wrap>
<xalign>0</xalign>
<yalign>0.5</yalign>
<xpad>0</xpad>
<ypad>0</ypad>
<child>
<left_attach>0</left_attach>
<right_attach>1</right_attach>
<top_attach>2</top_attach>
<bottom_attach>3</bottom_attach>
<xpad>5</xpad>
<ypad>5</ypad>
<xexpand>False</xexpand>
<yexpand>False</yexpand>
<xshrink>False</xshrink>
<yshrink>False</yshrink>
<xfill>True</xfill>
<yfill>False</yfill>
</child>
</widget>
<widget>
<class>GtkLabel</class>
<name>label3</name>
<label>Families</label>
<justify>GTK_JUSTIFY_CENTER</justify>
<wrap>False</wrap>
<xalign>0</xalign>
<yalign>0.5</yalign>
<xpad>0</xpad>
<ypad>0</ypad>
<child>
<left_attach>0</left_attach>
<right_attach>1</right_attach>
<top_attach>1</top_attach>
<bottom_attach>2</bottom_attach>
<xpad>5</xpad>
<ypad>5</ypad>
<xexpand>False</xexpand>
<yexpand>False</yexpand>
<xshrink>False</xshrink>
<yshrink>False</yshrink>
<xfill>True</xfill>
<yfill>False</yfill>
</child>
</widget>
<widget>
<class>GtkLabel</class>
<name>label2</name>
<label>People</label>
<justify>GTK_JUSTIFY_CENTER</justify>
<wrap>False</wrap>
<xalign>0</xalign>
<yalign>0.5</yalign>
<xpad>0</xpad>
<ypad>0</ypad>
<child>
<left_attach>0</left_attach>
<right_attach>1</right_attach>
<top_attach>0</top_attach>
<bottom_attach>1</bottom_attach>
<xpad>5</xpad>
<ypad>5</ypad>
<xexpand>False</xexpand>
<yexpand>False</yexpand>
<xshrink>False</xshrink>
<yshrink>False</yshrink>
<xfill>True</xfill>
<yfill>False</yfill>
</child>
</widget>
<widget>
<class>GtkProgressBar</class>
<name>pbar</name>
<value>0</value>
<lower>0</lower>
<upper>100</upper>
<bar_style>GTK_PROGRESS_CONTINUOUS</bar_style>
<orientation>GTK_PROGRESS_LEFT_TO_RIGHT</orientation>
<activity_mode>False</activity_mode>
<show_text>False</show_text>
<format>%P %%</format>
<text_xalign>0.5</text_xalign>
<text_yalign>0.5</text_yalign>
<child>
<left_attach>1</left_attach>
<right_attach>2</right_attach>
<top_attach>0</top_attach>
<bottom_attach>1</bottom_attach>
<xpad>0</xpad>
<ypad>0</ypad>
<xexpand>True</xexpand>
<yexpand>False</yexpand>
<xshrink>False</xshrink>
<yshrink>False</yshrink>
<xfill>True</xfill>
<yfill>False</yfill>
</child>
</widget>
<widget>
<class>GtkProgressBar</class>
<name>fbar</name>
<value>0</value>
<lower>0</lower>
<upper>100</upper>
<bar_style>GTK_PROGRESS_CONTINUOUS</bar_style>
<orientation>GTK_PROGRESS_LEFT_TO_RIGHT</orientation>
<activity_mode>False</activity_mode>
<show_text>False</show_text>
<format>%P %%</format>
<text_xalign>0.5</text_xalign>
<text_yalign>0.5</text_yalign>
<child>
<left_attach>1</left_attach>
<right_attach>2</right_attach>
<top_attach>1</top_attach>
<bottom_attach>2</bottom_attach>
<xpad>0</xpad>
<ypad>0</ypad>
<xexpand>True</xexpand>
<yexpand>False</yexpand>
<xshrink>False</xshrink>
<yshrink>False</yshrink>
<xfill>True</xfill>
<yfill>False</yfill>
</child>
</widget>
<widget>
<class>GtkProgressBar</class>
<name>sbar</name>
<value>0</value>
<lower>0</lower>
<upper>100</upper>
<bar_style>GTK_PROGRESS_CONTINUOUS</bar_style>
<orientation>GTK_PROGRESS_LEFT_TO_RIGHT</orientation>
<activity_mode>False</activity_mode>
<show_text>False</show_text>
<format>%P %%</format>
<text_xalign>0.5</text_xalign>
<text_yalign>0.5</text_yalign>
<child>
<left_attach>1</left_attach>
<right_attach>2</right_attach>
<top_attach>2</top_attach>
<bottom_attach>3</bottom_attach>
<xpad>0</xpad>
<ypad>0</ypad>
<xexpand>True</xexpand>
<yexpand>False</yexpand>
<xshrink>False</xshrink>
<yshrink>False</yshrink>
<xfill>True</xfill>
<yfill>False</yfill>
</child>
</widget>
</widget>
</widget>
</widget>
</widget>
</GTK-Interface>