From cec0f8a0cf47559bc6856e5ed0b0db2e150ac451 Mon Sep 17 00:00:00 2001 From: niphlod Date: Thu, 19 Mar 2015 00:04:24 +0100 Subject: [PATCH] fix app packaging --- gluon/fileutils.py | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/gluon/fileutils.py b/gluon/fileutils.py index 1eda8553..8d77d101 100644 --- a/gluon/fileutils.py +++ b/gluon/fileutils.py @@ -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