-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathptr_config.py
91 lines (71 loc) · 2.54 KB
/
ptr_config.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
84
85
86
87
88
89
90
91
# -*- coding: utf-8 -*-
"""
Created on Fri Aug 2 11:57:41 2019
Updated 20220904 22:42WER
@authors: wrosing, mfitz
"""
import os
import pathlib
import sys
import socket
import glob
# This routine here removes all mention of previous configs from the path...
# for safety and local computer got clogged with all manner of configs in the path
path_removals = []
for q in range(len(sys.path)):
if "ptr-wema" in sys.path[q] and "configs" in sys.path[q]:
print("Removing old config path: " + str(sys.path[q]))
path_removals.append(sys.path[q])
for remover in path_removals:
sys.path.remove(remover)
pathdone = 0
# First try to get the wemaname from a file in the directory above (..) ptr-observatory
cwd = str(pathlib.Path().resolve())
hwd = cwd.replace("ptr-wema", "")
wemaname_file = glob.glob(hwd + "wemaname*")
try:
#breakpoint()
site_name = wemaname_file[0].split("wemaname")[1].split('.')[0]
# print(
# "Adding new config path: "
# + str(os.path.join(pathlib.Path().resolve(), "configs", site_name))
# )
sys.path.append(os.path.join(pathlib.Path().resolve(), "configs", site_name))
pathdone = 1
except OSError:
print(
"Could not find a wemaname* file in the directory above ptr-observatory \
(e.g. wemanamesro).\n Trying another method..."
)
if pathdone == 0:
print("Attempting wemaname approach to config file...")
# NB May be better to split on '-' and use first part of wemaname.
host_site = socket.gethostname()[:3].lower()
#if host_site == "saf":
# host_site == "aro" # NB NB THIS is a blatant hack. TODO Remove this
# print(
# "Adding new config path: "
# + str(os.path.join(pathlib.Path().resolve(), "configs", host_site))
# )
sys.path.append(os.path.join(pathlib.Path().resolve(), "configs", host_site))
try:
from wema_config import *
except ImportError:
print(
"Failed the wemaname approach to config file.\n"
+ str(host_site)
+ " isn't a real place, or there isn't a config file \
that I can find!"
)
try:
site_name = input("What site am I running at?\n")
sys.path.append(os.path.join(pathlib.Path().resolve(), "configs", site_name))
from site_config import *
except ImportError:
print(
str(site_name)
+ " isn't a real place, or there isn't a config file \
that I can find! Make sure you supplied \
a correct site name. Exiting."
)
sys.exit()