forked from datature/portal
-
Notifications
You must be signed in to change notification settings - Fork 0
/
portal.py
53 lines (43 loc) · 1.64 KB
/
portal.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
import os
import sys
# If false means run locally
arguments = sys.argv
root = os.path.join(os.path.abspath(os.curdir), "portal_build")
cache_folder = os.path.join(root, "server/cache")
model_folder = os.path.join(root, "server/hub_models")
variables_folder = os.path.join(root, "server/var")
# If these folders do not exist (perhaps first time using the program),
# create the folders.
for folder in [cache_folder, model_folder, variables_folder]:
if not os.path.isdir(folder):
os.makedirs(folder)
use_gpu_dir = os.path.join(variables_folder, "gpu.var")
cache_dir = os.path.join(cache_folder, "store.portalCache")
use_cache_dir = os.path.join(variables_folder, "cache.var")
gpu_dir = os.path.join(root, "server/cache/use_gpu")
if os.path.exists(root):
os.environ["ROOT_DIR"] = root
os.environ["COMMAND_LINE"] = "0"
if "--electron" in arguments:
os.environ["IS_ELECTRON"] = "0"
if "--gpu" in arguments:
os.environ["IS_GPU"] = "0"
with open(use_gpu_dir, "w+") as gpu_flag:
gpu_flag.write("0")
else:
with open(use_gpu_dir, "w+") as gpu_flag:
gpu_flag.write("-1")
use_cache = "0"
if os.path.isfile(use_cache_dir):
with open(use_cache_dir, "r") as cache_flag:
use_cache = cache_flag.read()
else:
with open(use_cache_dir, "w") as cache_flag:
cache_flag.write(use_cache)
if os.getenv("IS_ELECTRON"):
os.system("npm run portal_build")
else:
from portal_build.run import initialize # pylint: disable=import-error
initialize()
else:
raise FileNotFoundError("Portal not installed or installation failed.")