2019-01-27 20:26:50 -08:00
|
|
|
"""Module for config file helper functions."""
|
|
|
|
|
2019-03-30 08:00:17 -07:00
|
|
|
from pathlib import Path
|
2023-01-06 21:56:50 -08:00
|
|
|
from pycman.config import PacmanConfig
|
2019-01-27 20:26:50 -08:00
|
|
|
|
2019-01-30 17:05:49 -08:00
|
|
|
# ========== Constants ==========
|
2019-03-30 08:00:17 -07:00
|
|
|
PACMAN_CONF = Path("/etc/pacman.conf")
|
2019-01-27 20:26:50 -08:00
|
|
|
|
|
|
|
|
2019-01-30 17:05:49 -08:00
|
|
|
# ========== Functions ==========
|
2019-01-27 20:26:50 -08:00
|
|
|
def list_configured_repos():
|
|
|
|
"""Read /etc/pacman.conf to list all configured repositories.
|
|
|
|
|
|
|
|
:raises FileNotFoundError: if config file does not exist
|
|
|
|
:returns: all repos configured on the system
|
|
|
|
:rtype: list
|
|
|
|
"""
|
2023-01-06 21:56:50 -08:00
|
|
|
if not Path(PACMAN_CONF).is_file():
|
|
|
|
raise FileNotFoundError(f"{PACMAN_CONF} does not exist")
|
2019-01-27 20:26:50 -08:00
|
|
|
|
2023-01-06 21:56:50 -08:00
|
|
|
config = PacmanConfig()
|
|
|
|
config.load_from_file(PACMAN_CONF)
|
2019-01-27 20:26:50 -08:00
|
|
|
|
2023-01-06 21:56:50 -08:00
|
|
|
return list(config.repos)
|