-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsettings.py
50 lines (42 loc) · 1.57 KB
/
settings.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
# Settings file for the library
import yaml
from yaml.scanner import ScannerError
from pathlib import Path
class SettingsError(Exception):
pass
class Settings():
def __init__(self, settings_file=None):
if settings_file is None:
script_dir = Path(__file__).parents[0]
self.settings_file = script_dir / "settings.yml"
else:
self.settings_file = Path(settings_file)
# Isilon Server Settings and Credentials
self.ip = ""
self.name = ""
self.username = ""
self.password = ""
self.port = ""
self.verify_ssl = True
# Override the defaults above
self.load_settings_file()
# Load data from the settings.yml file
def load_settings_file(self):
try:
with open(self.settings_file, "r") as settings_file:
data = yaml.safe_load(settings_file)
for k, v in data.items():
setattr(self, k, v)
except FileNotFoundError:
# If the settings.yml file is missing, means use defaults
pass
except AttributeError as e:
if str(e) == "'NoneType' object has no attribute 'items'":
# The settings.yml file exists but is empty, use defaults
pass
else:
raise
except ScannerError as e:
raise SettingsError("You have a malformed 'settings.yml' file. "
"Please fix this. The error can be found in "
f"the following message: {e}")