From 3baf75fe3b3db7b7ae3adf9ba097cb45dfbd50fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20H=C3=B6rnquist?= Date: Mon, 24 Jan 2022 20:10:47 +0100 Subject: Minor fixups. --- main.py | 48 ++++++++++++++++++++++++++++++++---------------- 1 file changed, 32 insertions(+), 16 deletions(-) diff --git a/main.py b/main.py index 86ee9c8..386c53f 100755 --- a/main.py +++ b/main.py @@ -83,6 +83,12 @@ def get_conf(key, default=None): logging.config.dictConfig(get_conf('logging')) logger = logging.getLogger(__name__) +def log_cmd(cmd): + if cmd.returncode == 0: + logger.info('%s finished without errors', cmd.args) + else: + logger.warning('%s exited with status code %s', cmd.args, cmd.returncode) + auracle_args = ['--color=never'] pacman_args = ['--noconfirm', '--asdeps', '--noprogressbar', '--needed'] @@ -102,6 +108,7 @@ def gather_packages(pkgs): repo_pkgs = [] aur_pkgs = [] cmd = subprocess.run(['auracle', *auracle_args, 'buildorder', *pkgs], capture_output=True, text=True) + log_cmd(cmd) for line in cmd.stdout.split('\n'): if not line: continue @@ -110,13 +117,13 @@ def gather_packages(pkgs): source = m[2] package = m[3] if status == 'SATISFIED': - logger.debug(f'Package already installed: {package}') + logger.debug('Package already installed: %s', package) continue if source == 'REPOS': - logger.debug(f'Would install from repo: {package}') + logger.debug('Would install from repo: %s', package) repo_pkgs.append(package) elif source == 'AUR': - logger.debug(f'Would install from aur: {package}') + logger.debug('Would install from aur: %s', package) aur_pkgs.append(package) elif source == 'UNKNOWN': # auracle buildorder guile-chickadee fails with @@ -124,7 +131,7 @@ def gather_packages(pkgs): # Since guile-opengl is provided by guile-opengl-git, and # auracle doesn't find that. The information is however there # on the aur: https://aur.archlinux.org/packages/guile-chickadee/ - logger.fatal('Something went wrong', line, m[4]) + logger.fatal('AURACLE UNKNOWN, [%s], [%s]', line, m[4]) sys.exit(1) return repo_pkgs, aur_pkgs @@ -134,11 +141,17 @@ def gather_packages(pkgs): def main(): with open(get_conf('package-list')) as f: - pkgs = yaml.safe_load(f) + data = yaml.safe_load(f) + + if type(data) != dict: + logger.fatal('Package must have a dict as root') + sys.exit(1) - if type(pkgs) != list: - logger.fatal('Package list is not a list') - os.exit(1) + if type(data.get('packages')) != list: + logger.fatal('Invalid key packages in package list') + sys.exit(1) + + pkgs = data.get('packages') # os.path.join discards earlier components whenever it finds an absolute path cachedir = os.path.join(os.getcwd(), get_conf('cache-dir')) @@ -154,24 +167,27 @@ def main(): repo_pkgs, aur_pkgs = gather_packages(pkgs) - def log_cmd(cmd): - if cmd.returncode == 0: - logger.info('%s finished without errors', cmd.args) - else: - logger.warning('%s exited with status code %s', cmd.args, cmd.retruncode) - if repo_pkgs: - logger.info(f'Installing from the repos: {repo_pkgs}') + logger.info('Installing from the repos: %s', repo_pkgs) log_cmd(subprocess.run(['sudo', 'pacman', *pacman_args, '-S', *repo_pkgs])) for package in aur_pkgs: cmd = subprocess.run(['auracle', *auracle_args, '--chdir', cachedir, 'clone', package], capture_output=True, text=True) - cwd = re.match('[^:]*: (.*)', cmd.stdout)[1] + log_cmd(cmd) + m = re.match('[^:]*: (.*)', cmd.stdout) + if not m: + logger.error('Auracle clone had unexpected output [%s], skipping package [%s]', + cmd.stdout, package) + continue + cwd = m[1] env = { 'PKGDEST': pkgdest, 'PATH': ':'.join(path), } log_cmd(subprocess.run(['makepkg', *makepkg_args, '--install', *pacman_args], env=env, cwd=cwd)) if __name__ == '__main__': + if os.getuid() == 0: + logger.fatal("Running as root isn't supported by makepkg, exiting") + sys.exit(1) main() -- cgit v1.2.3