Run black python linting utility on all source files

This commit is contained in:
Eric Torres 2019-03-06 23:41:05 -08:00
parent a2ec1729b9
commit 01f41472e2
8 changed files with 77 additions and 78 deletions

View File

@ -1,6 +1,6 @@
# Maintainer: Eric Torres <erictorres4@protonmail.com>
pkgname=packaging-scripts
pkgver=1.0.2
pkgver=1.0.3
pkgrel=1
pkgdesc="A set of helper scripts for handling Arch Linux packages"
arch=('any')

View File

@ -18,8 +18,8 @@ import packaging_scripts.pkgfiles as pkgfiles
import packaging_scripts.repos as repos
# ========== Constants ==========
DB_EXT = 'db.tar.xz'
LOGFORMAT = '==> %(levelname)s %(message)s'
DB_EXT = "db.tar.xz"
LOGFORMAT = "==> %(levelname)s %(message)s"
# ========== Exit codes ==========
E_NOFILESERR = 1
@ -27,7 +27,7 @@ E_REPO_ADDERR = 2
# ========== Logging setup ==========
console_formatter = logging.Formatter(LOGFORMAT)
syslog = logging.getLogger('packaging_scripts')
syslog = logging.getLogger("packaging_scripts")
syslog.setLevel(logging.DEBUG)
stdout_handler = logging.StreamHandler(sys.stdout)
@ -56,24 +56,26 @@ def add_pkgfile(pkgfile, cachedir):
shutil.move(pkgfile, os.path.join(cachedir, os.path.basename(pkgfile)))
if __name__ == '__main__':
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument('-s', '--sign',
dest='opts',
action='append_const',
const='--sign',
help='sign repository file')
parser.add_argument('-v', '--verbose',
action='store_true',
help='increase script verbosity')
parser.add_argument('repository',
parser.add_argument(
"-s",
"--sign",
dest="opts",
action="append_const",
const="--sign",
help="sign repository file",
)
parser.add_argument(
"-v", "--verbose", action="store_true", help="increase script verbosity"
)
parser.add_argument(
"repository",
choices=pacmanconf.list_configured_repos(),
help='the repository to operate on',
metavar='repo')
parser.add_argument('packages',
default=None,
nargs='*',
help='packages to add')
help="the repository to operate on",
metavar="repo",
)
parser.add_argument("packages", default=None, nargs="*", help="packages to add")
args = parser.parse_args()
repo = args.repository
@ -84,7 +86,7 @@ if __name__ == '__main__':
else:
opts = args.opts
cachedir = os.path.join('/var', 'cache', 'pacman', repo)
cachedir = os.path.join("/var", "cache", "pacman", repo)
# this assumes that the db file for the repo
# has the same name as that repo
db = os.path.join(cachedir, f"{repo}.{DB_EXT}")
@ -100,11 +102,11 @@ if __name__ == '__main__':
sigfiles = pkgfiles.get_pkgfiles(signatures_only=True)
if not pkg_tarballs:
syslog.critical('No package tarballs have been found, exiting')
syslog.critical("No package tarballs have been found, exiting")
exit(E_NOFILESERR)
try:
repos.db_modify('add', db, *opts, *pkg_tarballs)
repos.db_modify("add", db, *opts, *pkg_tarballs)
except repos.RepoAddError as e:
syslog.error(e)
exit(E_REPO_ADDERR)

View File

@ -17,14 +17,14 @@ import packaging_scripts.pkgfiles as pkgfiles
import packaging_scripts.repos as repos
# ========== Constants ==========
DB_EXT = 'db.tar.xz'
DB_EXT = "db.tar.xz"
# ========== Exit codes ==========
E_REPO_REMOVEERR = 2
# ========== Logging setup ==========
console_formatter = logging.Formatter('==> %(levelname)s %(message)s')
syslog = logging.getLogger('packaging_scripts')
console_formatter = logging.Formatter("==> %(levelname)s %(message)s")
syslog = logging.getLogger("packaging_scripts")
syslog.setLevel(logging.DEBUG)
stdout_handler = logging.StreamHandler(sys.stdout)
@ -51,23 +51,26 @@ def del_pkgfile(pkg):
syslog.info(f"Removed {pkg}")
if __name__ == '__main__':
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument('-s', '--sign',
dest='opts',
action='append_const',
const='--sign',
help='sign repository file')
parser.add_argument('-v', '--verbose',
action='store_true',
help='increase script verbosity')
parser.add_argument('repository',
parser.add_argument(
"-s",
"--sign",
dest="opts",
action="append_const",
const="--sign",
help="sign repository file",
)
parser.add_argument(
"-v", "--verbose", action="store_true", help="increase script verbosity"
)
parser.add_argument(
"repository",
choices=pacmanconf.list_configured_repos(),
help='the repository to operate on',
metavar='repo')
parser.add_argument('packages',
nargs='+',
help='packages to remove')
help="the repository to operate on",
metavar="repo",
)
parser.add_argument("packages", nargs="+", help="packages to remove")
args = parser.parse_args()
repo = args.repository
@ -78,7 +81,7 @@ if __name__ == '__main__':
else:
opts = args.opts
cachedir = os.path.join('/var', 'cache', 'pacman', repo)
cachedir = os.path.join("/var", "cache", "pacman", repo)
# this assumes that the db file for the repo
# has the same name as that repo
db = os.path.join(cachedir, f"{repo}.{DB_EXT}")
@ -87,16 +90,15 @@ if __name__ == '__main__':
stdout_handler.setLevel(logging.DEBUG)
for pkg in pkgs:
pkg_tarballs = pkgfiles.get_pkgfiles(query=pkg,
directory=cachedir)
sigfiles = pkgfiles.get_pkgfiles(query=pkg,
directory=cachedir,
signatures_only=True)
pkg_tarballs = pkgfiles.get_pkgfiles(query=pkg, directory=cachedir)
sigfiles = pkgfiles.get_pkgfiles(
query=pkg, directory=cachedir, signatures_only=True
)
for pkgfile in (*pkg_tarballs, *sigfiles):
del_pkgfile(pkgfile)
try:
repos.db_modify('remove', db, *opts, *pkgs)
repos.db_modify("remove", db, *opts, *pkgs)
except repos.RepoAddError as e:
syslog.error(e)

26
bin/fqo
View File

@ -12,12 +12,12 @@ import subprocess
# ========== Constants ==========
# Commands
PACMAN_CMD = '/usr/bin/pacman'
FZF_CMD = '/usr/bin/fzf'
FZF_OPTS = ['--read0', '--select-1', '--exit-0', '--print0']
LOCATE_CMD = '/usr/bin/locate'
LOCATE_OPTS = ['--all', '--ignore-case', '--null']
LOCALE = 'utf-8'
PACMAN_CMD = "/usr/bin/pacman"
FZF_CMD = "/usr/bin/fzf"
FZF_OPTS = ["--read0", "--select-1", "--exit-0", "--print0"]
LOCATE_CMD = "/usr/bin/locate"
LOCATE_OPTS = ["--all", "--ignore-case", "--null"]
LOCALE = "utf-8"
# ========== Functions ==========
@ -29,11 +29,11 @@ def run_fzf(files):
:returns: selected file
:rtype: str
"""
selected_file = subprocess.run([FZF_CMD] + FZF_OPTS,
input=files,
stdout=subprocess.PIPE).stdout
selected_file = subprocess.run(
[FZF_CMD] + FZF_OPTS, input=files, stdout=subprocess.PIPE
).stdout
return selected_file.decode(LOCALE).strip('\x00')
return selected_file.decode(LOCALE).strip("\x00")
def locate_files(patterns):
@ -52,13 +52,11 @@ def locate_files(patterns):
# ========== Main Script ==========
parser = argparse.ArgumentParser()
parser.add_argument('patterns',
nargs='+',
help='file pattern to search for')
parser.add_argument("patterns", nargs="+", help="file pattern to search for")
args = parser.parse_args()
files = locate_files(args.patterns)
selected_file = run_fzf(files)
subprocess.run([PACMAN_CMD, '-Qo', selected_file])
subprocess.run([PACMAN_CMD, "-Qo", selected_file])

View File

@ -4,7 +4,7 @@ import configparser
import pathlib
# ========== Constants ==========
PACMAN_CONF = pathlib.Path('/etc/pacman.conf')
PACMAN_CONF = pathlib.Path("/etc/pacman.conf")
# ========== Functions ==========
@ -21,8 +21,7 @@ def parse_configfile(filepath):
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 = configparser.ConfigParser(strict=False, allow_no_value=True)
config_reader.read(filepath)
return config_reader

View File

@ -5,7 +5,7 @@ import os
import os.path
# ========== Constants ==========
PKGEXT = 'pkg.tar.xz'
PKGEXT = "pkg.tar.xz"
SIGEXT = f"{PKGEXT}.sig"

View File

@ -37,10 +37,10 @@ def db_modify(operation, db, *args):
:raises: RepoAddError if repo-add failed
:raises: ValueError if an invalid operation was specified
"""
if operation == 'add':
syslog.info('Adding packages to database')
elif operation == 'remove':
syslog.info('Removing packages from database')
if operation == "add":
syslog.info("Adding packages to database")
elif operation == "remove":
syslog.info("Removing packages from database")
else:
raise ValueError(f"Invalid operation specified: {operation}")
@ -53,7 +53,7 @@ def db_modify(operation, db, *args):
raise RepoAddError(e)
else:
syslog.debug(process.stdout)
syslog.info('Database operation complete')
syslog.info("Database operation complete")
def _run_script(operation, *args):
@ -66,7 +66,6 @@ def _run_script(operation, *args):
options and packages
:type args: str
"""
return subprocess.run((f"repo-{operation}", *args),
check=True,
capture_output=True,
text=True)
return subprocess.run(
(f"repo-{operation}", *args), check=True, capture_output=True, text=True
)

View File

@ -1,7 +1,6 @@
#compdef addpkg
# zsh completions for 'addpkg'
# automatically generated with http://github.com/RobSis/zsh-completion-generator
local arguments
arguments=(