-
Notifications
You must be signed in to change notification settings - Fork 0
/
manage.py
87 lines (64 loc) · 2.03 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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# -*- coding: utf-8 -*-
"""Manage Flask application """
import ConfigParser
import os
import shutil
import subprocess
import uuid
import pytest
from flask_script import Manager
from pylint import epylint
from src.app_factory import build_app
manager = Manager(build_app)
@manager.command
def init():
"""Read flask configuration template and write to instance folder """
cwd = os.path.abspath(os.getcwd())
template = os.path.join(cwd, 'config', 'flask.tmp')
path = os.path.join(cwd, 'src', 'instance', 'flask.ini')
config = ConfigParser.RawConfigParser()
# override forcing everything to uppercase
config.optionxform = str
config.read(template)
# create a new secret key for flask app
config.set('flask', 'SECRET_KEY', uuid.uuid4())
with open(path, 'wb') as f:
config.write(f)
@manager.command
def lint():
"""Run pylint """
paths = ['src', 'tests', 'manage.py', 'wsgi.py']
for path in paths:
epylint.py_run('{} -r n'.format(path))
@manager.command
def test():
"""Run pytest """
pytest.main(['tests'])
@manager.command
def build_docs():
"""Build documentation from docstrings in current code """
subprocess.call(['sphinx-apidoc', '-o', 'docs', '.', 'tests'])
@manager.command
def publish_docs():
"""Build documentation html files """
subprocess.call(['sphinx-build', 'docs', 'docs/html'])
@manager.command
def clean():
"""Clean up autogenerated files and folders """
dirty = ['.coverage',
'docs/html/',
'src/instance/flask.ini',
'src/node_modules/',
'src/static/built/',
'src/static/css/local.min.css',
'src/static/js/local.min.js',
'tests/.cache/']
for path in dirty:
if os.path.isdir(path):
shutil.rmtree(path, ignore_errors=True)
elif os.path.isfile(path):
os.remove(path)
# clear all .pyc files
subprocess.call('find . -name "*.pyc" -exec rm -rf {} \;', shell=True)
if __name__ == '__main__':
manager.run()