#!/usr/bin/env python3 # -*- coding: utf-8 -*- # # This file is part of gns-deb-diff. # # gns-deb-diff is under the Public Domain. See # import shlex import sys from subprocess import run, PIPE # list of recognized fields. field_list = [ "Change-Type", "Changed-From-Debian", ] def read_file(fpath): """Read file `f` and return its content. """ try: f = open(fpath, 'r') except FileNotFoundError as e: print("Error opening '%s' \n Error Info:\n %r" % (fpath, e), file=sys.stderr) sys.exit(1) return f.read() def execute(cmd, out=None, err=None): """Run `cmd`. Returns an instance of `subprocess.CompletedProcess` `cmd` must be a string containing the command to run. """ cmd = shlex.split(cmd) try: completed_process = run(cmd, stdout=out, stderr=err) except (FileNotFoundError, OSError, ValueError) as e: print("Error running '%s'\n Error Info:\n %r" % (cmd[0], e), file=sys.stderr) sys.exit(1) return completed_process def get_packages(pkgs_file): """Return an iterator contaning of package names from `pkgs_file`. """ pkgs = read_file(pkgs_file).split('\n') # sanitize pkgs_iter = map(lambda x: x.strip(), pkgs) return pkgs_iter