-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmanage.py
executable file
·74 lines (63 loc) · 2.25 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
#!flask/bin/python
from app import create_app, db
from flask.ext.script import Manager, Shell, Command, Option
from flask.ext.migrate import Migrate, MigrateCommand
from app.models import User, Role, Album, Directory, Photo, ExifData
import os
if os.path.exists('.env'):
print('Importing environment from .env...')
for line in open('.env'):
var = line.strip().split('=')
if len(var) == 2:
os.environ[var[0]] = var[1]
os.putenv(var[0], var[1])
app = create_app(os.getenv('FLASK_CONFIG') or 'default')
manager = Manager(app)
migrate = Migrate(app, db)
def make_shell_context():
return dict(app=app, db=db, User=User, Role=Role,
Album=Album, Directory=Directory,
Photo=Photo, ExifData=ExifData)
manager.add_command("shell", Shell(make_context=make_shell_context))
manager.add_command('db', MigrateCommand)
@manager.command
def test():
"""Run the unit tests."""
import coverage
cov = coverage.coverage(branch=True, include='app/*')
cov.start()
import unittest
tests = unittest.TestLoader().discover('tests')
unittest.TextTestRunner(verbosity=2).run(tests)
cov.stop()
cov.save()
print('Coverage Summary:')
cov.report()
cov.erase()
def _get_pybabel():
import sys
if sys.platform == 'win32':
pybabel = 'flask\\Scripts\\pybabel'
else:
pybabel = 'flask/bin/pybabel'
return pybabel
BabelCommand = Manager(usage='Perform pybabel related tasks')
@BabelCommand.command
def update(babel_cfg = 'app/babel.cfg', translations_dir = 'app/translations', pot_file='app/translations/messages.pot'):
"""Update catalogs with new texts."""
pybabel = _get_pybabel()
os.system(pybabel + ' extract -F ' + babel_cfg + ' -k lazy_gettext -o ' + pot_file + ' app')
os.system(pybabel + ' update -i ' + pot_file + ' -d ' + translations_dir)
@BabelCommand.command
def compile(translations_dir = 'app/translations'):
"""Compile the catalogs."""
pybabel = _get_pybabel()
os.system(pybabel + ' compile -d ' + translations_dir)
@BabelCommand.command
def init(language, translations_dir = 'app/translations', pot_file='app/translations/messages.pot'):
"""Init new language catalogs."""
pybabel = _get_pybabel()
os.system(pybabel + ' init -i ' + pot_file + ' -d ' + translations_dir + ' -l ' + language)
manager.add_command('babel', BabelCommand)
if __name__ == "__main__":
manager.run()