Initial commit

This commit is contained in:
Eric Torres
2019-01-27 20:26:50 -08:00
commit 4c578142c1
17 changed files with 552 additions and 0 deletions

View File

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,47 @@
"""Module for config file helper functions."""
import configparser
import pathlib
PACMAN_CONF = pathlib.Path('/etc/pacman.conf')
def parse_configfile(filepath):
"""Parse a config file given its path and return
a ConfigParser object.
:param path: path to config file to parse
:type path: str, bytes, or path-like object
:returns: object used to parse config file
:rtype: ConfigParser object
:raises: FileNotFoundError if path does not exist
"""
if not pathlib.Path(filepath).is_file():
raise FileNotFoundError(f"{filepath} does not exist")
config_reader = configparser.ConfigParser(strict=False,
allow_no_value=True)
config_reader.read(filepath)
return config_reader
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 PACMAN_CONF.is_file():
raise FileNotFoundError(f"{PACMAN_CONF} was not found")
parsed_config = parse_configfile(PACMAN_CONF)
repos = parsed_config.sections()
# remove the 'option' entry from the list
del repos[0]
repos.sort()
return repos

View File

@ -0,0 +1,24 @@
"""Helper functions for dealing with package files."""
import pathlib
PKGEXT = 'pkg.tar.xz'
SIGEXT = f"{PKGEXT}.sig"
def get_pkgfiles(directory=None, signatures=False):
"""Return a list of package files in the current working directory.
:param directory: a directory to search in
:type directory: str, bytes, or path-like object
:returns: paths of package files
:rtype: list
"""
if directory:
path = pathlib.Path(directory)
else:
path = pathlib.Path.cwd()
if signatures:
return list(path.glob(f"*.{SIGEXT}"))
return list(path.glob(f"*.{PKGEXT}"))

View File

@ -0,0 +1,17 @@
#compdef addpkg
# zsh completions for 'addpkg'
# automatically generated with http://github.com/RobSis/zsh-completion-generator
local arguments
arguments=(
{-h,--help}'[show this help message and exit]'
{-C,--compression-type}'[the compression algorithm the db is using]'
{-c,--clean-cachedir}'[use paccache to clean the cache directory]'
{-R,--remove}'[remove old package files]'
{-s,--sign}'[sign repository file]'
{-v,--verbose}'[increase script verbosity]'
'*:filename:_files'
)
_arguments -s $arguments

View File

@ -0,0 +1,15 @@
#compdef delpkg
# zsh completions for 'delpkg'
# automatically generated with http://github.com/RobSis/zsh-completion-generator
local arguments
arguments=(
{-c,--clean-cachedir}'[run paccache to clean the cache directory]'
{-h,--help}'[show this help message and exit]'
{-s,--sign}'[sign repository file]'
{-v, --verbose}'[increase script verbosity]'
'*:filename:_files'
)
_arguments -s $arguments