summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHugo Hörnquist <hugo@lysator.liu.se>2022-01-28 14:55:47 +0100
committerHugo Hörnquist <hugo@lysator.liu.se>2022-01-28 14:55:47 +0100
commitb8d616d4db61608862ddf02368775a4100adfc70 (patch)
treecb812f0e91e1b5c209d18950f828910b9c4cc31f
parentAllow package declarations to create files. (diff)
downloadaur-runner-b8d616d4db61608862ddf02368775a4100adfc70.tar.gz
aur-runner-b8d616d4db61608862ddf02368775a4100adfc70.tar.xz
Formatting fixes.
-rwxr-xr-xmain.py58
1 files changed, 35 insertions, 23 deletions
diff --git a/main.py b/main.py
index 0eace77..0dd81f5 100755
--- a/main.py
+++ b/main.py
@@ -10,6 +10,7 @@ import logging.config
class PackageFilter(logging.Filter):
+ """Logging filter which adds a package field."""
def __init__(self):
self.package = False
@@ -21,6 +22,7 @@ class PackageFilter(logging.Filter):
def get_config_files():
+ """Return list of possible configuration files."""
subpath = ['aur-runner', 'config.yaml']
conf_files = []
# TODO better name for this, preferably matching the program name
@@ -122,10 +124,10 @@ def subprocess_with_log(args, capture_output=False, **kv_args):
if not capture_output and not kv_args.get('stdout'):
kv_args['stdout'] = subprocess.PIPE
kv_args['stderr'] = subprocess.STDOUT
- get_port = lambda process: process.stdout
+ def get_port(process): return process.stdout
else:
kv_args['stderr'] = subprocess.PIPE
- get_port = lambda process: process.stderr
+ def get_port(process): return process.stderr
if type(args) == list:
process_name = args[0]
@@ -134,7 +136,6 @@ def subprocess_with_log(args, capture_output=False, **kv_args):
else:
process_name = 'Unknown'
-
process = subprocess.Popen(args, **kv_args,)
logger.info('pid = %i, exec(%s)', process.pid, process.args)
@@ -157,7 +158,7 @@ def subprocess_with_log(args, capture_output=False, **kv_args):
pass
logger.log(level, '%s', line, extra={
- 'pid':process.pid,
+ 'pid': process.pid,
'process_name': process_name,
})
@@ -172,14 +173,15 @@ def subprocess_with_log(args, capture_output=False, **kv_args):
logger.warning('%i exit failure = %s', process.pid, process.returncode)
return process
+
auracle_args = ['--color=never']
-pacman_args = ['--noconfirm', '--asdeps', '--noprogressbar', '--needed']
+pacman_args = ['--noconfirm', '--asdeps', '--noprogressbar', '--needed']
makepkg_args = ['--nocolor']
def gather_packages(pkgs):
"""
- Figure out which packages to install, and in which order
+ Figure out which packages to install, and in which order.
Takes a list of package names, and returns to lists, one of
packages which are alreaddy available in the repos, and a list of
@@ -189,11 +191,15 @@ def gather_packages(pkgs):
"""
repo_pkgs = []
aur_pkgs = []
- cmd = subprocess_with_log(['auracle', *auracle_args, 'buildorder', *pkgs], capture_output=True, text=True)
+ cmd = subprocess_with_log(
+ ['auracle', *auracle_args, 'buildorder', *pkgs],
+ capture_output=True, text=True)
for line in cmd.stdout.split('\n'):
- if not line: continue
- m = re.match(r'(SATISFIED|TARGET)?(AUR|REPOS|UNKNOWN) ([^ ]*) ?(.*)', line)
+ if not line:
+ continue
+ pat = r'(SATISFIED|TARGET)?(AUR|REPOS|UNKNOWN) ([^ ]*) ?(.*)'
+ m = re.match(pat, line)
status = m[1]
source = m[2]
package = m[3]
@@ -246,7 +252,7 @@ def main():
for pkg in pkgs_:
if type(pkg) == str:
pkg_names.append(pkg)
- elif type(pkg) == dict:
+ elif type(pkg) == dict:
pkg_names.append(pkg['name'])
pkg_options[pkg['name']] = pkg.get('options', '').split(' ')
pkg_envs[pkg['name']] = pkg.get('env', {})
@@ -255,12 +261,13 @@ def main():
f.write(file['content'])
else:
logger.fatal('Package entries must be string or dict, not %s',
- type(pkg))
+ type(pkg))
sys.exit(1)
- # os.path.join discards earlier components whenever it finds an absolute path
+ # os.path.join discards earlier components whenever it finds an
+ # absolute path
cachedir = os.path.join(os.getcwd(), get_conf('cache-dir'))
- pkgdest = os.path.join(os.getcwd(), get_conf('pkgdest-dir'))
+ pkgdest = os.path.join(os.getcwd(), get_conf('pkgdest-dir'))
for dir in [cachedir, pkgdest]:
try:
@@ -279,21 +286,26 @@ def main():
failed_packages = []
for package in aur_pkgs:
filter.package = package
- cmd = subprocess_with_log(['auracle', *auracle_args, '--chdir', cachedir, 'clone', package],
- capture_output=True, text=True)
+ args = ['auracle', *auracle_args,
+ '--chdir', cachedir,
+ 'clone', package]
+ cmd = subprocess_with_log(args, capture_output=True, text=True)
m = re.match('[^:]*: (.*)', cmd.stdout)
if not m:
- logger.error('Auracle clone had unexpected output [%s], skipping package [%s]',
- cmd.stdout, package)
+ logger.error('Auracle clone had unexpected output [%s], '
+ 'skipping package [%s]',
+ cmd.stdout, package)
continue
cwd = m[1]
# Allow extra environments, but force our as non-overridable
- env = { **pkg_envs.get(package, {}),
- 'PKGDEST': pkgdest,
- 'PATH': ':'.join(path),
- }
+ env = {**pkg_envs.get(package, {}),
+ 'PKGDEST': pkgdest,
+ 'PATH': ':'.join(path),
+ }
extra_opts = pkg_options.get(package, [])
- cmd = subprocess_with_log(['makepkg', *makepkg_args, *extra_opts, '--install', *pacman_args], env=env, cwd=cwd)
+ args = ['makepkg', *makepkg_args, *extra_opts,
+ '--install', *pacman_args]
+ cmd = subprocess_with_log(args, env=env, cwd=cwd)
if cmd.returncode != 0:
failed_packages.append(package)
@@ -301,7 +313,7 @@ def main():
if failed_packages:
logger.warning('The following packages failed: %s',
- failed_packages)
+ failed_packages)
else:
logger.info('All packages built successfully')