fix app packaging

This commit is contained in:
niphlod
2015-03-19 00:04:24 +01:00
parent 09eb7ce3b7
commit cec0f8a0cf
+18 -8
View File
@@ -139,11 +139,14 @@ def listdir(path,
add_dirs=False,
sort=True,
maxnum=None,
exclude_content_from=None
):
"""
Like `os.listdir()` but you can specify a regex pattern to filter files.
If `add_dirs` is True, the returned items will have the full path.
"""
if exclude_content_from is None:
exclude_content_from = []
if path[-1:] != os.path.sep:
path = path + os.path.sep
if drop:
@@ -160,8 +163,9 @@ def listdir(path,
items.append(root[n:])
for file in sorted(files):
if regex.match(file) and not file.startswith('.'):
items.append(os.path.join(root, file)[n:])
if maxnum and len(items)>=maxnum:
if root not in exclude_content_from:
items.append(os.path.join(root, file)[n:])
if maxnum and len(items) >= maxnum:
break
if sort:
return sorted(items)
@@ -201,14 +205,16 @@ def _extractall(filename, path='.', members=None):
return ret
def tar(file, dir, expression='^.+$', filenames=None):
def tar(file, dir, expression='^.+$',
filenames=None, exclude_content_from=None):
"""Tars dir into file, only tars file that match expression
"""
tar = tarfile.TarFile(file, 'w')
try:
if filenames is None:
filenames = listdir(dir, expression, add_dirs=True)
filenames = listdir(dir, expression, add_dirs=True,
exclude_content_from=exclude_content_from)
for file in filenames:
tar.add(os.path.join(dir, file), file, False)
finally:
@@ -235,9 +241,11 @@ def w2p_pack(filename, path, compiled=False, filenames=None):
path = abspath(path)
tarname = filename + '.tar'
if compiled:
tar_compiled(tarname, path, '^[\w\.\-]+$')
tar_compiled(tarname, path, '^[\w\.\-]+$',
exclude_content_from=['cache', 'sessions', 'errors'])
else:
tar(tarname, path, '^[\w\.\-]+$', filenames=filenames)
tar(tarname, path, '^[\w\.\-]+$', filenames=filenames,
exclude_content_from=['cache', 'sessions', 'errors'])
w2pfp = gzopen(filename, 'wb')
tarfp = open(tarname, 'rb')
w2pfp.write(tarfp.read())
@@ -314,13 +322,15 @@ def w2p_unpack_plugin(filename, path, delete_tar=True):
w2p_unpack(filename, path, delete_tar)
def tar_compiled(file, dir, expression='^.+$'):
def tar_compiled(file, dir, expression='^.+$',
exclude_content_from=None):
"""Used to tar a compiled application.
The content of models, views, controllers is not stored in the tar file.
"""
tar = tarfile.TarFile(file, 'w')
for file in listdir(dir, expression, add_dirs=True):
for file in listdir(dir, expression, add_dirs=True,
exclude_content_from=exclude_content_from):
filename = os.path.join(dir, file)
if os.path.islink(filename):
continue