comparison carton.py @ 13:f522620c6a78

now works properly with tarballs
author Jeff Hammel <jhammel@mozilla.com>
date Fri, 08 Jul 2011 15:20:01 -0700
parents 542b46ac4e28
children c474362cf69a
comparison
equal deleted inserted replaced
12:542b46ac4e28 13:f522620c6a78
141 141
142 if isURL(source): 142 if isURL(source):
143 # remote tarball 143 # remote tarball
144 raise NotImplementedError 144 raise NotImplementedError
145 else: 145 else:
146 assert os.path.exists(source), "%s does not exist" % source
147
146 # local directory or tarball 148 # local directory or tarball
147 # TODO: check for a tarball 149 if (not os.path.isdir(source)) and tarfile.is_tarfile(source):
148 source_buffer = StringIO() 150 # check for a tarball
149 source_tar = tarfile.open(mode="w:gz", fileobj=source_buffer) 151 buffer = file(source).read()
150 source_tar.add(source, arcname=os.path.basename(source)) 152 else:
151 source_tar.close() 153 source_buffer = StringIO()
152 buffer = source_buffer.getvalue() 154 source_tar = tarfile.open(mode="w:gz", fileobj=source_buffer)
155 source_tar.add(source, arcname=os.path.basename(source))
156 source_tar.close()
157 buffer = source_buffer.getvalue()
153 158
154 # could use git, hg, etc repos. but probably shouldn't 159 # could use git, hg, etc repos. but probably shouldn't
155 160
156 source_array.append(buffer.encode('zlib').encode('base64')) 161 source_array.append(buffer.encode('zlib').encode('base64'))
157 162