-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun.py
executable file
·74 lines (61 loc) · 2.59 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
#!/usr/bin/env python
import argparse
import webbrowser
from multiprocessing import Process, Queue
from threading import Thread
import subprocess
from app import create_app
from app.utils.misc import get_os, get_executable
from app.utils.session_key import SessionKey
processes = {}
queue = Queue(5)
def main():
parser = argparse.ArgumentParser(description='DPass - Distributed & Decentralized Password Manager')
parser.add_argument('--develop', action='store_true', help='Run on development config.')
parser.add_argument('--use_ethereum', action='store_true', help='Launch Ethereum (geth)')
args = parser.parse_args()
app, socketio = create_app('development' if args.develop else 'production', queue,
'ethereum' if args.use_ethereum else 'local')
os = get_os()
if os == 'win32':
print('Windows 32-bit is not supported.')
exit(1)
if os.startswith('win'):
server = Thread(target=socketio.run, args=(app,), kwargs={'use_reloader': False}, daemon=True)
else:
server = Process(target=socketio.run, args=(app,), kwargs={'use_reloader': False})
if args.use_ethereum:
processes['geth'] = subprocess.Popen([get_executable('./geth', 'geth'),
'--datadir',
'./ethereum_private/data/',
'--ethash.dagdir',
'./ethereum_private/data/ethash',
'--networkid',
'1042',
'--targetgaslimit',
'4000000'
],
stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL)
init_key = SessionKey.generate_key()
queue.put(init_key)
processes['server'] = server
server.start()
webbrowser.open_new_tab('http://localhost:5000/?key=' + init_key)
def terminate():
if isinstance(processes['server'], Process):
# FIXME: may change to terminate server gently
processes['server'].terminate()
processes['server'].join()
if 'geth' in processes:
processes['geth'].terminate()
queue.close()
if __name__ == '__main__':
try:
main()
while True:
input()
if not queue.empty():
print(queue.get())
except (EOFError, KeyboardInterrupt):
terminate()