-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsetup.py
63 lines (55 loc) · 2.23 KB
/
setup.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
#!/usr/bin/env python3
import getpass
import pathlib
import subprocess
import netcfg.config as cfg
# Install needed packages
subprocess.run("pip3 install paramiko", shell=True)
subprocess.run("pip3 install bs4", shell=True)
# Check if config file exists, or config-sample exists
file_path = ""
while not file_path:
file_path = input(
"Please enter a path to use as the configuration file's basis or press enter to continue:\n"
).strip()
if not file_path:
print("Using default file paths. Looking for old configuration files...")
file_path = pathlib.Path("./config")
if not file_path.exists() or not file_path.is_file():
print("No old file located. Searching for sample configuration file...")
file_path = pathlib.Path("./config-sample")
if not file_path.exists() or not file_path.is_file():
print("Unable to locate any old files. Restarting from scratch.")
file_path = pathlib.Path("./config")
file_path.touch()
file_path.write_text("Hello world, will be overwritten soon by configuration details (hopefully).")
else:
print("Using default sample file as basis.")
else:
print("Using old configuration file as basis.")
else:
print("Using following path:", file_path)
file_path = pathlib.Path(file_path)
if not file_path.exists() or not file_path.is_file():
file_path = ""
# Now has a valid end goal
cfg.Config(cfg_file=file_path, delay_login=True)
data = {}
for subject, text, secure in cfg.Config.REQ_ELEM:
value = ""
if not secure:
value = input(
"Current data stored for {} is {}.\nThis is{} please enter a value:".format(
subject, cfg.Config.ENV_VARS[subject], text
)
).strip()
else:
value = getpass.getpass()
if value:
data[subject] = value
else:
data[subject] = cfg.Config.ENV_VARS[subject]
with open("./config", mode="w") as config_file:
for subject in data:
print("New stuff for {} is {}".format(subject, data[subject]))
config_file.write("{}:{}\n".format(subject, "" if data[subject] is None else data[subject]))