-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconfigure.py
74 lines (66 loc) · 2.58 KB
/
configure.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
import os
import sys
import argparse
import subprocess
parser = argparse.ArgumentParser(
description='Configuration of KAMIStudio')
parser.add_argument(
'-u', '--uploads', dest="uploads",
default=os.getcwd(),
help='path to uploads folder ' +
'(default: current working directory)')
parser.add_argument(
'-c', '--configs', dest="configs",
default=os.getcwd(),
help='path to configuration file \'kamistudio.conf\' ' +
'(default: current working directory with default configs)')
parser.add_argument(
'-s', '--session',
dest='session',
default=os.getcwd(),
help='path to sessions folder' +
'(default: current working directory)')
def configure(argdict):
# Create uploads folder
if "uploads" in argdict.keys():
uploads = argdict["uploads"]
else:
uploads = parser.get_default('-u')
if not os.path.isdir(os.path.join(uploads, "uploads")):
subprocess.run(["mkdir", os.path.join(uploads, "uploads")])
print("Set uploads folder to '{}'".format(os.path.join(uploads, "uploads")))
# Create session files folder
if "session" in argdict.keys():
session = argdict["session"]
else:
session = parser.get_default('-s')
if not os.path.isdir(os.path.join(session, "flask_session")):
subprocess.run(["mkdir", os.path.join(session, "flask_session")])
print("Set session folder to '{}'".format(os.path.join(session, "flask_session")))
# Create configuration file
if "configs" in argdict.keys():
configs = argdict["configs"]
else:
configs = parser.get_default('-c')
file = os.path.join(configs, "kamistudio.conf")
print("Writing the following configs to '{}'...".format(file))
with open(file, "w+") as f:
confs = [
"NEO4J_URI = 'bolt://localhost:7687'",
"NEO4J_USER = 'neo4j'",
"NEO4J_PWD = 'admin'",
"MONGO_URI = 'mongodb://localhost:27017'",
"SECRET_KEY = {}".format(os.urandom(24)),
"UPLOAD_FOLDER = '{}'".format(os.path.join(uploads, "uploads")),
"SESSION_FILE_DIR = '{}'".format(os.path.join(session, "flask_session")),
"READ_ONLY = False"
]
for c in confs:
f.write(c + "\n")
print("\t" + c)
print("WARNING: to not forget to set environment variable KAMISTUDIO_SETTINGS to '{}'".format(file))
print("Example: export KAMISTUDIO_SETTINGS='{}'".format(file))
os.environ["KAMISTUDIO_SETTINGS"] = file
if __name__ == '__main__':
argdict = vars(parser.parse_args(sys.argv[1:]))
configure(argdict)