forked from jacebrowning/memegen
-
Notifications
You must be signed in to change notification settings - Fork 0
/
manage.py
executable file
·45 lines (30 loc) · 1.05 KB
/
manage.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!env/bin/python
import os
from flask_script import Command, Manager, Server
from memegen.settings import get_config
from memegen.factory import create_app
class Validate(Command):
"""Checks for issues in all templates."""
# pylint: disable=method-hidden
def run(self):
if app.template_service.validate():
return 0
else:
return 1
def find_assets():
"""Yield paths for all static files and templates."""
for name in ['static', 'templates']:
directory = os.path.join(app.config['PATH'], name)
for entry in os.scandir(directory):
if entry.is_file():
yield entry.path
# Select app configuration from the environment
config = get_config(os.getenv('FLASK_CONFIG', 'dev'))
# Build the app using configuration from the environment
app = create_app(config)
# Configure the command-line interface
manager = Manager(app)
manager.add_command('validate', Validate())
manager.add_command('run', Server(extra_files=find_assets()))
if __name__ == '__main__':
manager.run()