-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathmanage.py
55 lines (46 loc) · 1.41 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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from flaskext.script import Command, Manager, Shell
from rta import api
from web import app
manager = Manager(app)
class SyncDB(Command):
"""
Initializes the database tables.
"""
def run(self):
db = api.Model.db()
db.reset()
class FixedShell(Shell):
"""
Runs a Python shell inside Flask application context.
"""
def run(self, no_ipython):
context = self.get_context()
if not no_ipython:
try:
from IPython.frontend.terminal.embed import InteractiveShellEmbed
sh = InteractiveShellEmbed(banner1=self.banner)
sh(global_ns=dict(), local_ns=context)
return
except ImportError:
pass
from code import interact
interact(banner=self.banner, local=context)
class Test(Command):
"""
Runs the application's unit tests.
"""
def run(self):
import os
from unittest import TestLoader, TextTestRunner
cur_dir = os.path.dirname(os.path.abspath(__file__))
loader = TestLoader()
test_suite = loader.discover(cur_dir)
runner = TextTestRunner(verbosity=2)
runner.run(test_suite)
del manager._commands['shell']
manager.add_command('shell', FixedShell())
manager.add_command('syncdb', SyncDB())
manager.add_command('test', Test())
manager.run()