forked from pdonorio/rest-mock
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmanage.py
executable file
·56 lines (39 loc) · 1.3 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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
RESTful API Python 3 Flask server
"""
import sys
import click
import better_exceptions as be
from flask.cli import FlaskGroup
from rapydo.server import create_app
from rapydo.utils.logs import get_logger
log = get_logger(__name__)
#############################
# Management with click
def init_services(info):
# print("INFO?", info)
return create_app(name='Initializing Flask services', init_mode=True)
def destory_services_data(info):
return create_app(name='Removing data from services', destroy_mode=True)
@click.group(cls=FlaskGroup, create_app=init_services)
def init():
"""This is a management script for the wiki application."""
log.debug("Custom command group: %s" % be.__class__)
@click.group(cls=FlaskGroup, create_app=destory_services_data)
def destroy():
"""This is a management script for the wiki application."""
log.debug("Custom command group: %s" % be.__class__)
if __name__ == '__main__':
# http://flask.pocoo.org/docs/0.12/cli/
if len(sys.argv) > 1:
command = sys.argv[1]
if command == 'init':
init()
elif command == 'destroy':
destroy()
else:
log.warning("Unknown command: '%s'" % command)
else:
log.warning("No command available")