1
0
mirror of https://gitlab.com/libvirt/libvirt-python.git synced 2025-08-03 08:21:58 +03:00

setup: switch away fron subprocess.Popen()

Adopt subprocess.check_output() as more modern and higher-level way to
invoke processes, checking that they succeed, and getting their output.

Signed-off-by: Pino Toscano <ptoscano@redhat.com>
This commit is contained in:
Pino Toscano
2023-09-25 11:56:24 +02:00
committed by Daniel P. Berrangé
parent bf83c2b236
commit 41363417b7

View File

@ -51,13 +51,9 @@ def get_pkgconfig_data(args, mod, required=True):
"""Run pkg-config to and return content associated with it""" """Run pkg-config to and return content associated with it"""
cmd = ["pkg-config"] + args + [mod] cmd = ["pkg-config"] + args + [mod]
with subprocess.Popen(cmd, output = subprocess.check_output(cmd, universal_newlines=True)
stdout=subprocess.PIPE, for line in output.splitlines():
stderr=subprocess.STDOUT, if line == "":
universal_newlines=True) as p:
line = p.stdout.readline()
if line is None or line == "":
if required: if required:
args_str = " ".join(args) args_str = " ".join(args)
raise Exception(f"Cannot determine '{args_str}' from " raise Exception(f"Cannot determine '{args_str}' from "
@ -205,14 +201,11 @@ class my_sdist(sdist):
authors = [] authors = []
cmd = ["git", "log", "--pretty=format:%aN <%aE>"] cmd = ["git", "log", "--pretty=format:%aN <%aE>"]
with subprocess.Popen(cmd, output = subprocess.check_output(cmd, universal_newlines=True)
stdout=subprocess.PIPE, for line in output.splitlines():
stderr=subprocess.DEVNULL, line = " " + line.strip()
universal_newlines=True) as p: if line not in authors:
for line in p.stdout: authors.append(line)
line = " " + line.strip()
if line not in authors:
authors.append(line)
authors.sort(key=str.lower) authors.sort(key=str.lower)
self._gen_from_in("AUTHORS.in", self._gen_from_in("AUTHORS.in",
@ -222,12 +215,9 @@ class my_sdist(sdist):
def gen_changelog(self): def gen_changelog(self):
cmd = ["git", "log", "--pretty=format:%H:%ct %an <%ae>%n%n%s%n%b%n"] cmd = ["git", "log", "--pretty=format:%H:%ct %an <%ae>%n%n%s%n%b%n"]
with open("ChangeLog", "w") as f_out, \ with open("ChangeLog", "w") as f_out:
subprocess.Popen(cmd, output = subprocess.check_output(cmd, universal_newlines=True)
stdout=subprocess.PIPE, for line in output.splitlines():
stderr=subprocess.DEVNULL,
universal_newlines=True) as p:
for line in p.stdout:
m = re.match(r"([a-f0-9]+):(\d+)\s(.*)", line) m = re.match(r"([a-f0-9]+):(\d+)\s(.*)", line)
if m: if m:
t = time.gmtime(int(m.group(2))) t = time.gmtime(int(m.group(2)))