Verified Commit a62e1b65 authored by Ansgar's avatar Ansgar

Merge branches 'use-subprocess-instead-of-commands' and 'py3-cleanup-1'

Pipeline #43831 passed with stages
in 15 minutes and 55 seconds
......@@ -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)
......
......@@ -340,13 +340,13 @@ def check_timestamps():
if os.access(filename, os.R_OK):
f = utils.open_file(filename)
current_file = filename
sys.stderr.write("Processing %s.\n" % (filename))
print("Processing %s." % (filename), file=sys.stderr)
apt_inst.debExtract(f, Ent, "control.tar.gz")
f.seek(0)
apt_inst.debExtract(f, Ent, "data.tar.gz")
count += 1
print("Checked %d files (out of %d)." % (count, len(db_files.keys())))
print("Checked %d files (out of %d)." % (count, len(db_files)))
################################################################################
......
......@@ -225,9 +225,9 @@ def export_files(session, archive, clpool, progress=False):
stats['unpack'] += 1
if progress:
if stats['unpack'] % 100 == 0:
sys.stderr.write('%d packages unpacked\n' % stats['unpack'])
print('%d packages unpacked' % stats['unpack'], file=sys.stderr)
elif stats['unpack'] % 10 == 0:
sys.stderr.write('.')
print('.', end='', file=sys.stderr)
for file in files:
for f in glob(os.path.join(tempdir, 'debian', '*%s' % file)):
for s in unpack[p][1]:
......
......@@ -170,7 +170,7 @@ SELECT
if Options["Print"]:
for package in sorted(maintainers):
sys.stdout.write(format(package, maintainers[package]))
print(format(package, maintainers[package]), end='')
else:
maintainer_file = open('Maintainers', 'w')
uploader_file = open('Uploaders', 'w')
......
......@@ -123,7 +123,7 @@ def main():
print("Skipping %s as it is marked as untouchable" % suite.suite_name)
continue
sys.stderr.write("Processing %s...\n" % (suite.suite_name))
print("Processing %s..." % (suite.suite_name), file=sys.stderr)
override_suite = suite.overridecodename or suite.codename
for component in session.query(Component).all():
......
......@@ -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 ! ! ! #####################
#
......
......@@ -777,7 +777,7 @@ def end():
sets = "set"
if accept_count > 1:
sets = "sets"
sys.stderr.write("Accepted %d package %s, %s.\n" % (accept_count, sets, utils.size_type(int(accept_bytes))))
print("Accepted %d package %s, %s." % (accept_count, sets, utils.size_type(int(accept_bytes))), file=sys.stderr)
Logger.log(["total", accept_count, accept_bytes])
if not Options["No-Action"] and not Options["Trainee"]:
......@@ -832,7 +832,7 @@ def main():
readline.parse_and_bind("tab: complete")
if len(uploads) > 1:
sys.stderr.write("Sorting changes...\n")
print("Sorting changes...", file=sys.stderr)
uploads = sort_uploads(new_queue, uploads, session, Options["No-Binaries"])
if Options["Comments"]:
......
......@@ -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
################################################################################
......@@ -131,18 +105,14 @@ def open_file(filename, mode='r'):
def our_raw_input(prompt=""):
if prompt:
while 1:
try:
sys.stdout.write(prompt)
break
except IOError:
pass
print(prompt, end='')
# TODO: py3: use `print(..., flush=True)`
sys.stdout.flush()
try:
ret = raw_input()
return ret
except EOFError:
sys.stderr.write("\nUser interrupt (^D).\n")
print("\nUser interrupt (^D).", file=sys.stderr)
raise SystemExit
################################################################################
......@@ -189,7 +159,7 @@ def parse_deb822(armored_contents, signing_rules=0, keyrings=None, session=None)
index += 1
indexed_lines[index] = line[:-1]
num_of_lines = len(indexed_lines.keys())
num_of_lines = len(indexed_lines)
index = 0
first = -1
while index < num_of_lines:
......@@ -504,9 +474,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:
......@@ -607,12 +579,12 @@ def TemplateSubst(subst_map, filename):
def fubar(msg, exit_code=1):
sys.stderr.write("E: %s\n" % (msg))
print("E:", msg, file=sys.stderr)
sys.exit(exit_code)
def warn(msg):
sys.stderr.write("W: %s\n" % (msg))
print("W:", msg, file=sys.stderr)
################################################################################
......
......@@ -5,6 +5,8 @@
# Author: Filippo Giunchedi <filippo@debian.org>
# Version: 0.5
from __future__ import print_function
import cgi
import os
import os.path
......@@ -110,7 +112,7 @@ def parse_leave_reason(fname):
try:
f = open(fname)
except IOError as e:
sys.stderr.write("Can't open %s: %s\n" % (fname, e))
print("Can't open %s: %s" % (fname, e), file=sys.stderr)
return {}
res = {}
......@@ -195,12 +197,12 @@ if __name__ == "__main__":
(settings, args) = parser.parse_args()
if not os.path.exists(settings.outdir):
sys.stderr.write("Outdir '%s' does not exists\n" % settings.outdir)
print("Outdir '%s' does not exists" % settings.outdir, file=sys.stderr)
parser.print_help()
sys.exit(1)
if not os.path.exists(settings.datadir):
sys.stderr.write("Datadir '%s' does not exists\n" % settings.datadir)
print("Datadir '%s' does not exists" % settings.datadir, file=sys.stderr)
parser.print_help()
sys.exit(1)
......@@ -225,7 +227,7 @@ if __name__ == "__main__":
status.feed_in.write_xml(file(feed_in_file, "w+"), "utf-8")
status.feed_out.write_xml(file(feed_out_file, "w+"), "utf-8")
except IOError as why:
sys.stderr.write("Unable to write feeds: %s\n" % why)
print("Unable to write feeds:", why, file=sys.stderr)
sys.exit(1)
status.queue = current_queue
......@@ -233,7 +235,7 @@ if __name__ == "__main__":
try:
cPickle.dump(status, open(status_db, "w+"))
except IOError as why:
sys.stderr.write("Unable to save status: %s\n" % why)
print("Unable to save status:", why, file=sys.stderr)
sys.exit(1)
# vim:et:ts=4
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