#!/usr/bin/env python3 from dataclasses import dataclass import logging import platform from typing import Optional import config logger = logging.getLogger(__name__) args = config.add_commandline_args( f'({__file__})', 'Args related to __file__' ) args.add_argument( '--site_config_location', default='AUTO', const='AUTO', nargs='?', choices=('HOUSE', 'CABIN', 'AUTO'), help='Where are we, HOUSE or CABIN?' ) @dataclass class SiteConfig(object): network: str network_netmask: str network_router_ip: str def get_location(): location = config.config['site_config_location'] if location == 'AUTO': hostname = platform.node() if '.house' in hostname: location = 'HOUSE' elif '.cabin' in hostname: location = 'CABIN' else: raise Exception(f'Unknown hostname {hostname}, help.') return location def get_config(): location = get_location() if location == 'HOUSE': return SiteConfig( network = '10.0.0.0/24', network_netmask = '255.255.255.0', network_router_ip = '10.0.0.1', ) elif location == 'CABIN': return SiteConfig( network = '192.168.0.0/24', network_netmask = '255.255.255.0', network_router_ip = '192.168.0.1', ) else: raise Exception('Unknown site location')