forked from kobotoolbox/kobo-install
-
Notifications
You must be signed in to change notification settings - Fork 0
/
run.py
executable file
·111 lines (99 loc) · 4.24 KB
/
run.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
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
100
101
102
103
104
105
106
107
108
109
110
111
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import platform
import sys
from helpers.cli import CLI
if sys.version_info[0] == 2:
message = (
'Python 2.7 has reached the end of its life on '
'January 1st, 2020. Please upgrade your Python as Python 2.7 is '
'not maintained anymore.'
)
CLI.framed_print(message, color=CLI.COLOR_ERROR)
sys.exit(1)
from helpers.command import Command
from helpers.config import Config
from helpers.setup import Setup
from helpers.template import Template
from helpers.updater import Updater
from helpers.upgrading import Upgrading
def run(force_setup=False):
if not platform.system() in ['Linux', 'Darwin']:
CLI.colored_print('Not compatible with this OS', CLI.COLOR_ERROR)
else:
config = Config()
dict_ = config.get_dict()
if config.first_time:
force_setup = True
if force_setup:
dict_ = config.build()
Setup.clone_kobodocker(config)
Template.render(config)
Setup.update_hosts(dict_)
else:
if config.auto_detect_network():
Template.render(config)
Setup.update_hosts(dict_)
config.validate_passwords()
Command.start(force_setup=force_setup)
if __name__ == '__main__':
try:
# avoid infinite self-updating loops
update_self = Updater.NO_UPDATE_SELF_OPTION not in sys.argv
while True:
try:
sys.argv.remove(Updater.NO_UPDATE_SELF_OPTION)
except ValueError:
break
if len(sys.argv) > 2:
if sys.argv[1] == '-cf' or sys.argv[1] == '--compose-frontend':
Command.compose_frontend(sys.argv[2:])
elif sys.argv[1] == '-cb' or sys.argv[1] == '--compose-backend':
Command.compose_backend(sys.argv[2:])
elif sys.argv[1] == '-u' or sys.argv[1] == '--update':
Updater.run(sys.argv[2], update_self=update_self)
elif sys.argv[1] == '--upgrade':
Updater.run(sys.argv[2], update_self=update_self)
elif sys.argv[1] == '--auto-update':
Updater.run(sys.argv[2], cron=True, update_self=update_self)
else:
CLI.colored_print("Bad syntax. Try 'run.py --help'",
CLI.COLOR_ERROR)
elif len(sys.argv) == 2:
if sys.argv[1] == '-h' or sys.argv[1] == '--help':
Command.help()
elif sys.argv[1] == '-u' or sys.argv[1] == '--update':
Updater.run(update_self=update_self)
elif sys.argv[1] == '--upgrade':
# 'update' was called 'upgrade' in a previous release; accept
# either 'update' or 'upgrade' here to ease the transition
Updater.run(update_self=update_self)
elif sys.argv[1] == '--auto-update':
Updater.run(cron=True, update_self=update_self)
elif sys.argv[1] == '-i' or sys.argv[1] == '--info':
Command.info(0)
elif sys.argv[1] == '-s' or sys.argv[1] == '--setup':
run(force_setup=True)
elif sys.argv[1] == '-S' or sys.argv[1] == '--stop':
Command.stop()
elif sys.argv[1] == '-l' or sys.argv[1] == '--logs':
Command.logs()
elif sys.argv[1] == '-b' or sys.argv[1] == '--build':
Command.build()
elif sys.argv[1] == '-bkf' or sys.argv[1] == '--build-kpi':
Command.build('kf')
elif sys.argv[1] == '-bkc' or sys.argv[1] == '--build-kobocat':
Command.build('kc')
elif sys.argv[1] == '-v' or sys.argv[1] == '--version':
Command.version()
elif sys.argv[1] == '-m' or sys.argv[1] == '--maintenance':
Command.configure_maintenance()
elif sys.argv[1] == '-sm' or sys.argv[1] == '--stop-maintenance':
Command.stop_maintenance()
else:
CLI.colored_print("Bad syntax. Try 'run.py --help'",
CLI.COLOR_ERROR)
else:
run()
except KeyboardInterrupt:
CLI.colored_print('\nUser interrupted execution', CLI.COLOR_INFO)