Some fixes to the datetime_utils.
[python_utils.git] / site_config.py
1 #!/usr/bin/env python3
2
3 from dataclasses import dataclass
4 import logging
5 import platform
6 from typing import Optional
7
8 import config
9
10 logger = logging.getLogger(__name__)
11 args = config.add_commandline_args(
12     f'({__file__})',
13     'Args related to __file__'
14 )
15
16 args.add_argument(
17     '--site_config_location',
18     default='AUTO',
19     const='AUTO',
20     nargs='?',
21     choices=('HOUSE', 'CABIN', 'AUTO'),
22     help='Where are we, HOUSE, CABIN or AUTO?',
23 )
24
25
26 @dataclass
27 class SiteConfig(object):
28     network: str
29     network_netmask: str
30     network_router_ip: str
31
32
33 def get_location():
34     location = config.config['site_config_location']
35     if location == 'AUTO':
36         hostname = platform.node()
37         if '.house' in hostname:
38             location = 'HOUSE'
39         elif '.cabin' in hostname:
40             location = 'CABIN'
41         else:
42             raise Exception(f'Unknown hostname {hostname}, help.')
43     return location
44
45
46 def get_config():
47     location = get_location()
48     if location == 'HOUSE':
49         return SiteConfig(
50             network = '10.0.0.0/24',
51             network_netmask = '255.255.255.0',
52             network_router_ip = '10.0.0.1',
53         )
54     elif location == 'CABIN':
55         return SiteConfig(
56             network = '192.168.0.0/24',
57             network_netmask = '255.255.255.0',
58             network_router_ip = '192.168.0.1',
59         )
60     else:
61         raise Exception('Unknown site location')