mirror of
https://git.launchpad.net/ubuntu-dev-tools
synced 2025-04-18 05:41:08 +00:00
simplify subprocess usage
This commit is contained in:
parent
463d1f63a8
commit
b5ae0bdca3
@ -27,7 +27,9 @@ import os
|
||||
import re
|
||||
import shutil
|
||||
import sys
|
||||
from subprocess import call, check_call, Popen, PIPE
|
||||
|
||||
from subprocess import call, check_call, run, Popen, PIPE, DEVNULL
|
||||
|
||||
from tempfile import mkdtemp
|
||||
|
||||
from debian.changelog import Changelog
|
||||
@ -85,9 +87,8 @@ def gen_debdiff(tmpdir, changelog):
|
||||
|
||||
debdiff = os.path.join(tmpdir, '%s_%s.debdiff' % (pkg, newver))
|
||||
|
||||
devnull = open('/dev/null', 'w')
|
||||
diff_cmd = ['bzr', 'diff', '-r', 'tag:' + str(oldver)]
|
||||
if call(diff_cmd, stdout=devnull, stderr=devnull) == 1:
|
||||
if call(diff_cmd, stdout=DEVNULL, stderr=DEVNULL) == 1:
|
||||
print("Extracting bzr diff between %s and %s" % (oldver, newver))
|
||||
else:
|
||||
if oldver.epoch is not None:
|
||||
@ -104,14 +105,10 @@ def gen_debdiff(tmpdir, changelog):
|
||||
print("Generating debdiff between %s and %s" % (oldver, newver))
|
||||
diff_cmd = ['debdiff', olddsc, newdsc]
|
||||
|
||||
diff = Popen(diff_cmd, stdout=PIPE)
|
||||
debdiff_f = open(debdiff, 'w')
|
||||
filterdiff = Popen(['filterdiff', '-x', '*changelog*'],
|
||||
stdin=diff.stdout, stdout=debdiff_f)
|
||||
diff.stdout.close()
|
||||
filterdiff.wait()
|
||||
debdiff_f.close()
|
||||
devnull.close()
|
||||
with Popen(diff_cmd, stdout=PIPE, encoding='utf-8') as diff:
|
||||
with open(debdiff, 'w', encoding='utf-8') as debdiff_f:
|
||||
run(['filterdiff', '-x', '*changelog*'],
|
||||
stdin=diff.stdout, stdout=debdiff_f, encoding='utf-8')
|
||||
|
||||
return debdiff
|
||||
|
||||
|
10
ubuntu-iso
10
ubuntu-iso
@ -27,15 +27,15 @@ import sys
|
||||
|
||||
def extract(iso, path):
|
||||
command = ['isoinfo', '-R', '-i', iso, '-x', path]
|
||||
pipe = subprocess.Popen(command, stdout=subprocess.PIPE,
|
||||
stderr=subprocess.PIPE, encoding='utf-8')
|
||||
stdout, stderr = pipe.communicate()
|
||||
pipe = subprocess.run(command, encoding='utf-8',
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=subprocess.PIPE)
|
||||
|
||||
if pipe.returncode != 0:
|
||||
sys.stderr.write(stderr)
|
||||
sys.stderr.write(pipe.stderr)
|
||||
sys.exit(pipe.returncode)
|
||||
|
||||
return stdout
|
||||
return pipe.stdout
|
||||
|
||||
|
||||
def main():
|
||||
|
@ -34,8 +34,7 @@ class Builder(object):
|
||||
def __init__(self, name):
|
||||
self.name = name
|
||||
cmd = ["dpkg-architecture", "-qDEB_BUILD_ARCH_CPU"]
|
||||
self.architecture = subprocess.check_output(
|
||||
cmd, encoding='utf-8').strip()
|
||||
self.architecture = subprocess.check_output(cmd, encoding='utf-8').strip()
|
||||
|
||||
def _build_failure(self, returncode, dsc_file):
|
||||
if returncode != 0:
|
||||
@ -124,9 +123,8 @@ class Sbuild(Builder):
|
||||
def update(self, dist):
|
||||
cmd = ["schroot", "--list"]
|
||||
Logger.command(cmd)
|
||||
process = subprocess.Popen(
|
||||
cmd, stdout=subprocess.PIPE, encoding='utf-8')
|
||||
chroots, _ = process.communicate()[0].strip().split()
|
||||
process = subprocess.run(cmd, stdout=subprocess.PIPE, encoding='utf-8')
|
||||
chroots, _ = process.stdout.strip().split()
|
||||
if process.returncode != 0:
|
||||
return process.returncode
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user