X-Git-Url: https://wannabe.guru.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=site_config.py;h=3bf049e3787f66a38f42b5be0330642f4f39e645;hb=65e6f781dffb268be6ef0a015f4cc89b57b62a5e;hp=233589970ea2058b2768de16ec649602eda2be2f;hpb=31c81f6539969a5eba864d3305f9fb7bf716a367;p=python_utils.git diff --git a/site_config.py b/site_config.py index 2335899..3bf049e 100644 --- a/site_config.py +++ b/site_config.py @@ -3,7 +3,7 @@ import logging import platform from dataclasses import dataclass -from typing import Callable +from typing import Callable, Optional # Note: this module is fairly early loaded. Be aware of dependencies. import config @@ -35,6 +35,7 @@ class SiteConfig(object): presence_location: Location is_anyone_present: Callable arper_minimum_device_count: int + arper_cache_file: str def get_location_name(): @@ -69,7 +70,29 @@ def is_anyone_present_wrapper(location: Location): return p.is_anyone_in_location_now(location) -def get_config(): +def other_location() -> str: + hostname = platform.node() + if '.house' in hostname: + location = 'CABIN' + elif '.cabin' in hostname: + location = 'HOUSE' + else: + raise Exception(f"{hostname} doesn't help me know where I'm running?!") + return location + + +def this_location() -> str: + hostname = platform.node() + if '.house' in hostname: + location = 'HOUSE' + elif '.cabin' in hostname: + location = 'CABIN' + else: + raise Exception(f"{hostname} doesn't help me know where I'm running?!") + return location + + +def get_config(location_override: Optional[str] = None): """ Get a configuration dataclass with information that is site-specific including the current running location. @@ -79,16 +102,17 @@ def get_config(): True """ - hostname = platform.node() - try: - location_override = config.config['site_config_override_location'] - except KeyError: - location_override = 'NONE' - if location_override == 'NONE': - if '.house' in hostname: - location = 'HOUSE' - elif '.cabin' in hostname: - location = 'CABIN' + if location_override is None: + try: + location_override = config.config['site_config_override_location'] + except KeyError: + location_override = None + + if location_override is None or location_override == 'NONE': + location = this_location() + else: + location = location_override + if location == 'HOUSE': return SiteConfig( location_name='HOUSE', @@ -99,6 +123,7 @@ def get_config(): presence_location=Location.HOUSE, 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', ) elif location == 'CABIN': return SiteConfig( @@ -110,6 +135,7 @@ def get_config(): presence_location=Location.CABIN, 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', ) else: raise Exception(f'Unknown site location: {location}')