From 5d2e5dded3cf05e38b38a42b9800372b4e2ee3c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leonel=20C=C3=A2mara?= Date: Tue, 30 Jun 2015 17:51:39 +0100 Subject: [PATCH] Allow packing an application with the windows executable --- applications/admin/controllers/default.py | 29 ++++++++++++++++++++++ applications/admin/views/default/site.html | 1 + 2 files changed, 30 insertions(+) diff --git a/applications/admin/controllers/default.py b/applications/admin/controllers/default.py index 96b0e2ef..ad7ca31c 100644 --- a/applications/admin/controllers/default.py +++ b/applications/admin/controllers/default.py @@ -395,6 +395,35 @@ def pack_custom(): return locals() +def pack_exe(): + 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() + out.write(urllib.urlopen(download_url).read()) + web2py_win = zipfile.ZipFile(out, mode='a') + # Write routes.py with the application as default + routes = u'# -*- coding: utf-8 -*-\nrouters = dict(BASE=dict(default_application="%s"))' % app + 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) + web2py_win.close() + response.headers['Content-Type'] = 'application/zip' + response.headers['Content-Disposition'] = 'attachment; filename=web2py.app.%s.zip' % app + out.seek(0) + return response.stream(out) + + def upgrade_web2py(): dialog = FORM.confirm(T('Upgrade'), {T('Cancel'): URL('site')}) diff --git a/applications/admin/views/default/site.html b/applications/admin/views/default/site.html index d11e14db..0ba52fde 100644 --- a/applications/admin/views/default/site.html +++ b/applications/admin/views/default/site.html @@ -26,6 +26,7 @@ {{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:}}