projects
/
python_utils.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Since this thing is on the innerwebs I suppose it should have a
[python_utils.git]
/
site_config.py
diff --git
a/site_config.py
b/site_config.py
index fcf22a8d2cf20d4e6a6dd83690a51de08ce2f44d..5604de676c0ded41ce5edcc051809ac7968c6286 100644
(file)
--- a/
site_config.py
+++ b/
site_config.py
@@
-1,5
+1,9
@@
#!/usr/bin/env python3
#!/usr/bin/env python3
+# © Copyright 2021-2022, Scott Gasch
+
+"""Location/site dependent data."""
+
import logging
import platform
from dataclasses import dataclass
import logging
import platform
from dataclasses import dataclass
@@
-27,6
+31,8
@@
args.add_argument(
@dataclass
class SiteConfig(object):
@dataclass
class SiteConfig(object):
+ """The set of information specific to where the program is running."""
+
location_name: str
location: Location
network: str
location_name: str
location: Location
network: str
@@
-78,15
+84,18
@@
def other_location() -> str:
>>> x in set(['HOUSE', 'CABIN'])
True
>>> x in set(['HOUSE', 'CABIN'])
True
+ >>> y = this_location()
+ >>> x == y
+ False
+
"""
"""
-
hostname = platform.node
()
- if
'.house' in hostname
:
-
location =
'CABIN'
- elif
'.cabin' in hostname
:
-
location =
'HOUSE'
+
this = this_location
()
+ if
this == 'HOUSE'
:
+
return
'CABIN'
+ elif
this == 'CABIN'
:
+
return
'HOUSE'
else:
else:
- raise Exception(f"{hostname} doesn't help me know where I'm running?!")
- return location
+ raise Exception(f"{this} doesn't tell me where I'm running?!")
def this_location() -> str:
def this_location() -> str:
@@
-103,6
+112,8
@@
def this_location() -> str:
location = 'HOUSE'
elif '.cabin' in hostname:
location = 'CABIN'
location = 'HOUSE'
elif '.cabin' in hostname:
location = 'CABIN'
+ elif '.local' in hostname:
+ location = 'HOUSE'
else:
raise Exception(f"{hostname} doesn't help me know where I'm running?!")
return location
else:
raise Exception(f"{hostname} doesn't help me know where I'm running?!")
return location
@@
-129,7
+140,7
@@
def effective_location(location_override: Optional[str] = None) -> str:
if location_override is None or location_override == 'NONE':
location = this_location()
else:
if location_override is None or location_override == 'NONE':
location = this_location()
else:
- logger.debug(
f'site_config\'s location_override was set to: {location_override}'
)
+ logger.debug(
'site_config\'s location_override was set to: %s', location_override
)
location = location_override
return location
location = location_override
return location