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