app pack custom

This commit is contained in:
mdipierro
2013-04-02 11:12:40 -05:00
parent 7714b5dc7b
commit 07e809acb3
6 changed files with 71 additions and 11 deletions
+6 -5
View File
@@ -223,19 +223,20 @@ def _extractall(filename, path='.', members=None):
return ret
def tar(file, dir, expression='^.+$'):
def tar(file, dir, expression='^.+$', filenames=None):
"""
tars dir into file, only tars file that match expression
"""
tar = tarfile.TarFile(file, 'w')
try:
for file in listdir(dir, expression, add_dirs=True):
if filenames is None:
filenames = listdir(dir, expression, add_dirs=True)
for file in filenames:
tar.add(os.path.join(dir, file), file, False)
finally:
tar.close()
def untar(file, dir):
"""
untar file into dir
@@ -244,14 +245,14 @@ def untar(file, dir):
_extractall(file, dir)
def w2p_pack(filename, path, compiled=False):
def w2p_pack(filename, path, compiled=False, filenames=None):
filename = abspath(filename)
path = abspath(path)
tarname = filename + '.tar'
if compiled:
tar_compiled(tarname, path, '^[\w\.\-]+$')
else:
tar(tarname, path, '^[\w\.\-]+$')
tar(tarname, path, '^[\w\.\-]+$', filenames=filenames)
w2pfp = gzopen(filename, 'wb')
tarfp = open(tarname, 'rb')
w2pfp.write(tarfp.read())