manage.find_assets()   A
last analyzed

Complexity

Conditions 4

Size

Total Lines 7
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 6
nop 0
dl 0
loc 7
rs 10
c 0
b 0
f 0
1
#!/usr/bin/env python
2
3
import os
4
5
from flask_script import Command, Manager, Server
6
7
from memegen.settings import get_config
8
from memegen.factory import create_app
9
10
11
class Validate(Command):
12
    """Checks for issues in all templates."""
13
14
    def run(self):  # pylint: disable=method-hidden
15
        if app.template_service.validate():
16
            return 0
17
        else:
18
            return 1
19
20
21
def find_assets():
22
    """Yield paths for all static files and templates."""
23
    for name in ['static', 'templates']:
24
        directory = os.path.join(app.config['PATH'], name)
25
        for entry in os.scandir(directory):
26
            if entry.is_file():
27
                yield entry.path
28
29
30
# Select app configuration from the environment
31
config = get_config(os.getenv('FLASK_ENV', 'local'))
32
33
# Build the app using configuration from the environment
34
app = create_app(config)
35
36
# Configure the command-line interface
37
manager = Manager(app)
38
manager.add_command('validate', Validate())
39
manager.add_command('run', Server(extra_files=find_assets()))
40
41
42
if __name__ == '__main__':
43
    manager.run()
44