pull/210/head
Patrick Robertson 2025-02-19 10:28:35 +00:00
rodzic 3c543a3a6a
commit eb60b271b9
1 zmienionych plików z 30 dodań i 5 usunięć

Wyświetl plik

@ -95,6 +95,8 @@ class UniqueAppendAction(argparse.Action):
class ArchivingOrchestrator: class ArchivingOrchestrator:
setup_finished: bool = False
logger_id: int = None
feeders: List[Type[Feeder]] feeders: List[Type[Feeder]]
extractors: List[Type[Extractor]] extractors: List[Type[Extractor]]
enrichers: List[Type[Enricher]] enrichers: List[Type[Enricher]]
@ -274,11 +276,18 @@ class ArchivingOrchestrator:
def setup_logging(self, config): def setup_logging(self, config):
# setup loguru logging # setup loguru logging
logger.remove(0) # remove the default logger try:
logger.remove(0) # remove the default logger
except ValueError:
pass
logging_config = config['logging'] logging_config = config['logging']
logger.add(sys.stderr, level=logging_config['level'])
if log_file := logging_config['file']: # add other logging info
logger.add(log_file) if not logging_config['rotation'] else logger.add(log_file, rotation=logging_config['rotation']) if self.logger_id is None: # note - need direct comparison to None since need to consider falsy value 0
self.logger_id = logger.add(sys.stderr, level=logging_config['level'])
if log_file := logging_config['file']:
logger.add(log_file) if not logging_config['rotation'] else logger.add(log_file, rotation=logging_config['rotation'])
def install_modules(self, modules_by_type): def install_modules(self, modules_by_type):
""" """
@ -359,7 +368,10 @@ class ArchivingOrchestrator:
def setup_config(self, args: list) -> dict: def setup_config(self, args: list) -> dict:
""" """
Sets up the configuration file, merging the default config with the user's config Sets up the configuration file, merging the default config with the user's config
This function should only ever be run once.
""" """
self.setup_basic_parser() self.setup_basic_parser()
# parse the known arguments for now (basically, we want the config file) # parse the known arguments for now (basically, we want the config file)
@ -378,8 +390,19 @@ class ArchivingOrchestrator:
def setup(self, args: list): def setup(self, args: list):
""" """
Main entry point for the orchestrator, sets up the basic parser, loads the config file, and sets up the complete parser Function to configure all setup of the orchestrator: setup configs and load modules.
This method should only ever be called once
""" """
if self.setup_finished:
logger.warning("The `setup_config()` function should only ever be run once. \
If you need to re-run the setup, please re-instantiate a new instance of the orchestrator. \
For code implementatations, you should call .setup_config() once then you may call .feed() \
multiple times to archive multiple URLs.")
return
self.setup_basic_parser()
self.config = self.setup_config(args) self.config = self.setup_config(args)
logger.info(f"======== Welcome to the AUTO ARCHIVER ({__version__}) ==========") logger.info(f"======== Welcome to the AUTO ARCHIVER ({__version__}) ==========")
@ -388,6 +411,8 @@ class ArchivingOrchestrator:
# log out the modules that were loaded # log out the modules that were loaded
for module_type in BaseModule.MODULE_TYPES: for module_type in BaseModule.MODULE_TYPES:
logger.info(f"{module_type.upper()}S: " + ", ".join(m.display_name for m in getattr(self, f"{module_type}s"))) logger.info(f"{module_type.upper()}S: " + ", ".join(m.display_name for m in getattr(self, f"{module_type}s")))
self.setup_finished = True
def _command_line_run(self, args: list) -> Generator[Metadata]: def _command_line_run(self, args: list) -> Generator[Metadata]:
""" """