2
# Gramps - a GTK+/GNOME based genealogy program
4
# Copyright (C) 2000 Donald N. Allingham
6
# This program is free software; you can redistribute it and/or modify
7
# it under the terms of the GNU General Public License as published by
8
# the Free Software Foundation; either version 2 of the License, or
9
# (at your option) any later version.
11
# This program is distributed in the hope that it will be useful,
12
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
# GNU General Public License for more details.
16
# You should have received a copy of the GNU General Public License
17
# along with this program; if not, write to the Free Software
18
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27
#------------------------------------------------------------------------
31
#------------------------------------------------------------------------
33
def __init__(self,name):
35
self.f = gzip.open(name,"wb")
38
def add_file(self,filename,mtime,iobuf):
44
buf = buf + '\0'*(100-len(filename))
45
buf = buf + "0100664" + nul
46
buf = buf + "0000764" + nul
47
buf = buf + "0000764" + nul
48
buf = buf + "%011o" % length + nul
49
buf = buf + "%011o" % mtime + nul
51
buf = buf + "0" + '\0'*100 + 'ustar \0'
60
chksum = chksum + ord(c)
61
sum = "%06o " % chksum
65
self.pos = self.pos + len(buf)
68
buf = iobuf.read(length)
70
self.pos = self.pos + length
71
rem = _BLKSIZE - (self.pos % _BLKSIZE)
73
self.f.write('\0' * rem)
74
self.pos = self.pos + rem
77
rem = (_BLKSIZE*20) - (self.pos % (_BLKSIZE*20))
79
self.f.write('\0' * rem)
82
#------------------------------------------------------------------------
86
#------------------------------------------------------------------------
88
def __init__(self,name,wd="/tmp"):
91
self.f = gzip.open(name,"rb")
94
def extract_files(self):
97
buf = self.f.read(100)
108
filename = buf[0:index]
111
self.f.read(24) # modes
112
l = string.replace(self.f.read(12),chr(0),' ')
120
foo = cStringIO.StringIO()
122
foo.write(self.f.read(length))
124
self.f.read(_BLKSIZE-(length%_BLKSIZE))
128
buf = self.f.read(100)
139
filename = buf[0:index]
140
self.f.read(24) # modes
145
length_string = length_string + char
146
length = int(length_string,8)
153
foo = open("%s/%s" % (self.wd,filename),"wb")
154
foo.write(self.f.read(length))
156
self.f.read(_BLKSIZE-(length%_BLKSIZE))