From 032af7c04d5bcb67c4dfd01302480269c0b51dee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leonel=20C=C3=A2mara?= Date: Tue, 30 Jun 2015 19:19:38 +0100 Subject: [PATCH] Moved pack as exe functionality to the pack_custom.html form --- applications/admin/controllers/default.py | 72 ++++++++++--------- .../admin/views/default/pack_custom.html | 1 + applications/admin/views/default/site.html | 1 - 3 files changed, 38 insertions(+), 36 deletions(-) diff --git a/applications/admin/controllers/default.py b/applications/admin/controllers/default.py index ad7ca31c..3e615c1e 100644 --- a/applications/admin/controllers/default.py +++ b/applications/admin/controllers/default.py @@ -367,40 +367,12 @@ 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 pack_exe(): +def pack_exe(app, base, filenames=None): import urllib import zipfile from cStringIO import StringIO - app = get_app() - base = apath(app, r=request) # Download latest web2py_win and open it with zipfile download_url = 'http://www.web2py.com/examples/static/web2py_win.zip' out = StringIO() @@ -411,12 +383,10 @@ def pack_exe(): web2py_win.writestr('web2py/routes.py', routes.encode('utf-8')) # Copy the application into the zipfile common_root = os.path.dirname(base) - for root, dirs, files in os.walk(base, topdown=True): - dirs[:] = [d for d in dirs if d not in ['cache', 'sessions', 'errors']] - for filename in files: - fname = os.path.join(root, filename) - arcname = os.path.join('web2py/applications', os.path.relpath(root, common_root), filename) - web2py_win.write(fname, arcname) + for filename in filenames: + fname = os.path.join(base, filename) + arcname = os.path.join('web2py/applications', app, filename) + web2py_win.write(fname, arcname) web2py_win.close() response.headers['Content-Type'] = 'application/zip' response.headers['Content-Disposition'] = 'attachment; filename=web2py.app.%s.zip' % app @@ -424,6 +394,38 @@ def pack_exe(): return response.stream(out) +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 + if request.post_vars.doexe is None: + 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)) + else: + return pack_exe(app, base, files) + 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'), {T('Cancel'): URL('site')}) diff --git a/applications/admin/views/default/pack_custom.html b/applications/admin/views/default/pack_custom.html index 50411df1..01481deb 100644 --- a/applications/admin/views/default/pack_custom.html +++ b/applications/admin/views/default/pack_custom.html @@ -25,6 +25,7 @@

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

+
{{tree(base)}}
diff --git a/applications/admin/views/default/site.html b/applications/admin/views/default/site.html index 0ba52fde..d11e14db 100644 --- a/applications/admin/views/default/site.html +++ b/applications/admin/views/default/site.html @@ -26,7 +26,6 @@ {{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")))}} - {{buttons.append((URL('pack_exe',args=a), T("Download as exe")))}} {{if not os.path.exists('applications/%s/compiled' % a):}} {{buttons.append((URL('compile_app',args=a), T("Compile")))}} {{else:}}