capcat.core.config
File: Application/capcat/core/config.py
Description
Configuration management for Capcat. Handles settings from config files, environment variables, and CLI overrides.
Classes
NetworkConfig
Network-related configuration settings.
ProcessingConfig
Processing-related configuration settings.
UIConfig
User interface and experience configuration settings.
LoggingConfig
Logging-related configuration settings.
PdfConfig
PDF download configuration settings.
MediaConfig
Per-session media download toggles.
These are the vault-level defaults for what types of files are downloaded. Override per-source in source config.yaml or capcat.yml source entries. CLI flags always take precedence.
FetchNewsConfig
Main configuration class containing all settings.
Methods
post_init
def __post_init__(self)
Initialize sub-configs if not provided.
Creates default instances for network, processing, logging, UI, and PDF configurations when not explicitly specified.
Parameters:
self
to_dict
def to_dict(self) -> Dict[str, Any]
Convert configuration to dictionary.
Returns: Dictionary representation of full configuration
Parameters:
self
Returns: Dict[str, Any]
from_dict
def from_dict(cls, data: Dict[str, Any]) -> 'FetchNewsConfig'
Create configuration from dictionary.
Args: data: Dictionary with network, processing, logging, ui, pdf sections
Returns: New FetchNewsConfig instance
Parameters:
clsdata(Dict[str, Any])
Returns: ‘FetchNewsConfig’
ConfigManager
Manages configuration loading and merging from multiple sources.
Methods
init
def __init__(self)
Initialize the configuration manager.
Creates default configuration and sets load status to false.
Parameters:
self
_load_settings_file
def _load_settings_file(self, path: Path) -> None
Load a Global-settings.yaml file and merge into current config.
Silently ignores missing files, sources/bundles keys, and unknown keys.
Parameters:
selfpath(Path)
Returns: None
load_config
def load_config(self, config_file: Optional[str] = None, load_env: bool = True) -> FetchNewsConfig
Load configuration from files and environment variables.
Searches default locations if no file specified. Caches loaded config.
Args: config_file: Path to config file (JSON or YAML) load_env: Whether to load environment variables
Returns: Loaded configuration instance
Parameters:
selfconfig_file(Optional[str]) optionalload_env(bool) optional
Returns: FetchNewsConfig
_load_default_config_files
def _load_default_config_files(self)
Load from default config file locations.
Searches in order: local dir, ~/.config/capcat/, /etc/capcat/. Stops at first found file.
Parameters:
self
_load_from_file
def _load_from_file(self, config_file: str)
Load configuration from a file.
Supports JSON and YAML formats. Merges into existing config.
Args: config_file: Path to configuration file
Parameters:
selfconfig_file(str)
_load_from_env
def _load_from_env(self)
Load configuration from environment variables.
Maps CAPCAT_* environment variables to configuration settings. Handles type conversion for int, float, bool, and str types.
Parameters:
self
_merge_config_data
def _merge_config_data(self, data: Dict[str, Any])
Merge configuration data into current config.
Updates existing config object with values from data dict. The ‘sources’ list from capcat.yml is parsed into source_overrides. The ‘bundles’ key is silently ignored (not a settings concern). Warns about unknown sections or keys.
Args: data: Dictionary with section.key structure
Parameters:
selfdata(Dict[str, Any])
⚠️ High complexity: 19
get_config
def get_config(self) -> FetchNewsConfig
Get the current configuration.
Returns: Current configuration instance
Parameters:
self
Returns: FetchNewsConfig
save_config
def save_config(self, config_file: str, format: str = 'yaml')
Save current configuration to a file.
Creates parent directories if needed. Supports YAML and JSON formats.
Args: config_file: Path to save configuration format: Output format - ‘yaml’, ‘yml’, or ‘json’
Returns: True if saved successfully, False otherwise
Parameters:
selfconfig_file(str)format(str) optional
Functions
_filter_fields
def _filter_fields(cls, data: dict) -> dict
Return only keys that are known fields on the dataclass cls.
Parameters:
clsdata(dict)
Returns: dict
get_config
def get_config() -> FetchNewsConfig
Get the global configuration instance.
Returns: Global configuration object (singleton)
Returns: FetchNewsConfig
load_config
def load_config(config_file: Optional[str] = None, load_env: bool = True) -> FetchNewsConfig
Load configuration from file and/or environment variables.
Module-level convenience function for global config manager.
Args: config_file: Path to config file (JSON or YAML) load_env: Whether to load environment variables
Returns: Loaded configuration instance
Parameters:
config_file(Optional[str]) optionalload_env(bool) optional
Returns: FetchNewsConfig
save_config
def save_config(config_file: str, format: str = 'yaml') -> bool
Save current configuration to a file.
Module-level convenience function for global config manager.
Args: config_file: Path to save configuration format: Output format - ‘yaml’, ‘yml’, or ‘json’
Returns: True if saved successfully, False otherwise
Parameters:
config_file(str)format(str) optional
Returns: bool