-
Notifications
You must be signed in to change notification settings - Fork 0
/
manage.py
executable file
·163 lines (118 loc) · 4.73 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
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
#!../bin/python
# Core import
import sys
import random
from json import dumps
from config.settings import CREDENTIALS
cred = random.choice(CREDENTIALS)
get_token = cred[0] + ':' + cred[1]
usage = """
Options:\n\n[General options]:\n\n\n
help Show this usage information.
for func help please send second arg
as a method name.
e.g:
./manage.py help main.stop
version Show version information
runserver Start your server (For custom port, please
see settings file.)
shutdown Shutdown your server
[0
start_component Create your component. send your
component name as second argument.
e.g: python manage.py start_component test
logs Show all logs(error, jobs, debug, object,
service, request)
plugin Show All components with their plugins.
memory Access to all data of the shared memory.
Just pass your key to memory option.
e.g: python manage.py memory local_airports
generate_settings Generate your settings_local from scratch.
e.g: python manage.py generate_settings
"""
def main():
if len(sys.argv) > 1:
if sys.argv[1] == 'runserver':
from runner import initRPC
# Start server from here
initRPC()
elif sys.argv[1] == 'start_component':
from core.manager.execute_start_component import start_component
# Create component
start_component(sys.argv[2])
elif sys.argv[1] == 'shutdown':
from jsonrpclib import Server
from socket import error
from config.settings import CORE_PORT
try:
conn = Server(
'http://{0}@localhost:{1}'.format(get_token, CORE_PORT)
)
conn.main.stop()
except error:
print 'Core Services shutdown \t\t\t\t\t\t[OK]'
elif sys.argv[1] == 'logs':
from os import system
from config.settings import CORE_ID
system('tail -f /var/log/core/{0}/*'.format(CORE_ID))
elif sys.argv[1] == 'memory':
from jsonrpclib import Server
from socket import error
from config.settings import CORE_PORT
try:
key = sys.argv[2]
conn = Server(
'http://{0}@localhost:{1}'.format(get_token, CORE_PORT)
)
data = conn.main.access_shared_memory(key)
pretty(data)
except error:
print 'Core Services shutdown \t\t\t\t\t\t[OK]'
elif sys.argv[1] == 'generate_settings':
from shutil import copyfile
from config.settings import BASE_DIR
raw = BASE_DIR + '/config/settings_local.txt'
gen = BASE_DIR + '/config/settings_local.py'
copyfile(raw, gen)
elif sys.argv[1] == 'plugin':
from jsonrpclib import Server
from socket import error
from config.settings import CORE_PORT
try:
conn = Server(
'http://{0}@localhost:{1}'.format(get_token, CORE_PORT)
)
data = conn.listMethods()
pretty(dumps(data))
except error:
print 'Core Services shutdown \t\t\t\t\t\t[OK]'
elif sys.argv[1] == 'help':
if len(sys.argv) == 3:
from os import system
from jsonrpclib import Server
from socket import error
from config.settings import CORE_PORT
try:
conn = Server(
'http://{0}@localhost:{1}'.format(
get_token,
CORE_PORT
)
)
data = conn.methodHelp(sys.argv[2])
system('echo {}'.format(data))
except error:
print 'Core Services shutdown \t\t\t\t\t\t[OK]'
elif len(sys.argv) == 2:
print usage
def pretty(data):
from os import system
try:
import pjson
except ImportError:
print "Please install pjson module. \t( sudo pip install pjson )"
return
system("""echo '{0}' | pjson""".format(data))
if __name__ == "__main__":
# execute only if run as a script
main()