diff options
Diffstat (limited to 'gd_diff.py')
-rw-r--r-- | gd_diff.py | 21 |
1 files changed, 21 insertions, 0 deletions
@@ -6,8 +6,12 @@ # gns-deb-diff is under the Public Domain. See # <https://creativecommons.org/publicdomain/zero/1.0> +import shlex import sys +from subprocess import run, PIPE + + # list of recognized fields. field_list = [ "Change-Type", @@ -28,6 +32,23 @@ def read_file(fpath): 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`. |