Skip to content
Commits on Source (29)
......@@ -6,3 +6,4 @@ omit =
*/dist-packages/*
*/tests/*
source = .
concurrency = multiprocessing
*.pyc
*~
.coverage
.coverage.*.*
.idea
.cache
cover/
web/epydoc/
web/d-i
......@@ -27,3 +30,11 @@ web/transitions.yaml
web/cruft-report-daily.txt
web/pseudo-packages.*
web/licenses/
tests/fixtures/packages/*.buildinfo
tests/fixtures/packages/*.tar.*
tests/fixtures/packages/*.deb
tests/fixtures/packages/*.dsc
tests/fixtures/packages/**/.debhelper
tests/fixtures/packages/**/*.debhelper.log
tests/fixtures/packages/**/*.substvars
......@@ -30,7 +30,7 @@ pages:
- apt-get update
- apt-get install -y python-epydoc
- mkdir -p public/epydoc
- epydoc -q --html --graph all --css blue -n DAK -o public/epydoc --include-log --show-imports dak dakweb
- epydoc -q --html --graph all --css white -n DAK -o public/epydoc --include-log --show-imports dak dakweb
- mv coverage public/coverage
stage: deploy
artifacts:
......
......@@ -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)
......
......@@ -54,6 +54,15 @@ def die_arglen(args, args_needed, msg):
die(msg)
def get_suite_or_die(suite_name, session=None, error_message=None):
suite = get_suite(suite_name.lower(), session=session)
if suite is None:
if error_message is None:
error_message = "E: Invalid/unknown suite %(suite_name)s"
die(error_message % {'suite_name': suite_name})
return suite
def usage(exit_code=0):
"""Perform administrative work on the dak database."""
......@@ -340,9 +349,7 @@ def __suite_show(d, args):
die("E: showing an suite entry requires a suite")
s = d.session()
su = get_suite(args[2].lower())
if su is None:
die("E: can't find suite entry for %s" % (args[2].lower()))
su = get_suite_or_die(args[2])
print(su.details())
......@@ -410,9 +417,7 @@ def __suite_rm(d, args):
if not dryrun:
try:
s = d.session()
su = get_suite(name.lower())
if su is None:
die("E: Cannot find suite {0}".format(name))
su = get_suite_or_die(name, s)
s.delete(su)
s.commit()
except IntegrityError as e:
......@@ -518,9 +523,7 @@ def __suite_architecture_list(d, args):
def __suite_architecture_listarch(d, args):
die_arglen(args, 3, "E: suite-architecture list-arch requires a suite")
suite = get_suite(args[2].lower(), d.session())
if suite is None:
die('E: suite %s is invalid' % args[2].lower())
suite = get_suite_or_die(args[2], d.session())
a = suite.get_architectures(skipsrc=True, skipall=True)
for j in a:
print(j.arch_string)
......@@ -541,9 +544,7 @@ def __suite_architecture_add(d, args):
s = d.session()
suite = get_suite(args[2].lower(), s)
if suite is None:
die("E: Can't find suite %s" % args[2].lower())
suite = get_suite_or_die(args[2], s)
for arch_name in args[3:]:
arch = get_architecture(arch_name.lower(), s)
......@@ -574,9 +575,7 @@ def __suite_architecture_rm(d, args):
if not dryrun:
try:
suite_name = args[2].lower()
suite = get_suite(suite_name, s)
if suite is None:
die('E: no such suite %s' % suite_name)
suite = get_suite_or_die(suite_name, s)
arch_string = args[3].lower()
architecture = get_architecture(arch_string, s)
if architecture not in suite.architectures:
......@@ -630,9 +629,7 @@ def __suite_component_list(d, args):
def __suite_component_listcomponent(d, args):
die_arglen(args, 3, "E: suite-component list-component requires a suite")
suite = get_suite(args[2].lower(), d.session())
if suite is None:
die('E: suite %s is invalid' % args[2].lower())
suite = get_suite_or_die(args[2], d.session())
for c in suite.components:
print(c.component_name)
......@@ -652,9 +649,7 @@ def __suite_component_add(d, args):
s = d.session()
suite = get_suite(args[2].lower(), s)
if suite is None:
die("E: Can't find suite %s" % args[2].lower())
suite = get_suite_or_die(args[2], s)
for component_name in args[3:]:
component = get_component(component_name.lower(), s)
......@@ -684,9 +679,7 @@ def __suite_component_rm(d, args):
if not dryrun:
try:
suite_name = args[2].lower()
suite = get_suite(suite_name, s)
if suite is None:
die('E: no such suite %s' % suite_name)
suite = get_suite_or_die(suite_name, s)
component_string = args[3].lower()
component = get_component(arch_string, s)
if component not in suite.components:
......@@ -762,7 +755,7 @@ def __suite_config_get(d, args):
die_arglen(args, 4, "E: suite-config get needs the name of a configuration")
session = d.session()
suite_name = args[2]
suite = get_suite(suite_name, session)
suite = get_suite_or_die(suite_name, session)
for arg in args[3:]:
if arg not in ALLOWED_SUITE_CONFIGS:
die("Unknown (or unsupported) suite configuration variable")
......@@ -774,7 +767,7 @@ def __suite_config_set(d, args):
die_arglen(args, 4, "E: suite-config set needs the name of a configuration")
session = d.session()
suite_name = args[2]
suite = get_suite(suite_name, session)
suite = get_suite_or_die(suite_name, session)
for arg in args[3:]:
if '=' not in arg:
die("Missing value for configuration %s: Use key=value format" % arg)
......@@ -806,7 +799,7 @@ def __suite_config_list(d, args):
warn("W: Ignoring extra argument after the suite name")
if len(args) == 3:
suite_name = args[2]
suite = get_suite(suite_name, session)
suite = get_suite_or_die(suite_name, session)
else:
print("Valid suite-config options managable by this command:")
print()
......@@ -941,12 +934,10 @@ def __version_check_list_suite(d, suite_name):
def __version_check_add(d, suite_name, check, reference_name):
suite = get_suite(suite_name)
if not suite:
die("E: Could not find suite %s." % (suite_name))
reference = get_suite(reference_name)
if not reference:
die("E: Could not find reference suite %s." % (reference_name))
suite = get_suite_or_die(suite_name,
error_message="E: Could not find suite %(suite_name)s")
reference = get_suite_or_die(reference_name,
error_message="E: Could not find reference suite %(suite_name)s")
session = d.session()
vc = VersionCheck()
......@@ -958,12 +949,10 @@ def __version_check_add(d, suite_name, check, reference_name):
def __version_check_rm(d, suite_name, check, reference_name):
suite = get_suite(suite_name)
if not suite:
die("E: Could not find suite %s." % (suite_name))
reference = get_suite(reference_name)
if not reference:
die("E: Could not find reference suite %s." % (reference_name))
suite = get_suite_or_die(suite_name,
error_message="E: Could not find suite %(suite_name)s")
reference = get_suite_or_die(reference_name,
error_message="E: Could not find reference suite %(suite_name)s")
session = d.session()
try:
......@@ -1224,7 +1213,7 @@ def main():
subcommand = str(arguments[0])
if subcommand in dispatch.keys():
if subcommand in dispatch:
dispatch[subcommand](arguments)
else:
die("E: Unknown command")
......
......@@ -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)))
################################################################################
......
......@@ -126,7 +126,7 @@ def britney_changelog(packages, suite, session):
new = {}
for p in current.keys():
if p in old.keys():
if p in old:
if apt_pkg.version_compare(current[p], old[p]) > 0:
new[p] = [current[p], old[p]]
else:
......
......@@ -99,6 +99,7 @@ def do_anais(architecture, binaries_list, source, session):
if architecture == "any" or architecture == "all":
return ""
version_sort_key = functools.cmp_to_key(apt_pkg.version_compare)
anais_output = ""
architectures = {}
for arch in architecture.split():
......@@ -116,7 +117,7 @@ def do_anais(architecture, binaries_list, source, session):
version = i[1]
if arch in architectures:
versions.append(version)
versions.sort(key=functools.cmp_to_key(apt_pkg.version_compare))
versions.sort(key=version_sort_key)
if versions:
latest_version = versions.pop()
else:
......@@ -132,11 +133,8 @@ def do_anais(architecture, binaries_list, source, session):
if versions_d != {}:
anais_output += "\n (*) %s_%s [%s]: %s\n" % (binary, latest_version, source, architecture)
versions = versions_d.keys()
versions.sort(key=functools.cmp_to_key(apt_pkg.version_compare))
for version in versions:
arches = versions_d[version]
arches.sort()
for version in sorted(versions_d, key=version_sort_key):
arches = sorted(versions_d[version])
anais_output += " o %s: %s\n" % (version, ", ".join(arches))
return anais_output
......@@ -318,18 +316,15 @@ def do_dubious_nbs(dubious_nbs):
print("-----------")
print()
dubious_nbs_keys = dubious_nbs.keys()
dubious_nbs_keys.sort()
for source in dubious_nbs_keys:
version_sort_key = functools.cmp_to_key(apt_pkg.version_compare)
for source in sorted(dubious_nbs):
print(" * %s_%s builds: %s" % (source,
source_versions.get(source, "??"),
source_binaries.get(source, "(source does not exist)")))
print(" won't admit to building:")
versions = dubious_nbs[source].keys()
versions.sort(key=functools.cmp_to_key(apt_pkg.version_compare))
versions = sorted(dubious_nbs[source], key=version_sort_key)
for version in versions:
packages = dubious_nbs[source][version].keys()
packages.sort()
packages = sorted(dubious_nbs[source][version])
print(" o %s: %s" % (version, ", ".join(packages)))
print()
......@@ -676,11 +671,10 @@ def main():
# Distinguish dubious (version numbers match) and 'real' NBS (they don't)
dubious_nbs = {}
for source in nbs.keys():
for package in nbs[source].keys():
versions = nbs[source][package].keys()
versions.sort(key=functools.cmp_to_key(apt_pkg.version_compare))
latest_version = versions.pop()
version_sort_key = functools.cmp_to_key(apt_pkg.version_compare)
for source in nbs:
for package in nbs[source]:
latest_version = max(nbs[source][package], key=version_sort_key)
source_version = source_versions.get(source, "0")
if apt_pkg.version_compare(latest_version, source_version) == 0:
add_nbs(dubious_nbs, source, latest_version, package, suite_id, session)
......@@ -704,11 +698,8 @@ def main():
print("Unbuilt binary packages")
print("-----------------------")
print()
keys = bin_not_built.keys()
keys.sort()
for source in keys:
binaries = bin_not_built[source].keys()
binaries.sort()
for source in sorted(bin_not_built):
binaries = sorted(bin_not_built[source])
print(" o %s: %s" % (source, ", ".join(binaries)))
print()
......
......@@ -52,6 +52,8 @@ import sys
import apt_pkg
import shutil
import subprocess
import tarfile
import tempfile
import threading
from daklib import utils
......@@ -60,7 +62,7 @@ from daklib.dbconn import DBConn, get_component_by_package_suite
from daklib.gpg import SignedFile
from daklib.regexes import html_escaping, re_html_escaping, re_version, re_spacestrip, \
re_contrib, re_nonfree, re_localhost, re_newlinespace, \
re_package, re_doc_directory
re_package, re_doc_directory, re_file_binary
from daklib.dak_exceptions import ChangesUnicodeError
import daklib.daksubprocess
......@@ -335,13 +337,13 @@ def read_changes_or_dsc(suite, filename, session=None):
if use_html:
dsc[k] = formatted_text(dsc[k], strip=True)
else:
dsc[k] = ('\n' + '\n'.join(map(lambda x: ' ' + x, dsc[k].split('\n')))).rstrip()
dsc[k] = ('\n' + '\n'.join(' ' + x for x in dsc[k].split('\n'))).rstrip()
else:
dsc[k] = escape_if_needed(dsc[k])
keysinorder = filter(lambda x: not x.lower().startswith('checksums-'), keysinorder)
filecontents = '\n'.join(map(lambda x: format_field(x, dsc[x.lower()]), keysinorder)) + '\n'
filecontents = '\n'.join(format_field(x, dsc[x.lower()])
for x in keysinorder if not x.lower().startswith('checksums-')
) + '\n'
return filecontents
......@@ -511,22 +513,43 @@ def do_lintian(filename):
return do_command(cmd, escaped=True)
def extract_one_file_from_deb(deb_filename, match):
with tempfile.TemporaryFile() as tmpfh:
dpkg_cmd = ('dpkg-deb', '--fsys-tarfile', deb_filename)
daklib.daksubprocess.check_call(dpkg_cmd, stdout=tmpfh)
tmpfh.seek(0)
with tarfile.open(fileobj=tmpfh, mode="r") as tar:
matched_member = None
for member in tar:
if member.isfile() and match.match(member.name):
matched_member = member
break
if not matched_member:
return None, None
fh = tar.extractfile(matched_member)
matched_data = fh.read()
fh.close()
return matched_member.name, matched_data
def get_copyright(deb_filename):
global printed
package = re_package.sub(r'\1', os.path.basename(deb_filename))
o = os.popen("dpkg-deb -c %s | egrep 'usr(/share)?/doc/[^/]*/copyright' | awk '{print $6}' | head -n 1" % (deb_filename))
cright = o.read()[:-1]
re_copyright = re.compile(r"\./usr(/share)?/doc/(?P<package>[^/]+)/copyright")
cright_path, cright = extract_one_file_from_deb(deb_filename, re_copyright)
if cright == "":
if not cright_path:
return formatted_text("WARNING: No copyright found, please check package manually.")
doc_directory = re_doc_directory.sub(r'\1', cright)
package = re_file_binary.match(os.path.basename(deb_filename)).group('package')
doc_directory = re_copyright.match(cright_path).group('package')
if package != doc_directory:
return formatted_text("WARNING: wrong doc directory (expected %s, got %s)." % (package, doc_directory))
o = os.popen("dpkg-deb --fsys-tarfile %s | tar xvOf - %s 2>/dev/null" % (deb_filename, cright))
cright = o.read()
copyrightmd5 = hashlib.md5(cright).hexdigest()
res = ""
......@@ -539,12 +562,13 @@ def get_copyright(deb_filename):
def get_readme_source(dsc_filename):
# TODO: py3: use tempfile.TemporaryDirectory
tempdir = utils.temp_dirname()
os.rmdir(tempdir)
targetdir = os.path.join(tempdir, "source")
cmd = ('dpkg-source', '--no-check', '--no-copy', '-x', dsc_filename, tempdir)
cmd = ('dpkg-source', '--no-check', '--no-copy', '-x', dsc_filename, targetdir)
try:
daklib.daksubprocess.check_output(cmd, stderr=1)
daklib.daksubprocess.check_output(cmd, stderr=subprocess.STDOUT)
except subprocess.CalledProcessError as e:
res = "How is education supposed to make me feel smarter? Besides, every time I learn something new, it pushes some\n old stuff out of my brain. Remember when I took that home winemaking course, and I forgot how to drive?\n"
res += "Error, couldn't extract source, WTF?\n"
......@@ -552,10 +576,11 @@ def get_readme_source(dsc_filename):
res += e.output
return res
path = os.path.join(tempdir, 'debian/README.source')
path = os.path.join(targetdir, 'debian/README.source')
res = ""
if os.path.exists(path):
res += do_command(["cat", "--", path])
with open(path, 'r') as fh:
res += formatted_text(fh.read())
else:
res += "No README.source in this package\n\n"
......
......@@ -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]:
......@@ -253,7 +253,7 @@ def export_files(session, archive, clpool, progress=False):
files = [f for f in files if f != filelist]
if len(files):
if root != clpool:
if root.split('/')[-1] not in sources.keys():
if root.split('/')[-1] not in sources:
if os.path.exists(root):
stats['removed'] += len(os.listdir(root))
rmtree(root)
......
......@@ -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"]:
......
......@@ -212,13 +212,12 @@ def get_upload_data(changesfn):
def list_uploads(filelist, rrd_dir):
uploads = map(get_upload_data, filelist)
uploads.sort()
uploads = sorted(get_upload_data(x) for x in filelist)
# print the summary page
print(header())
if uploads:
print(table_header())
print(''.join(map(lambda x: table_row(*x[1:6]), uploads)).encode('utf-8'))
print(''.join(table_row(*x[1:6]) for x in uploads).encode('utf-8'))
print(table_footer())
else:
print('<h1>Currently no deferred uploads to Debian</h1>')
......@@ -306,11 +305,10 @@ def main():
filelist = []
for r, d, f in os.walk(Cnf["Show-Deferred::DeferredQueue"]):
filelist += map(lambda x: os.path.join(r, x),
filter(lambda x: x.endswith('.changes'), f))
filelist.extend(os.path.join(r, x) for x in f if x.endswith('.changes'))
list_uploads(filelist, rrd_dir)
available_changes = set(map(os.path.basename, filelist))
available_changes = set(os.path.basename(x) for x in filelist)
if "Show-Deferred::LinkPath" in Cnf:
# remove dead links
for r, d, f in os.walk(Cnf["Show-Deferred::LinkPath"]):
......
......@@ -165,7 +165,7 @@ Updates dak's database schema to the lastest version. You should disable crontab
database_revision = 0
dbfiles = glob(os.path.join(os.path.dirname(__file__), 'dakdb/update*.py'))
required_database_schema = max(map(int, findall(r'update(\d+).py', " ".join(dbfiles))))
required_database_schema = max(int(x) for x in findall(r'update(\d+).py', " ".join(dbfiles)))
print("dak database schema at %d" % database_revision)
print("dak version requires schema %d" % required_database_schema)
......
......@@ -27,31 +27,41 @@ from daklib.utils import mail_addresses_for_upload, TemplateSubst, send_mail
class ProcessedUpload(object):
"""Contains data of a processed upload.
"""
# people
maintainer = None
changed_by = None
fingerprint = None
maintainer = None #: Maintainer: field contents
changed_by = None #: Changed-By: field contents
fingerprint = None #: Fingerprint of upload signer
# suites
suites = []
from_policy_suites = []
suites = [] #: Destination suites
from_policy_suites = [] #: Policy suites
# package
changes = None
changes_filename = None
sourceful = None
source = None
architecture = None
version = None
bugs = None
changes = None #: Contents of .changes file from upload
changes_filename = None #: Changes Filename
sourceful = None #: Did upload contain source
source = None #: Source value from changes
architecture = None #: Architectures from changes
version = None #: Version from changes
bugs = None #: Bugs closed in upload
# program
program = "unknown-program"
program = "unknown-program" #: Which dak program was in use
warnings = []
warnings = [] #: Eventual warnings for upload
def _subst_for_upload(upload):
""" Prepare substitutions used for announce mails.
@type upload: L{daklib.upload.Source} or L{daklib.upload.Binary}
@param upload: upload to handle
@rtype: dict
@returns: A dict of substition values for use by L{daklib.utils.TemplateSubst}
"""
cnf = Config()
maintainer = upload.maintainer or cnf['Dinstall::MyEmailAddress']
......@@ -98,6 +108,17 @@ def _whitelists(upload):
def announce_reject(upload, reason, rejected_by=None):
""" Announce a reject.
@type upload: L{daklib.upload.Source} or L{daklib.upload.Binary}
@param upload: upload to handle
@type reason: string
@param reason: Reject reason
@type rejected_by: string
@param rejected_by: Who is doing the reject.
"""
cnf = Config()
subst = _subst_for_upload(upload)
whitelists = _whitelists(upload)
......@@ -118,6 +139,12 @@ def announce_reject(upload, reason, rejected_by=None):
def announce_accept(upload):
""" Announce an upload.
@type upload: L{daklib.upload.Source} or L{daklib.upload.Binary}
@param upload: upload to handle
"""
cnf = Config()
subst = _subst_for_upload(upload)
whitelists = _whitelists(upload)
......@@ -171,6 +198,12 @@ def announce_accept(upload):
def announce_new(upload):
""" Announce an upload going to NEW.
@type upload: L{daklib.upload.Source} or L{daklib.upload.Binary}
@param upload: upload to handle
"""
cnf = Config()
subst = _subst_for_upload(upload)
whitelists = _whitelists(upload)
......
......@@ -60,7 +60,7 @@ re_srchasver = re.compile(r"^(\S+)\s+\((\S+)\)$")
re_verwithext = re.compile(r"^(\d+)(?:\.(\d+))(?:\s+\((\S+)\))?$")
html_escaping = {'"': '&quot;', '&': '&amp;', '<': '&lt;', '>': '&gt;'}
re_html_escaping = re.compile('|'.join(map(re.escape, html_escaping.keys())))
re_html_escaping = re.compile('|'.join(re.escape(x) for x in html_escaping))
# From clean_proposed_updates.py
re_isdeb = re.compile(r"^(.+)_(.+?)_(.+?).u?deb$")
......
......@@ -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)
################################################################################
......