-
Notifications
You must be signed in to change notification settings - Fork 0
/
manage.py
60 lines (49 loc) · 1.45 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
#-*- coding: utf-8 -*-
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]
from flask_script import Manager, prompt, prompt_bool, prompt_pass
from db_create import (
init_db,
drop_all,
init_admin_user,
init_entry,
init_category,
init_tag
)
from flask_migrate import MigrateCommand
from logpot.app import app
manager = Manager(app)
manager.add_command('db', MigrateCommand)
@manager.command
def run():
app.run(threaded=True)
@manager.command
def initialize():
if prompt_bool("Are you sure you want to initialize all ?"):
admin = init_admin()
if admin:
drop_all(app)
init_db()
init_admin_user(admin["name"], admin["email"], admin["password"])
init_category()
init_tag()
init_entry()
print('Success!')
@manager.command
def init_admin():
name = prompt('Resister admin user.\n[?] input username: ')
email = prompt('[?] input email: ')
password = prompt_pass('[?] input password: ')
confirm_password = prompt_pass('[?] input password again: ')
if password != confirm_password:
print('Password does not match.')
return False
else:
return {"name":name, "email":email, "password":password}
if __name__ == "__main__":
manager.run()