/
leselys
99 lines (82 loc) · 2.42 KB
/
leselys
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
97
98
99
#!/usr/bin/env python
# coding: utf-8
import sys
import os
import leselys
from docopt import docopt
from leselys import core
from leselys import worker
from leselys import accounts
doc = """Leselys is a Web Interface for Leselys.
Usage:
leselys serve <path> [--host=<address>] [--port=<port>] [--debug]
leselys (adduser|deluser|passwd) <path>
leselys init <path>
leselys worker <path> [--celery-config=<path>]
leselys (refresh|retention) <path>
leselys -h | --help
leselys -v | --version
Options:
--host=<address> Address to bind webserver on [default: 127.0.0.1]
--port=<port> Port to listen for webserver [default: 5000]
--debug Enable Debug mode for Flask [default: false]
-h --help Show help
-v --version Show version
- <path> is configuration file path.
"""
if __name__ == '__main__':
args = docopt(doc, version=leselys.__version__)
config_path = args.get('<path>')
if args.get('init'):
if not os.path.exists(config_path):
with open(args.get('<path>'), 'w') as config:
config_default = """[webserver]
host = 0.0.0.0
port = 5000
debug = false
[storage]
type = mongodb
host = mongodb://localhost:27017
database = leselys
[session]
type = memory
#type = redis
#host = localhost
#port = 6379
#db = 0
[worker]
broker = mongodb://localhost:27017/leselys
# Interval in minutes
interval = 10
# Retention in days
retention = 30"""
config.write(config_default)
print('Configuration file created.')
sys.exit(0)
else:
print('Error: "%s" file already exists.' % config_path)
sys.exit(1)
core.load_config(config_path, args)
core.load_storage()
core.load_session()
if args.get('serve'):
core.run()
if args.get('adduser'):
accounts.add_user(core.storage)
if args.get('deluser'):
accounts.del_user(core.storage)
if args.get('passwd'):
accounts.update_password(core.storage)
if args.get('worker'):
from leselys import worker
args = [arg for arg in sys.argv if arg != config_path]
worker.run(config_path, args)
sys.exit(0)
if args.get('refresh'):
from leselys.helpers import refresh_all
refresh_all()
sys.exit(0)
if args.get('retention'):
from leselys.helpers import run_retention
run_retention(core.config.get('worker', 'retention'))
sys.exit(0)