def get_mac_by_ip(self, ip: str) -> Optional[str]:
return self.state.inverse.get(ip, None)
- @overrides
- def save(self) -> bool:
- if len(self.state) > config.config['arper_min_entries_to_be_valid']:
- logger.debug(
- f'Persisting state to {config.config["arper_cache_location"]}'
- )
- with file_utils.FileWriter(config.config['arper_cache_location']) as wf:
- for (mac, ip) in self.state.items():
- mac = mac.lower()
- print(f'{mac}, {ip}', file=wf)
- return True
- else:
- logger.warning(
- f'Only saw {len(self.state)} entries; needed at least {config.config["arper_min_entries_to_be_valid"]} to bother persisting.'
- )
- return False
-
@classmethod
@overrides
def load(cls) -> Any:
logger.debug('No usable saved state found')
return None
+
+ @overrides
+ def save(self) -> bool:
+ if len(self.state) > config.config['arper_min_entries_to_be_valid']:
+ logger.debug(
+ f'Persisting state to {config.config["arper_cache_location"]}'
+ )
+ with file_utils.FileWriter(config.config['arper_cache_location']) as wf:
+ for (mac, ip) in self.state.items():
+ mac = mac.lower()
+ print(f'{mac}, {ip}', file=wf)
+ return True
+ else:
+ logger.warning(
+ f'Only saw {len(self.state)} entries; needed at least {config.config["arper_min_entries_to_be_valid"]} to bother persisting.'
+ )
+ return False
import json
import logging
import os
-from typing import List
+from typing import Any, List
import urllib.request
+from overrides import overrides
+
import argparse_utils
import config
import datetime_utils
)
@classmethod
- def load(cls):
+ @overrides
+ def load(cls) -> Any:
if persistent.was_file_written_within_n_seconds(
config.config['weather_data_cachefile'],
config.config['weather_data_stalest_acceptable'].total_seconds(),
return cls(weather_data)
return None
- def save(self):
+ @overrides
+ def save(self) -> bool:
import pickle
with open(config.config['weather_data_cachefile'], 'wb') as wf:
pickle.dump(
wf,
pickle.HIGHEST_PROTOCOL,
)
+ return True
import astral # type: ignore
from astral.sun import sun # type: ignore
from bs4 import BeautifulSoup # type: ignore
+from overrides import overrides
import pytz
import argparse_utils
)
@classmethod
+ @overrides
def load(cls):
if persistent.was_file_written_within_n_seconds(
config.config['weather_forecast_cachefile'],
return cls(weather_data)
return None
+ @overrides
def save(self):
import pickle
with open(config.config['weather_forecast_cachefile'], 'wb') as wf:
default=False,
help='Should we prepend pid/tid data to all log messages?'
)
+cfg.add_argument(
+ '--logging_debug_modules',
+ action=argparse_utils.ActionNoYes,
+ default=False,
+ help='Should we prepend module/function data to all log messages?'
+)
cfg.add_argument(
'--logging_info_is_print',
action=argparse_utils.ActionNoYes,
fmt = config.config['logging_format']
if config.config['logging_debug_threads']:
fmt = f'%(process)d.%(thread)d|{fmt}'
+ if config.config['logging_debug_modules']:
+ fmt = f'%(filename)s:%(funcName)s:%(lineno)s|{fmt}'
if config.config['logging_syslog']:
if sys.platform not in ('win32', 'cygwin'):