-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.py
83 lines (62 loc) · 1.9 KB
/
install.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
from sys import argv, exit
import os, json, logging
def install_dropbox():
config = {}
config_path = os.path.join(os.path.expanduser('~'), "dlxdd_config.json")
try:
with open(config_path, 'rb') as C:
config.update(json.loads(C.read()))
except Exception as e:
logging.warn("Config is not good: [%s, %s]" % (type(e), e))
from dropbox_api import init_dropbox
return init_dropbox(config)
def setup_slack():
config = {}
config_path = os.path.join(os.path.expanduser('~'), "dlxdd_config.json")
try:
with open(config_path, 'rb') as C:
config.update(json.loads(C.read()))
except Exception as e:
logging.warn("Config is not good: [%s, %s]" % (type(e), e))
from slack_api import init_slack
return init_slack(config)
def setup_xmpp():
from fabric.operations import prompt
config = {}
config_path = os.path.join(os.path.expanduser('~'), "dlxdd_config.json")
try:
with open(config_path, 'rb') as C:
config.update(json.loads(C.read()))
except Exception as e:
logging.warn("Config is not good: [%s, %s]" % (type(e), e))
if 'xmpp' not in config.keys():
config['xmpp'] = {}
for cred in ['jid', 'pwd', 'bot_jid']:
if cred not in config['xmpp'].keys():
config['xmpp'][cred] = prompt("What is %s for XMPP? " % cred)
with open(config_path, 'wb+') as C:
C.write(json.dumps(config))
return True
def make_dirs():
tmp_dir = os.path.join(os.path.expanduser('~'), "dlxdd_tmp")
try:
if not os.path.exists(tmp_dir):
os.mkdir(tmp_dir)
return True
except Exception as e:
logging.error("Could not make temp directory")
return False
if __name__ == "__main__":
res = False
if len(argv) == 1:
res = install_dropbox() and setup_slack() and make_dirs() and setup_xmpp()
else:
if argv[1] == "dropbox":
res = install_dropbox()
if argv[1] == "slack":
res = setup_slack()
if argv[1] == "dirs":
res = make_dirs()
if argv[1] == "xmpp":
res = setup_xmpp()
exit(0 if res else -1)