Browse Source

Don't scan the whole file contents for template detection

pull/262/head
Armin Ronacher 14 years ago
parent
commit
aa863efd92
  1. 20
      scripts/flask-07-upgrade.py

20
scripts/flask-07-upgrade.py

@ -33,6 +33,9 @@ except ImportError:
ast = None ast = None
TEMPLATE_LOOKAHEAD = 4096
_from_import_re = re.compile(r'^\s*from flask import\s+') _from_import_re = re.compile(r'^\s*from flask import\s+')
_string_re_part = r"('([^'\\]*(?:\\.[^'\\]*)*)'" \ _string_re_part = r"('([^'\\]*(?:\\.[^'\\]*)*)'" \
r'|"([^"\\]*(?:\\.[^"\\]*)*)")' r'|"([^"\\]*(?:\\.[^"\\]*)*)")'
@ -50,11 +53,6 @@ _blueprint_related = [
] ]
def error(message):
print >> sys.stderr, 'error:', message
sys.exit(1)
def make_diff(filename, old, new): def make_diff(filename, old, new):
for line in difflib.unified_diff(old.splitlines(), new.splitlines(), for line in difflib.unified_diff(old.splitlines(), new.splitlines(),
posixpath.normpath(posixpath.join('a', filename)), posixpath.normpath(posixpath.join('a', filename)),
@ -253,7 +251,7 @@ def walk_path(path):
yield filename, 'python' yield filename, 'python'
else: else:
with open(filename) as f: with open(filename) as f:
contents = f.read() contents = f.read(TEMPLATE_LOOKAHEAD)
if '{% for' or '{% if' or '{{ url_for' in contents: if '{% for' or '{% if' or '{{ url_for' in contents:
yield filename, 'template' yield filename, 'template'
@ -286,11 +284,6 @@ def autodetect_template_bundles(paths):
def main(): def main():
"""Entrypoint""" """Entrypoint"""
if ast is None:
error('Python 2.6 or later is required to run the upgrade script.\n'
'The runtime requirements for Flask 0.7 however are still '
'Python 2.5.')
parser = OptionParser() parser = OptionParser()
parser.add_option('-T', '--no-teardown-detection', dest='no_teardown', parser.add_option('-T', '--no-teardown-detection', dest='no_teardown',
action='store_true', help='Do not attempt to ' action='store_true', help='Do not attempt to '
@ -307,6 +300,11 @@ def main():
if not args: if not args:
args = ['.'] args = ['.']
if ast is None:
parser.error('Python 2.6 or later is required to run the upgrade script.\n'
'The runtime requirements for Flask 0.7 however are still '
'Python 2.5.')
if options.no_bundled_tmpl: if options.no_bundled_tmpl:
template_bundles = False template_bundles = False
elif options.bundled_tmpl: elif options.bundled_tmpl:

Loading…
Cancel
Save