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