forked from elekto-io/elekto
-
Notifications
You must be signed in to change notification settings - Fork 0
/
console
executable file
·96 lines (73 loc) · 3.18 KB
/
console
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
88
89
90
91
92
93
94
95
96
#!/usr/bin/env python
# Copyright 2020 Manish Sahani
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# Author(s): Manish Sahani <[email protected]>
import os
import argparse
from utils import env, generate_app_key
parser = argparse.ArgumentParser(description='Run the k8s.elections app')
parser.add_argument('-p',
'--port',
default=env('APP_PORT', '5000'),
help='Port for the flask application.')
parser.add_argument('--host',
default=env('APP_HOST', '127.0.0.1'),
help='Hostname to listen on. When set to 0.0.0.0 the \
server is available externally. Defaults to 127.0.0.1 \
making the it only visable on localhost')
parser.add_argument('--generate',
help='Generate 32 byte app secret key for session cookie encryption',
action='store_true')
parser.add_argument('--migrate',
help='Create the database tables',
action='store_true')
parser.add_argument('--sync',
action="store_true",
help="sync the database to the meta")
parser.add_argument('--run',
action="store_true",
help="Run the application at the debug mode")
if __name__ == "__main__":
# ###################################################################### #
# /!\ console /!\ #
# ###################################################################### #
args = parser.parse_args()
if args.generate:
print('# ----- Generating 32 byte app secret key ----- #')
generate_app_key()
exit()
if args.migrate:
from config import DATABASE_URL
from elekto.models.sql import migrate
print('# ----- Migrating the database and creating the tables ----- #')
migrate(DATABASE_URL)
exit()
if args.sync:
from config import META, DATABASE_URL
from elekto.models import meta
from elekto.models.sql import create_session
from elekto.models.utils import sync
SESSION = create_session(DATABASE_URL)
backend = meta.Meta(META)
print('# ----------- Syncing the meta with the database ----------- #')
if not os.path.exists(backend.META) or not os.path.isdir(backend.META):
backend.clone()
backend.pull()
print(sync(SESSION, meta.Election.all()))
exit()
if args.run:
from elekto import APP
APP.jinja_env.auto_reload = APP.config.get('DEBUG')
APP.run(debug=APP.config.get('DEBUG'), host=args.host, port=args.port)