projects
/
python_utils.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
More changes to get 3.9 working.
[python_utils.git]
/
site_config.py
diff --git
a/site_config.py
b/site_config.py
index fcf22a8d2cf20d4e6a6dd83690a51de08ce2f44d..eb7d8845639a6b81b73c22425c90fbc52eb8d5c9 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,18
+31,39
@@
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_name: str
+ """Either "HOUSE" or "CABIN" depending on where we're running"""
+
location: Location
location: Location
+ """Same as above but as an enum value instead of a string"""
+
network: str
network: str
+ """The local network specification, e.g. 192.168.0.0/24."""
+
network_netmask: str
network_netmask: str
+ """The netmask of the local network, e.g. 255.255.255.0."""
+
network_router_ip: str
network_router_ip: str
+ """The IP address of the local router, e.g. 192.168.0.1."""
+
presence_location: Location
presence_location: Location
+ """Same as location, above."""
+
is_anyone_present: Callable
is_anyone_present: Callable
+ """Returns a callable which, when invoked, will tell you if it detects
+ any person in your location by auditing network device MAC addresses."""
+
arper_minimum_device_count: int
arper_minimum_device_count: int
+ """How many MAC addresses do we need to see for it to be considered a
+ successful scan?"""
+
arper_cache_file: str
arper_cache_file: str
+ """The location of the persisted IP-MAC address mappings."""
-def get_location_name():
+def get_location_name()
-> str
:
"""
Where are we?
"""
Where are we?
@@
-50,7
+75,7
@@
def get_location_name():
return get_config().location_name
return get_config().location_name
-def get_location():
+def get_location()
-> Location
:
"""
Returns location as an enum instead of a string.
"""
Returns location as an enum instead of a string.
@@
-63,7
+88,7
@@
def get_location():
return get_config().location
return get_config().location
-def is_anyone_present_wrapper(location: Location):
+def
_
is_anyone_present_wrapper(location: Location):
import base_presence
p = base_presence.PresenceDetection()
import base_presence
p = base_presence.PresenceDetection()
@@
-78,15
+103,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
+131,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
+159,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
@@
-153,7
+183,7
@@
def get_config(location_override: Optional[str] = None):
network_netmask='255.255.255.0',
network_router_ip='10.0.0.1',
presence_location=Location.HOUSE,
network_netmask='255.255.255.0',
network_router_ip='10.0.0.1',
presence_location=Location.HOUSE,
- is_anyone_present=lambda x=Location.HOUSE: is_anyone_present_wrapper(x),
+ is_anyone_present=lambda x=Location.HOUSE:
_
is_anyone_present_wrapper(x),
arper_minimum_device_count=50,
arper_cache_file='/home/scott/cache/.arp_table_cache_house',
)
arper_minimum_device_count=50,
arper_cache_file='/home/scott/cache/.arp_table_cache_house',
)
@@
-165,7
+195,7
@@
def get_config(location_override: Optional[str] = None):
network_netmask='255.255.255.0',
network_router_ip='192.168.0.1',
presence_location=Location.CABIN,
network_netmask='255.255.255.0',
network_router_ip='192.168.0.1',
presence_location=Location.CABIN,
- is_anyone_present=lambda x=Location.CABIN: is_anyone_present_wrapper(x),
+ is_anyone_present=lambda x=Location.CABIN:
_
is_anyone_present_wrapper(x),
arper_minimum_device_count=15,
arper_cache_file='/home/scott/cache/.arp_table_cache_cabin',
)
arper_minimum_device_count=15,
arper_cache_file='/home/scott/cache/.arp_table_cache_cabin',
)