Browse Source

Add command to clean all the python compile file

The added command `flask clean` can be used to remove all the `.pyc` and `.pyo` file recursively starting at the path to the root of the application. Similar to Flask-Script's `clean` command.
pull/2439/head
Grey Li 8 years ago committed by GitHub
parent
commit
d78328bf8f
  1. 22
      flask/cli.py

22
flask/cli.py

@ -697,6 +697,28 @@ def routes_command(sort, all_methods):
click.echo(row.format(rule.endpoint, methods, rule.rule).rstrip())
@click.command('clean', short_help='Clean python compile file.')
@with_appcontext
def clean_command():
"""Clean all the .pyc and .pyo files recursively starting at
the path to the root of the application.
"""
from flask.globals import _app_ctx_stack
app = _app_ctx_stack.top.app
root_path = app.root_path
if not root_path:
return click.echo('The path to the root of the application was not found, '
'please define it through app.root_path manually.')
for dirpath, dirnames, filenames in os.walk(app.root_path):
for filename in filenames:
if filename.endswith('.pyc') or filename.endswith('.pyo'):
full_pathname = os.path.join(dirpath, filename)
click.echo('Removing %s' % full_pathname)
os.remove(full_pathname)
cli = FlaskGroup(help="""\
This shell command acts as general utility script for Flask applications.

Loading…
Cancel
Save