skip failed views, thanks Anthony
This commit is contained in:
@@ -484,9 +484,15 @@ def cleanup():
|
|||||||
|
|
||||||
def compile_app():
|
def compile_app():
|
||||||
app = get_app()
|
app = get_app()
|
||||||
c = app_compile(app, request)
|
c = app_compile(app, request,
|
||||||
|
skip_failed_views = (request.args(1) == 'skip_failed_views'))
|
||||||
if not c:
|
if not c:
|
||||||
session.flash = T('application compiled')
|
session.flash = T('application compiled')
|
||||||
|
elif isinstance(c, list):
|
||||||
|
session.flash = DIV(*[T('application compiled'), BR(), BR(),
|
||||||
|
T('WARNING: The following views could not be compiled:'), BR()] +
|
||||||
|
[CAT(BR(), view) for view in c] +
|
||||||
|
[BR(), BR(), T('DO NOT use the "Pack compiled" feature.')])
|
||||||
else:
|
else:
|
||||||
session.flash = DIV(T('Cannot compile: there are errors in your app:'),
|
session.flash = DIV(T('Cannot compile: there are errors in your app:'),
|
||||||
CODE(c))
|
CODE(c))
|
||||||
|
|||||||
@@ -27,7 +27,9 @@
|
|||||||
{{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")))}}
|
||||||
{{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, 'skip_failed_views']),
|
||||||
|
T("Compile (skip failed views)")))}}
|
||||||
|
{{buttons.append((URL('compile_app',args=a), T("Compile (all or nothing)")))}}
|
||||||
{{else:}}
|
{{else:}}
|
||||||
{{buttons.append((URL('pack',args=(a, 'compiled')), T("Pack compiled")))}}
|
{{buttons.append((URL('pack',args=(a, 'compiled')), T("Pack compiled")))}}
|
||||||
{{if glob.glob('applications/%s/controllers/*.py' % a):}}
|
{{if glob.glob('applications/%s/controllers/*.py' % a):}}
|
||||||
|
|||||||
+3
-3
@@ -131,7 +131,7 @@ def app_cleanup(app, request):
|
|||||||
return r
|
return r
|
||||||
|
|
||||||
|
|
||||||
def app_compile(app, request):
|
def app_compile(app, request, skip_failed_views=False):
|
||||||
"""Compiles the application
|
"""Compiles the application
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
@@ -145,8 +145,8 @@ def app_compile(app, request):
|
|||||||
from compileapp import compile_application, remove_compiled_application
|
from compileapp import compile_application, remove_compiled_application
|
||||||
folder = apath(app, request)
|
folder = apath(app, request)
|
||||||
try:
|
try:
|
||||||
compile_application(folder)
|
failed_views = compile_application(folder, skip_failed_views)
|
||||||
return None
|
return failed_views
|
||||||
except (Exception, RestrictedError):
|
except (Exception, RestrictedError):
|
||||||
tb = traceback.format_exc(sys.exc_info)
|
tb = traceback.format_exc(sys.exc_info)
|
||||||
remove_compiled_application(folder)
|
remove_compiled_application(folder)
|
||||||
|
|||||||
+36
-33
@@ -464,22 +464,28 @@ def read_pyc(filename):
|
|||||||
return marshal.loads(data[8:])
|
return marshal.loads(data[8:])
|
||||||
|
|
||||||
|
|
||||||
def compile_views(folder):
|
def compile_views(folder, skip_failed_views=False):
|
||||||
"""
|
"""
|
||||||
Compiles all the views in the application specified by `folder`
|
Compiles all the views in the application specified by `folder`
|
||||||
"""
|
"""
|
||||||
|
|
||||||
path = pjoin(folder, 'views')
|
path = pjoin(folder, 'views')
|
||||||
|
failed_views = []
|
||||||
for fname in listdir(path, '^[\w/\-]+(\.\w+)*$'):
|
for fname in listdir(path, '^[\w/\-]+(\.\w+)*$'):
|
||||||
try:
|
try:
|
||||||
data = parse_template(fname, path)
|
data = parse_template(fname, path)
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
raise Exception("%s in %s" % (e, fname))
|
if skip_failed_views:
|
||||||
filename = 'views.%s.py' % fname.replace(os.path.sep, '.')
|
failed_views.append(file)
|
||||||
filename = pjoin(folder, 'compiled', filename)
|
else:
|
||||||
write_file(filename, data)
|
raise Exception("%s in %s" % (e, file))
|
||||||
save_pyc(filename)
|
else:
|
||||||
os.unlink(filename)
|
filename = ('views/%s.py' % file).replace('/', '_').replace('\\', '_')
|
||||||
|
filename = pjoin(folder, 'compiled', filename)
|
||||||
|
write_file(filename, data)
|
||||||
|
save_pyc(filename)
|
||||||
|
os.unlink(filename)
|
||||||
|
return failed_views if failed_views else None
|
||||||
|
|
||||||
|
|
||||||
def compile_models(folder):
|
def compile_models(folder):
|
||||||
@@ -667,32 +673,28 @@ def run_view_in(environment):
|
|||||||
ccode = parse_template(view, pjoin(folder, 'views'),
|
ccode = parse_template(view, pjoin(folder, 'views'),
|
||||||
context=environment)
|
context=environment)
|
||||||
restricted(ccode, environment, 'file stream')
|
restricted(ccode, environment, 'file stream')
|
||||||
elif os.path.exists(path):
|
|
||||||
x = view.replace('/', '.')
|
|
||||||
files = ['views.%s.pyc' % x]
|
|
||||||
if allow_generic:
|
|
||||||
files.append('views.generic.%s.pyc' % request.extension)
|
|
||||||
# for backward compatibility
|
|
||||||
x = view.replace('/', '_')
|
|
||||||
files.append('views_%s.pyc' % x)
|
|
||||||
if allow_generic:
|
|
||||||
files.append('views_generic.%s.pyc' % request.extension)
|
|
||||||
if request.extension == 'html':
|
|
||||||
files.append('views_%s.pyc' % x[:-5])
|
|
||||||
if allow_generic:
|
|
||||||
files.append('views_generic.pyc')
|
|
||||||
# end backward compatibility code
|
|
||||||
for f in files:
|
|
||||||
filename = pjoin(path, f)
|
|
||||||
if os.path.exists(filename):
|
|
||||||
code = read_pyc(filename)
|
|
||||||
restricted(code, environment, layer=filename)
|
|
||||||
return
|
|
||||||
raise HTTP(404,
|
|
||||||
rewrite.THREAD_LOCAL.routes.error_message % badv,
|
|
||||||
web2py_error=badv)
|
|
||||||
else:
|
else:
|
||||||
filename = pjoin(folder, 'views', view)
|
filename = pjoin(folder, 'views', view)
|
||||||
|
if os.path.exists(path): # compiled views
|
||||||
|
x = view.replace('/', '_')
|
||||||
|
files = ['views_%s.pyc' % x]
|
||||||
|
is_compiled = os.path.exists(pjoin(path, files[0]))
|
||||||
|
# Don't use a generic view if the non-compiled view exists.
|
||||||
|
if is_compiled or (not is_compiled and not os.path.exists(filename)):
|
||||||
|
if allow_generic:
|
||||||
|
files.append('views_generic.%s.pyc' % request.extension)
|
||||||
|
# for backward compatibility
|
||||||
|
if request.extension == 'html':
|
||||||
|
files.append('views_%s.pyc' % x[:-5])
|
||||||
|
if allow_generic:
|
||||||
|
files.append('views_generic.pyc')
|
||||||
|
# end backward compatibility code
|
||||||
|
for f in files:
|
||||||
|
compiled = pjoin(path, f)
|
||||||
|
if os.path.exists(compiled):
|
||||||
|
code = read_pyc(compiled)
|
||||||
|
restricted(code, environment, layer=compiled)
|
||||||
|
return
|
||||||
if not os.path.exists(filename) and allow_generic:
|
if not os.path.exists(filename) and allow_generic:
|
||||||
view = 'generic.' + request.extension
|
view = 'generic.' + request.extension
|
||||||
filename = pjoin(folder, 'views', view)
|
filename = pjoin(folder, 'views', view)
|
||||||
@@ -726,7 +728,7 @@ def remove_compiled_application(folder):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
def compile_application(folder):
|
def compile_application(folder, skip_failed_views=False):
|
||||||
"""
|
"""
|
||||||
Compiles all models, views, controller for the application in `folder`.
|
Compiles all models, views, controller for the application in `folder`.
|
||||||
"""
|
"""
|
||||||
@@ -734,7 +736,8 @@ def compile_application(folder):
|
|||||||
os.mkdir(pjoin(folder, 'compiled'))
|
os.mkdir(pjoin(folder, 'compiled'))
|
||||||
compile_models(folder)
|
compile_models(folder)
|
||||||
compile_controllers(folder)
|
compile_controllers(folder)
|
||||||
compile_views(folder)
|
failed_views = compile_views(folder, skip_failed_views)
|
||||||
|
return failed_views
|
||||||
|
|
||||||
|
|
||||||
def test():
|
def test():
|
||||||
|
|||||||
Reference in New Issue
Block a user