/
init_client.py
executable file
·74 lines (63 loc) · 2.31 KB
/
init_client.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
#!/usr/bin/env python
import sys
import os
from os import path
from os.path import exists
from centinel.client import ServerConnection
from centinel.client_config import client_conf
from utils.colors import bcolors
c = client_conf()
print bcolors.OKBLUE + 'Initializing the client.' + bcolors.ENDC
def check_create_dir(path):
if not os.path.exists(path):
print "Creating directory in %s" % (path)
os.makedirs(path)
check_create_dir(c.c['centinel_home_dir'])
check_create_dir(c.c['keys_dir'])
check_create_dir(c.c['confs_dir'])
check_create_dir(c.c['results_dir'])
check_create_dir(c.c['results_archive_dir'])
check_create_dir(c.c['logs_dir'])
check_create_dir(c.c['remote_experiments_dir'])
check_create_dir(c.c['custom_experiments_dir'])
check_create_dir(c.c['experiment_data_dir'])
check_create_dir(c.c['custom_experiment_data_dir'])
if len(sys.argv) > 1 and sys.argv[1] == "--offline":
exit(0)
if c.config_read:
print bcolors.FAIL + 'A configuration file already exists for %s, are you sure you want to initialize? (if so, type \'yes\') ' %(c.c['client_tag']) + bcolors.ENDC
ans = raw_input()
if ans.lower() <> "yes":
print bcolors.OKBLUE + 'Nothing changed, exiting.' + bcolors.ENDC
exit(0)
ans = raw_input("Do you want to keep experiment results after sending them to the server?")
if ans.lower() == "yes" or ans.lower() == "y" or ans.lower() == "Y":
c.set("archive_sent_results", "1")
else:
print "Experiment results will not be archived, you can change this by editing the configuration file at \"" + c["config_file"] + "\""
c.update()
retry = True
done = True
while retry:
try:
print bcolors.OKBLUE + 'Connecting to server...' + bcolors.ENDC
serverconn = ServerConnection()
if not serverconn.connect(do_login = False):
raise Exception("Could not connect.")
serverconn.initialize_client()
done = True
retry = False
except Exception as e:
done = False
print bcolors.FAIL + "Error initializing: " + str(e) + bcolors.ENDC
print bcolors.OKBLUE + "Want to retry? " + bcolors.ENDC
ans = raw_input()
if ans.lower() == "yes" or ans.lower() == "y" or ans.lower() == "Y":
print bcolors.OKBLUE + 'Retrying...' + bcolors.ENDC
retry = True
else:
retry = False
serverconn.disconnect()
if not done:
print bcolors.FAIL + "Client not initialized!" + bcolors.ENDC
exit(1)