|
- import logging
-
- logger = logging.getLogger(__name__)
-
-
- def get_sources(path, delimiter='\n'):
- logger.info("Attempting to load sources from file: '%s' with delimiter: %r", path, delimiter)
- sources = None
- try:
- with open(path, 'r', encoding='utf-8') as source_file:
- logger.debug("Successfully opened file '%s' for reading", path)
- content = source_file.read()
- logger.debug("Read %d bytes/characters from '%s'", len(content), path)
- sources = content.split(delimiter)
- logger.info("Successfully read and split %d source entries from '%s'", len(sources), path)
- for idx, src in enumerate(sources):
- if not src.strip():
- logger.warning("Source at index %d is empty or whitespace-only: %r", idx, src)
- else:
- logger.debug("Source [%d]: %s", idx, src)
- except FileNotFoundError:
- logger.error("Source file not found at path: '%s'", path, exc_info=True)
- raise
- except PermissionError:
- logger.error("Permission denied when accessing source file: '%s'", path, exc_info=True)
- raise
- except Exception as e:
- logger.error("Failed to read sources from '%s': %s", path, e, exc_info=True)
- raise
-
- return sources
|