-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathptr_config.py
72 lines (59 loc) · 2.1 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
# -*- 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-observatory" 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 hostname from a file in the directory above (..) ptr-observatory
cwd = str(pathlib.Path().resolve())
hwd = cwd.replace("ptr-observatory", "")
hostname_file = glob.glob(hwd + "hostname*")
try:
site_name = hostname_file[0].replace('.txt','').split("hostname")[1]
sys.path.append(os.path.join(pathlib.Path().resolve(), "configs", site_name))
pathdone = 1
except OSError:
print(
"Could not find a hostname* file in the directory above ptr-observatory \
(e.g. hostnamesro).\n Trying another method..."
)
if pathdone == 0:
print("Attempting hostname approach to config file...")
host_site = socket.gethostname()[:3].lower()
sys.path.append(os.path.join(pathlib.Path().resolve(), "configs", host_site))
try:
from obs_config import *
except ImportError:
print(
"Failed the hostname 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()