25 lines
657 B
Python
Raw Permalink Normal View History

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
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
"""
if not Path(PACMAN_CONF).is_file():
raise FileNotFoundError(f"{PACMAN_CONF} does not exist")
2019-01-27 20:26:50 -08:00
config = PacmanConfig()
config.load_from_file(PACMAN_CONF)
2019-01-27 20:26:50 -08:00
return list(config.repos)