From 07e809acb31633cb3fb21e43e2cd857bd7586911 Mon Sep 17 00:00:00 2001 From: mdipierro Date: Tue, 2 Apr 2013 11:12:40 -0500 Subject: [PATCH] app pack custom --- VERSION | 2 +- applications/admin/controllers/default.py | 30 +++++++++++++++-- .../admin/views/default/pack_custom.html | 32 +++++++++++++++++++ applications/admin/views/default/site.html | 1 + gluon/admin.py | 6 ++-- gluon/fileutils.py | 11 ++++--- 6 files changed, 71 insertions(+), 11 deletions(-) create mode 100644 applications/admin/views/default/pack_custom.html diff --git a/VERSION b/VERSION index 2af7428b..be1ad23e 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -Version 2.4.5-stable+timestamp.2013.04.01.19.18.09 +Version 2.4.5-stable+timestamp.2013.04.02.11.12.01 diff --git a/applications/admin/controllers/default.py b/applications/admin/controllers/default.py index 5c40ac95..5881d16a 100644 --- a/applications/admin/controllers/default.py +++ b/applications/admin/controllers/default.py @@ -27,7 +27,7 @@ from gluon.languages import (read_possible_languages, read_dict, write_dict, read_plural_dict, write_plural_dict) -if DEMO_MODE and request.function in ['change_password', 'pack', 'pack_plugin', 'upgrade_web2py', 'uninstall', 'cleanup', 'compile_app', 'remove_compiled_app', 'delete', 'delete_plugin', 'create_file', 'upload_file', 'update_languages', 'reload_routes', 'git_push', 'git_pull']: +if DEMO_MODE and request.function in ['change_password', 'pack', 'pack_custom','pack_plugin', 'upgrade_web2py', 'uninstall', 'cleanup', 'compile_app', 'remove_compiled_app', 'delete', 'delete_plugin', 'create_file', 'upload_file', 'update_languages', 'reload_routes', 'git_push', 'git_pull']: session.flash = T('disabled in demo mode') redirect(URL('site')) @@ -341,7 +341,6 @@ def pack(): session.flash = T('internal error: %s' % e) redirect(URL('site')) - def pack_plugin(): app = get_app() if len(request.args) == 2: @@ -356,6 +355,33 @@ def pack_plugin(): session.flash = T('internal error') redirect(URL('plugin', args=request.args)) +def pack_custom(): + app = get_app() + base = apath(app, r=request) + if request.post_vars.file: + files = request.post_vars.file + files = [files] if not isinstance(files,list) else files + fname = 'web2py.app.%s.w2p' % app + try: + filename = app_pack(app, request, raise_ex=True, filenames=files) + except Exception, e: + filename = None + if filename: + response.headers['Content-Type'] = 'application/w2p' + disposition = 'attachment; filename=%s' % fname + response.headers['Content-Disposition'] = disposition + return safe_read(filename, 'rb') + else: + session.flash = T('internal error: %s' % e) + redirect(URL(args=request.args)) + def ignore(fs): + return [f for f in fs if not ( + f[:1] in '#' or f.endswith('~') or f.endswith('.bak'))] + files = {} + for (r,d,f) in os.walk(base): + files[r] = {'folders':ignore(d),'files':ignore(f)} + return locals() + def upgrade_web2py(): dialog = FORM.confirm(T('Upgrade'), diff --git a/applications/admin/views/default/pack_custom.html b/applications/admin/views/default/pack_custom.html new file mode 100644 index 00000000..1d2dfcd5 --- /dev/null +++ b/applications/admin/views/default/pack_custom.html @@ -0,0 +1,32 @@ +{{extend 'layout.html'}} +{{import os}} + +{{def tree(path):}} + + + {{=path[len(base):] or '/%s' % app}} + + + {{return}} + +
+

{{=T('Select Files to Package')}}

+ +
+{{tree(base)}} +
+
+ diff --git a/applications/admin/views/default/site.html b/applications/admin/views/default/site.html index 8a91d75f..5f56c45e 100644 --- a/applications/admin/views/default/site.html +++ b/applications/admin/views/default/site.html @@ -25,6 +25,7 @@ {{buttons.append((URL('errors',args=a), T("Errors")))}} {{buttons.append((URL('cleanup',args=a), T("Clean")))}} {{buttons.append((URL('pack',args=a), T("Pack all")))}} + {{buttons.append((URL('pack_custom',args=a), T("Pack custom")))}} {{if not os.path.exists('applications/%s/compiled' % a):}} {{buttons.append((URL('compile_app',args=a), T("Compile")))}} {{else:}} diff --git a/gluon/admin.py b/gluon/admin.py index 23b3a823..8801d44b 100644 --- a/gluon/admin.py +++ b/gluon/admin.py @@ -43,7 +43,7 @@ def apath(path='', r=None): return os.path.join(opath, path).replace('\\', '/') -def app_pack(app, request, raise_ex=False): +def app_pack(app, request, raise_ex=False, filenames=None): """ Builds a w2p package for the application @@ -60,9 +60,9 @@ def app_pack(app, request, raise_ex=False): filename of the w2p file or None on error """ try: - app_cleanup(app, request) + if filenames is None: app_cleanup(app, request) filename = apath('../deposit/web2py.app.%s.w2p' % app, request) - w2p_pack(filename, apath(app, request)) + w2p_pack(filename, apath(app, request), filenames=filenames) return filename except Exception, e: if raise_ex: diff --git a/gluon/fileutils.py b/gluon/fileutils.py index b6e6c5d1..293f3e08 100644 --- a/gluon/fileutils.py +++ b/gluon/fileutils.py @@ -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())