Moved pack as exe functionality to the pack_custom.html form
This commit is contained in:
@@ -367,12 +367,41 @@ def pack_plugin():
|
|||||||
session.flash = T('internal error')
|
session.flash = T('internal error')
|
||||||
redirect(URL('plugin', args=request.args))
|
redirect(URL('plugin', args=request.args))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def pack_exe(app, base, filenames=None):
|
||||||
|
import urllib
|
||||||
|
import zipfile
|
||||||
|
from cStringIO import StringIO
|
||||||
|
# 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 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
|
||||||
|
out.seek(0)
|
||||||
|
return response.stream(out)
|
||||||
|
|
||||||
|
|
||||||
def pack_custom():
|
def pack_custom():
|
||||||
app = get_app()
|
app = get_app()
|
||||||
base = apath(app, r=request)
|
base = apath(app, r=request)
|
||||||
if request.post_vars.file:
|
if request.post_vars.file:
|
||||||
|
|
||||||
files = request.post_vars.file
|
files = request.post_vars.file
|
||||||
files = [files] if not isinstance(files,list) else files
|
files = [files] if not isinstance(files,list) else files
|
||||||
|
if request.post_vars.doexe is None:
|
||||||
fname = 'web2py.app.%s.w2p' % app
|
fname = 'web2py.app.%s.w2p' % app
|
||||||
try:
|
try:
|
||||||
filename = app_pack(app, request, raise_ex=True, filenames=files)
|
filename = app_pack(app, request, raise_ex=True, filenames=files)
|
||||||
@@ -386,6 +415,8 @@ def pack_custom():
|
|||||||
else:
|
else:
|
||||||
session.flash = T('internal error: %s', e)
|
session.flash = T('internal error: %s', e)
|
||||||
redirect(URL(args=request.args))
|
redirect(URL(args=request.args))
|
||||||
|
else:
|
||||||
|
return pack_exe(app, base, files)
|
||||||
def ignore(fs):
|
def ignore(fs):
|
||||||
return [f for f in fs if not (
|
return [f for f in fs if not (
|
||||||
f[:1] in '#' or f.endswith('~') or f.endswith('.bak'))]
|
f[:1] in '#' or f.endswith('~') or f.endswith('.bak'))]
|
||||||
@@ -395,35 +426,6 @@ def pack_custom():
|
|||||||
return locals()
|
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():
|
def upgrade_web2py():
|
||||||
dialog = FORM.confirm(T('Upgrade'),
|
dialog = FORM.confirm(T('Upgrade'),
|
||||||
{T('Cancel'): URL('site')})
|
{T('Cancel'): URL('site')})
|
||||||
|
|||||||
@@ -25,6 +25,7 @@
|
|||||||
<form action="{{=URL(args=request.args)}}" method="POST">
|
<form action="{{=URL(args=request.args)}}" method="POST">
|
||||||
<h2>{{=T('Select Files to Package')}}</h2>
|
<h2>{{=T('Select Files to Package')}}</h2>
|
||||||
<input type="submit" value="{{=T('Download .w2p')}}" class="btn"/>
|
<input type="submit" value="{{=T('Download .w2p')}}" class="btn"/>
|
||||||
|
<input type="submit" name="doexe" value="{{=T('Download as .exe')}}" class="btn"/>
|
||||||
<div style="margin-top:20px">
|
<div style="margin-top:20px">
|
||||||
{{tree(base)}}
|
{{tree(base)}}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -26,7 +26,6 @@
|
|||||||
{{buttons.append((URL('cleanup',args=a), T("Clean")))}}
|
{{buttons.append((URL('cleanup',args=a), T("Clean")))}}
|
||||||
{{buttons.append((URL('pack',args=a), T("Pack all")))}}
|
{{buttons.append((URL('pack',args=a), T("Pack all")))}}
|
||||||
{{buttons.append((URL('pack_custom',args=a), T("Pack custom")))}}
|
{{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):}}
|
{{if not os.path.exists('applications/%s/compiled' % a):}}
|
||||||
{{buttons.append((URL('compile_app',args=a), T("Compile")))}}
|
{{buttons.append((URL('compile_app',args=a), T("Compile")))}}
|
||||||
{{else:}}
|
{{else:}}
|
||||||
|
|||||||
Reference in New Issue
Block a user