Coding style.

- Using subprocess.run
This commit is contained in:
Andrew Hamilton 2018-03-24 16:34:49 +10:00
parent 5715ab8ea9
commit 320670bb43
6 changed files with 16 additions and 13 deletions

View file

@ -20,8 +20,11 @@ if pip_deps:
if pip3_deps:
dist_deps.add("python3-pip")
if dist_deps:
subprocess.check_call(["sudo", "apt-get", "-y", "install"] + list(dist_deps))
subprocess.run(["sudo", "apt-get", "-y", "install"] + list(dist_deps),
check=True)
if pip_deps:
subprocess.check_call(["sudo", "pip", "install"] + list(pip_deps))
subprocess.run(["sudo", "pip", "install"] + list(pip_deps),
check=True)
if pip3_deps:
subprocess.check_call(["sudo", "pip3", "install"] + list(pip3_deps))
subprocess.run(["sudo", "pip3", "install"] + list(pip3_deps),
check=True)

View file

@ -14,7 +14,7 @@ VIGIL_PATH = os.path.realpath(os.path.dirname(__file__))
def cmd(command):
subprocess.check_call(command, shell=True)
subprocess.run(command, shell=True, check=True)
def mount_squashfs_iso(iso, squashfs_path, mount_point):

View file

@ -33,7 +33,7 @@ def _show_differences(failed):
os.symlink(os.path.abspath(golden_file),
os.path.join(golden_dir, name))
diff_command = ["meld"] if shutil.which("meld") else ["diff", "-r"]
subprocess.call(diff_command + [actual_dir, golden_dir])
subprocess.run(diff_command + [actual_dir, golden_dir])
finally:
shutil.rmtree(temp_dir)

View file

@ -242,7 +242,7 @@ class ParseLsLineTestCase(unittest.TestCase):
def test_against_ls(root_path, environment):
process = subprocess.Popen(
process = subprocess.run(
["ls", "--color=always", "-R", root_path],
stdout=subprocess.PIPE, stderr=subprocess.PIPE, env=environment)
stdout, stderr = process.communicate()

View file

@ -712,9 +712,9 @@ class Screen:
scroll_position[1] + 1)
self._log.log_message([in_green("Editing "), path_colored,
in_green(' at line %s...' % line_num)])
subprocess.Popen("%s +%s %s" %
(self.editor_command, line_num, path), shell=True,
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
subprocess.run("%s +%s %s" %
(self.editor_command, line_num, path), shell=True,
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
def toggle_status_style(self):
self._summary.toggle_status_style(self._log)

View file

@ -108,8 +108,8 @@ def _fix_input(input_):
def _do_command(command, timeout=None, **kwargs):
stdout, stderr = "", ""
with contextlib.suppress(subprocess.CalledProcessError):
process = subprocess.Popen(command, stdout=subprocess.PIPE,
stderr=subprocess.PIPE, **kwargs)
process = subprocess.run(command, stdout=subprocess.PIPE,
stderr=subprocess.PIPE, **kwargs)
try:
stdout, stderr = process.communicate(timeout=timeout)
except subprocess.TimeoutExpired:
@ -122,8 +122,8 @@ def _run_command(command, success_status=Status.ok,
error_status=Status.problem):
status, output = success_status, ""
try:
process = subprocess.Popen(command, stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
process = subprocess.run(command, stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
stdout, stderr = process.communicate()
output = stdout + stderr
except subprocess.CalledProcessError: