app pack custom
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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'),
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
{{extend 'layout.html'}}
|
||||
{{import os}}
|
||||
|
||||
{{def tree(path):}}
|
||||
<input type="checkbox" onclick="jQuery(this).parent().find(':checkbox').attr('checked',this.checked)" checked="checked"/>
|
||||
<a href="#" onclick="jQuery(this).next().slideToggle();return false;">
|
||||
{{=path[len(base):] or '/%s' % app}}
|
||||
</a>
|
||||
<ul class="collapsible">
|
||||
{{for file in files[path]['files']:}}
|
||||
<li style="list-style-type: none;">
|
||||
{{p = os.path.relpath(os.path.join(path,file),base)}}
|
||||
<input type="checkbox" value="{{=p}}" name="file" checked="checked"/>
|
||||
{{=file}}
|
||||
</li>
|
||||
{{pass}}
|
||||
{{for dir in files[path]['folders']:}}
|
||||
<li style="list-style-type: none;">
|
||||
{{tree(os.path.join(path,dir))}}
|
||||
</li>
|
||||
{{pass}}
|
||||
</ul>
|
||||
{{return}}
|
||||
|
||||
<form action="{{=URL(args=request.args)}}" method="POST">
|
||||
<h2>{{=T('Select Files to Package')}}</h2>
|
||||
<input type="submit" value="{{=T('Download .w2p')}}" class="btn"/>
|
||||
<div style="margin-top:20px">
|
||||
{{tree(base)}}
|
||||
</div>
|
||||
</form>
|
||||
<script>jQuery(function(){jQuery('.collapsible').hide();});</script>
|
||||
@@ -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:}}
|
||||
|
||||
+3
-3
@@ -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:
|
||||
|
||||
+6
-5
@@ -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())
|
||||
|
||||
Reference in New Issue
Block a user