-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathapp.py
More file actions
63 lines (44 loc) · 1.86 KB
/
app.py
File metadata and controls
63 lines (44 loc) · 1.86 KB
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
import threading
from dotenv import load_dotenv
from app import create_app, db
import argparse
from flask import render_template, request, Response
import json
import os
from app.features.rule.rule_format.utils_format.utils_import_update import delete_existing_repo_folder
from app.core.utils.init_db import create_admin, create_default_user, insert_default_formats, show_admin_first_connection
parser = argparse.ArgumentParser()
parser.add_argument("-i", "--init_db", help="Initialise the db if it not exist", action="store_true")
parser.add_argument("-r", "--recreate_db", help="Delete and initialise the db", action="store_true")
parser.add_argument("-d", "--delete_db", help="Delete the db", action="store_true")
args = parser.parse_args()
os.environ.setdefault('FLASKENV', 'development')
load_dotenv()
app = create_app()
@app.errorhandler(404)
def error_page_not_found(e):
if request.path.startswith('/api/'):
return Response(json.dumps({"status": "error", "reason": "404 Not Found"}, indent=2, sort_keys=True), mimetype='application/json'), 404
return render_template('404.html'), 404
if args.init_db:
with app.app_context():
db.create_all()
admin, raw_password = create_admin()
editor = create_default_user()
insert_default_formats()
show_admin_first_connection(admin , raw_password)
elif args.recreate_db:
with app.app_context():
db.drop_all()
db.create_all()
delete_existing_repo_folder("Rules_Github")
admin , raw_password = create_admin()
insert_default_formats()
show_admin_first_connection(admin , raw_password)
editor = create_default_user()
elif args.delete_db:
with app.app_context():
db.drop_all()
print("DB delete with success")
else:
app.run(host=app.config.get("FLASK_URL"), port=app.config.get("FLASK_PORT"))