Verified Commit 43001068 authored by Ansgar's avatar Ansgar

use subprocess module instead of commands module

parent bfc67494
......@@ -18,7 +18,7 @@ add his key to the GPGKeyring
# I know what I say. I dont know python and I wrote it. So go and read some other stuff.
from __future__ import print_function
import commands
import subprocess
import sys
import apt_pkg
......@@ -73,10 +73,12 @@ def main():
if not keyrings:
keyrings = get_active_keyring_paths()
cmd = "gpg --with-colons --no-secmem-warning --no-auto-check-trustdb --no-default-keyring %s --with-fingerprint --list-key %s" \
% (utils.gpg_keyring_args(keyrings),
Cnf["Add-User::Options::Key"])
(result, output) = commands.getstatusoutput(cmd)
cmd = ["gpg", "--with-colons", "--no-secmem-warning",
"--no-auto-check-trustdb", "--with-fingerprint",
"--no-default-keyring"]
cmd.extend(utils.gpg_keyring_args(keyrings).split())
cmd.extend(["--list-key", "--", Cnf["Add-User::Options::Key"]])
output = subprocess.check_output(cmd).rstrip()
m = re_gpg_fingerprint_colon.search(output)
if not m:
print(output)
......
......@@ -68,9 +68,10 @@ def spawn(command):
if Options["No-Action"]:
print("[%s]" % (command))
else:
(result, output) = commands.getstatusoutput(command)
if (result != 0):
utils.fubar("Invocation of '%s' failed:\n%s\n" % (command, output), result)
try:
subprocess.check_output(command.split(), stderr=subprocess.STDOUT)
except subprocess.CalledProcessError as e:
utils.fubar("Invocation of '%s' failed:\n%s\n" % (command, e.output.rstrip()), e.returncode)
##################### ! ! ! N O T E ! ! ! #####################
#
......
......@@ -41,11 +41,11 @@
from __future__ import absolute_import, print_function
import commands
import apt_pkg
import fcntl
import functools
import sqlalchemy.sql as sql
import subprocess
from re import sub
from collections import defaultdict
from .regexes import re_build_dep_arch
......@@ -331,7 +331,7 @@ def remove(session, reason, suites, removals,
@param whoami: The person (or entity) doing the removal. Defaults to utils.whoami()
@type date: string
@param date: The date of the removal. Defaults to commands.getoutput("date -R")
@param date: The date of the removal. Defaults to `date -R`
@type done_bugs: list
@param done_bugs: A list of bugs to be closed when doing this removal.
......@@ -375,7 +375,7 @@ def remove(session, reason, suites, removals,
whoami = utils.whoami()
if date is None:
date = commands.getoutput("date -R")
date = subprocess.check_output(["date", "-R"]).rstrip()
if partial and components:
......
......@@ -24,7 +24,6 @@
from __future__ import absolute_import, print_function
import commands
import codecs
import datetime
import os
......@@ -69,31 +68,6 @@ default_config = "/etc/dak/dak.conf" #: default dak config, defines host pro
alias_cache = None #: Cache for email alias checks
key_uid_email_cache = {} #: Cache for email addresses from gpg key uids
# Monkeypatch commands.getstatusoutput as it may not return the correct exit
# code in lenny's Python. This also affects commands.getoutput and
# commands.getstatus.
def dak_getstatusoutput(cmd):
pipe = daklib.daksubprocess.Popen(cmd, shell=True, universal_newlines=True,
stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
output = pipe.stdout.read()
pipe.wait()
if output[-1:] == '\n':
output = output[:-1]
ret = pipe.wait()
if ret is None:
ret = 0
return ret, output
commands.getstatusoutput = dak_getstatusoutput
################################################################################
......@@ -504,9 +478,11 @@ def send_mail(message, filename="", whitelists=None):
os.close(fd)
# Invoke sendmail
(result, output) = commands.getstatusoutput("%s < %s" % (Cnf["Dinstall::SendmailCommand"], filename))
if (result != 0):
raise SendmailFailedError(output)
try:
with open(filename, 'r') as fh:
subprocess.check_output(Cnf["Dinstall::SendmailCommand"].split(), stdin=fh, stderr=subprocess.STDOUT)
except subprocess.CalledProcessError as e:
raise SendmailFailedError(e.output.rstrip())
# Clean up any temporary files
if message:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment