launchpad-reviewers team mailing list archive
-
launchpad-reviewers team
-
Mailing list archive
-
Message #05135
[Merge] lp:~wgrant/launchpad/trim-dak-utils into lp:launchpad
William Grant has proposed merging lp:~wgrant/launchpad/trim-dak-utils into lp:launchpad.
Requested reviews:
Launchpad code reviewers (launchpad-reviewers)
For more details, see:
https://code.launchpad.net/~wgrant/launchpad/trim-dak-utils/+merge/77629
dak_utils, as the name suggests, is a holdover from some old dak code we imported. Only a few bits of it are used, most of which have more modern Python or Launchpad equivalents. This branch weans the few remaining callsites off it, and deletes it.
--
https://code.launchpad.net/~wgrant/launchpad/trim-dak-utils/+merge/77629
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~wgrant/launchpad/trim-dak-utils into lp:launchpad.
=== modified file 'scripts/ftpmaster-tools/archive-integrity-check.py'
--- scripts/ftpmaster-tools/archive-integrity-check.py 2010-04-27 19:48:39 +0000
+++ scripts/ftpmaster-tools/archive-integrity-check.py 2011-09-30 01:25:31 +0000
@@ -11,11 +11,10 @@
import os
import stat
import sys
+from tempfile import NamedTemporaryFile
import apt_pkg
-import dak_utils
-
################################################################################
Filelist = None
@@ -68,14 +67,14 @@
sys.stdout.write("Checking %s/%s/source: " % (suite, component))
sys.stdout.flush()
# apt_pkg.ParseTagFile needs a real file handle and can't handle a GzipFile instance...
- temp_filename = dak_utils.temp_filename()
+ sources = NamedTemporaryFile()
(result, output) = commands.getstatusoutput("gunzip -c %s > %s" \
% (sources_filename,
- temp_filename))
+ sources.name))
if (result != 0):
sys.stderr.write("Gunzip invocation failed!\n%s\n" % (output))
sys.exit(result)
- sources = open(temp_filename)
+ sources.seek(0)
Sources = apt_pkg.ParseTagFile(sources)
while Sources.Step():
directory = Sources.Section.Find('Directory')
@@ -87,7 +86,6 @@
sys.stdout.write("done.\n")
sys.stdout.flush()
sources.close()
- os.unlink(temp_filename)
################################################################################
@@ -98,14 +96,14 @@
sys.stdout.write("Checking %s/%s/%s: " % (suite, component, architecture))
sys.stdout.flush()
# apt_pkg.ParseTagFile needs a real file handle and can't handle a GzipFile instance...
- temp_filename = dak_utils.temp_filename()
+ packages = NamedTemporaryFile()
(result, output) = commands.getstatusoutput("gunzip -c %s > %s"
% (packages_filename,
- temp_filename))
+ packages.name))
if (result != 0):
sys.stderr.write("Gunzip invocation failed!\n%s\n" % (output))
sys.exit(result)
- packages = open(temp_filename)
+ packages.seek(0)
Packages = apt_pkg.ParseTagFile(packages)
while Packages.Step():
md5sum_expected = Packages.Section.Find('MD5sum')
@@ -117,7 +115,6 @@
sys.stdout.write("done.\n")
sys.stdout.flush()
packages.close()
- os.unlink(temp_filename)
################################################################################
=== removed file 'scripts/ftpmaster-tools/dak_utils.py'
--- scripts/ftpmaster-tools/dak_utils.py 2010-04-27 19:48:39 +0000
+++ scripts/ftpmaster-tools/dak_utils.py 1970-01-01 00:00:00 +0000
@@ -1,181 +0,0 @@
-#!/usr/bin/python
-
-# Utility functions from the dak suite
-# Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006 James Troup <james@xxxxxxxxxx>
-
-################################################################################
-
-# This program is free software; you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation; either version 2 of the License, or
-# (at your option) any later version.
-
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-
-################################################################################
-
-import os
-import pwd
-import re
-import sys
-import tempfile
-
-################################################################################
-
-re_single_line_field = re.compile(r"^(\S*)\s*:\s*(.*)")
-re_multi_line_field = re.compile(r"^\s(.*)")
-re_no_epoch = re.compile(r"^\d+\:")
-re_extract_src_version = re.compile(r"(\S+)\s*\((.*)\)")
-
-################################################################################
-
-def fubar(msg, exit_code=1):
- sys.stderr.write("E: %s\n" % (msg))
- sys.exit(exit_code)
-
-def warn(msg):
- sys.stderr.write("W: %s\n" % (msg))
-
-################################################################################
-
-def prefix_multi_line_string(str, prefix, include_blank_lines=0):
- out = ""
- for line in str.split('\n'):
- line = line.strip()
- if line or include_blank_lines:
- out += "%s%s\n" % (prefix, line)
- # Strip trailing new line
- if out:
- out = out[:-1]
- return out
-
-################################################################################
-
-# Split command line arguments which can be separated by either commas
-# or whitespace. If dwim is set, it will complain about string ending
-# in comma since this usually means someone did 'madison -a i386, m68k
-# foo' or something and the inevitable confusion resulting from 'm68k'
-# being treated as an argument is undesirable.
-
-def split_args (s, dwim=1):
- if not s:
- return []
-
- if s.find(",") == -1:
- return s.split();
- else:
- if s[-1:] == "," and dwim:
- fubar("split_args: found trailing comma, spurious space maybe?");
- return s.split(",");
-
-################################################################################
-
-def extract_component_from_section(section):
- component = "";
-
- if section.find('/') != -1:
- component = section.split('/')[0];
-
- # XXX James Troup 2006-01-30:
- # We don't have Cnf, don't want to use DB particularly, so...
- valid_components = [ "main", "restricted", "universe", "multiverse", "contrib", "non-free" ]
-
- # Expand default component
- if component == "":
- if section in valid_components:
- component = section;
- else:
- component = "main";
-
- return (section, component);
-
-################################################################################
-
-def Dict(**dict): return dict
-
-################################################################################
-
-def our_raw_input(prompt=""):
- if prompt:
- sys.stdout.write(prompt);
- sys.stdout.flush();
- try:
- ret = raw_input();
- return ret;
- except EOFError:
- sys.stderr.write("\nUser interrupt (^D).\n");
- raise SystemExit;
-
-################################################################################
-
-def temp_filename(directory=None, dotprefix=None, perms=0700):
- """Return a secure and unique filename by pre-creating it.
-If 'directory' is non-null, it will be the directory the file is pre-created in.
-If 'dotprefix' is non-null, the filename will be prefixed with a '.'."""
-
- if directory:
- old_tempdir = tempfile.tempdir;
- tempfile.tempdir = directory;
-
- filename = tempfile.mktemp();
-
- if dotprefix:
- filename = "%s/.%s" % (os.path.dirname(filename), os.path.basename(filename));
- fd = os.open(filename, os.O_RDWR|os.O_CREAT|os.O_EXCL, perms);
- os.close(fd);
-
- if directory:
- tempfile.tempdir = old_tempdir;
-
- return filename;
-
-################################################################################
-
-def pp_deps (deps):
- pp_deps = [];
- for atom in deps:
- (pkg, version, constraint) = atom;
- if constraint:
- pp_dep = "%s (%s %s)" % (pkg, constraint, version);
- else:
- pp_dep = pkg;
- pp_deps.append(pp_dep);
- return " |".join(pp_deps);
-
-################################################################################
-
-# Returns the user name with a laughable attempt at rfc822 conformancy
-# (read: removing stray periods).
-def whoami ():
- return pwd.getpwuid(os.getuid())[4].split(',')[0].replace('.', '');
-
-################################################################################
-
-def join_with_commas_and(list):
- if len(list) == 0: return "nothing";
- if len(list) == 1: return list[0];
- return ", ".join(list[:-1]) + " and " + list[-1];
-
-################################################################################
-
-# Function for use in sorting lists of architectures.
-# Sorts normally except that 'source' dominates all others.
-
-def arch_compare_sw (a, b):
- if a == "source" and b == "source":
- return 0;
- elif a == "source":
- return -1;
- elif b == "source":
- return 1;
-
- return cmp (a, b);
-
-################################################################################
=== modified file 'scripts/ftpmaster-tools/sync-source.py'
--- scripts/ftpmaster-tools/sync-source.py 2011-09-26 07:33:00 +0000
+++ scripts/ftpmaster-tools/sync-source.py 2011-09-30 01:25:31 +0000
@@ -15,7 +15,6 @@
wherever) into Ubuntu dapper and the whole fake upload trick can go away.
"""
-import commands
import errno
import os
import re
@@ -28,7 +27,6 @@
import _pythonpath
from _syncorigins import origins
import apt_pkg
-import dak_utils
from debian.deb822 import Dsc
from zope.component import getUtility
@@ -44,7 +42,10 @@
from lp.registry.interfaces.distribution import IDistributionSet
from lp.registry.interfaces.person import IPersonSet
from lp.registry.interfaces.pocket import PackagePublishingPocket
-from lp.services.scripts.base import LaunchpadScript
+from lp.services.scripts.base import (
+ LaunchpadScript,
+ LaunchpadScriptFailure,
+ )
from lp.soyuz.enums import (
PackagePublishingStatus,
re_bug_numbers,
@@ -59,6 +60,7 @@
reject_message = ""
+re_no_epoch = re.compile(r"^\d+\:")
re_strip_revision = re.compile(r"-([^-]+)$")
re_changelog_header = re.compile(
r"^\S+ \((?P<version>.*)\) .*;.*urgency=(?P<urgency>\w+).*")
@@ -105,40 +107,10 @@
return urgency_map.get(n, 'low')
-def sign_changes(changes, dsc):
- # XXX cprov 2007-07-06: hardcoded file locations and parameters for
- # production.
- temp_filename = "unsigned-changes"
- keyid = "0C12BDD7"
- secret_keyring = "/srv/launchpad.net/dot-gnupg/secring.gpg"
- pub_keyring = "/srv/launchpad.net/dot-gnupg/pubring.gpg"
-
- filehandle = open(temp_filename, 'w')
- filehandle.write(changes)
- filehandle.close()
-
- output_filename = "%s_%s_source.changes" % (
- dsc["source"], dak_utils.re_no_epoch.sub('', dsc["version"]))
-
- cmd = ("gpg --no-options --batch --no-tty --secret-keyring=%s "
- "--keyring=%s --default-key=0x%s --output=%s --clearsign %s" %
- (secret_keyring, pub_keyring, keyid, output_filename,
- temp_filename))
- result, output = commands.getstatusoutput(cmd)
-
- if (result != 0):
- print " * command was '%s'" % (cmd)
- print (dak_utils.prefix_multi_line_string(
- output, " [gpg output:] "), "")
- dak_utils.fubar("%s: signing .changes failed [return code: %s]." %
- (output_filename, result))
-
- os.unlink(temp_filename)
-
-
def parse_changelog(changelog_filename, previous_version):
if not os.path.exists(changelog_filename):
- dak_utils.fubar("debian/changelog not found in extracted source.")
+ raise LaunchpadScriptFailure(
+ "debian/changelog not found in extracted source.")
urgency = urgency_to_numeric('low')
changes = ""
is_debian_changelog = 0
@@ -158,7 +130,7 @@
changes += line
if not is_debian_changelog:
- dak_utils.fubar("header not found in debian/changelog")
+ raise LaunchpadScriptFailure("header not found in debian/changelog")
closes = []
for match in re_closes.finditer(changes):
@@ -217,7 +189,8 @@
source_description = ""
if not os.path.exists(control_filename):
- dak_utils.fubar("debian/control not found in extracted source.")
+ raise LaunchpadScriptFailure(
+ "debian/control not found in extracted source.")
control_filehandle = open(control_filename)
Control = apt_pkg.ParseTagFile(control_filehandle)
while Control.Step():
@@ -251,7 +224,7 @@
except DpkgSourceError, e:
print " * command was '%s'" % (e.command)
print e.output
- dak_utils.fubar(
+ raise LaunchpadScriptFailure(
"'dpkg-source -x' failed for %s [return code: %s]." %
(dsc_filename, e.result))
@@ -263,7 +236,8 @@
# Sanity check that'll probably break if people set $TMPDIR, but
# WTH, shutil.rmtree scares me
if not tmpdir.startswith("/tmp/"):
- dak_utils.fubar("%s: tmpdir doesn't start with /tmp" % (tmpdir))
+ raise LaunchpadScriptFailure(
+ "%s: tmpdir doesn't start with /tmp" % (tmpdir))
# Move back and cleanup the temporary tree
os.chdir(old_cwd)
@@ -271,7 +245,7 @@
shutil.rmtree(tmpdir)
except OSError, e:
if errno.errorcode[e.errno] != 'EACCES':
- dak_utils.fubar(
+ raise LaunchpadScriptFailure(
"%s: couldn't remove tmp dir for source tree."
% (dsc["source"]))
@@ -282,10 +256,11 @@
cmd = "chmod -R u+rwx %s" % (tmpdir)
result = os.system(cmd)
if result != 0:
- dak_utils.fubar("'%s' failed with result %s." % (cmd, result))
+ raise LaunchpadScriptFailure(
+ "'%s' failed with result %s." % (cmd, result))
shutil.rmtree(tmpdir)
except:
- dak_utils.fubar(
+ raise LaunchpadScriptFailure(
"%s: couldn't remove tmp dir for source tree." % (dsc["source"]))
@@ -303,11 +278,11 @@
# override a main binary package
if current_component == "main" and source_component != "main":
if not Options.forcemore:
- dak_utils.fubar(
+ raise LaunchpadScriptFailure(
"%s is in main but its source (%s) is not." %
(binary, source))
else:
- dak_utils.warn(
+ Log.warning(
"%s is in main but its source (%s) is not - "
"continuing anyway." % (binary, source))
@@ -315,7 +290,7 @@
# ubuntu-modified binary package
ubuntu_bin = current_binaries[binary][0].find("ubuntu")
if not Options.force and ubuntu_bin != -1:
- dak_utils.fubar(
+ raise LaunchpadScriptFailure(
"%s is trying to override %s_%s without -f/--force." %
(source, binary, current_version))
print "I: %s [%s] -> %s_%s [%s]." % (
@@ -333,13 +308,14 @@
dsc_file.seek(0)
(gpg_pre, payload, gpg_post) = Dsc.split_gpg_and_payload(dsc_file)
if gpg_pre == [] and gpg_post == []:
- dak_utils.fubar("signature required for %s but not present"
- % dsc_filename)
+ raise LaunchpadScriptFailure(
+ "signature required for %s but not present" % dsc_filename)
if signing_rules == "must be signed and valid":
if (gpg_pre[0] != "-----BEGIN PGP SIGNED MESSAGE-----" or
gpg_post[0] != "-----BEGIN PGP SIGNATURE-----"):
- dak_utils.fubar("signature for %s invalid %r %r" % (
- dsc_filename, gpg_pre, gpg_post))
+ raise LaunchpadScriptFailure(
+ "signature for %s invalid %r %r" %
+ (dsc_filename, gpg_pre, gpg_post))
dsc_files = dict((entry['name'], entry) for entry in dsc['files'])
check_dsc(dsc, current_sources, current_binaries)
@@ -353,7 +329,7 @@
(old_cwd, tmpdir) = extract_source(dsc_filename)
# Get the upstream version
- upstr_version = dak_utils.re_no_epoch.sub('', dsc["version"])
+ upstr_version = re_no_epoch.sub('', dsc["version"])
if re_strip_revision.search(upstr_version):
upstr_version = re_strip_revision.sub('', upstr_version)
@@ -377,10 +353,8 @@
section, priority, description, files_from_librarian, requested_by,
origin)
- # XXX cprov 2007-07-03: Soyuz wants an unsigned changes
- #sign_changes(changes, dsc)
output_filename = "%s_%s_source.changes" % (
- dsc["source"], dak_utils.re_no_epoch.sub('', dsc["version"]))
+ dsc["source"], re_no_epoch.sub('', dsc["version"]))
filehandle = open(output_filename, 'w')
try:
@@ -416,7 +390,7 @@
if (valid_component is not None and
component != valid_component.name):
- dak_utils.warn(
+ Log.warning(
"%s/%s: skipping because it is not in %s component" % (
pkg, version, component))
continue
@@ -425,7 +399,7 @@
S[pkg] = [version, component]
else:
if apt_pkg.VersionCompare(S[pkg][0], version) < 0:
- dak_utils.warn(
+ Log.warning(
"%s: skipping because %s is < %s" % (
pkg, version, S[pkg][0]))
S[pkg] = [version, component]
@@ -537,7 +511,8 @@
# Check it's in the Sources file
if pkg not in Sources:
- dak_utils.fubar("%s doesn't exist in the Sources file." % (pkg))
+ raise LaunchpadScriptFailure(
+ "%s doesn't exist in the Sources file." % (pkg))
syncsource = SyncSource(Sources[pkg]["files"], origin, Log,
urllib.urlretrieve, Options.todistro)
@@ -546,10 +521,10 @@
dsc_filename = syncsource.fetchSyncFiles()
syncsource.checkDownloadedFiles()
except SyncSourceError, e:
- dak_utils.fubar("Fetching files failed: %s" % (str(e),))
+ raise LaunchpadScriptFailure("Fetching files failed: %s" % (str(e),))
if dsc_filename is None:
- dak_utils.fubar(
+ raise LaunchpadScriptFailure(
"No dsc filename in %r" % Sources[pkg]["files"].keys())
import_dsc(os.path.abspath(dsc_filename), suite, previous_version,
@@ -589,7 +564,7 @@
if pkg not in Sources:
if not Options.all:
- dak_utils.fubar("%s: not found" % (pkg))
+ raise LaunchpadScriptFailure("%s: not found" % (pkg))
else:
print "[Ubuntu Specific] %s_%s" % (pkg, dest_version)
stat_us += 1
@@ -672,7 +647,7 @@
if Options.tocomponent is not None:
if Options.tocomponent not in valid_components:
- dak_utils.fubar(
+ raise LaunchpadScriptFailure(
"%s is not a valid component for %s/%s."
% (Options.tocomponent, Options.todistro.name,
Options.tosuite.name))
@@ -686,8 +661,8 @@
PersonSet = getUtility(IPersonSet)
person = PersonSet.getByName(Options.requestor)
if not person:
- dak_utils.fubar("Unknown LaunchPad user id '%s'."
- % (Options.requestor))
+ raise LaunchpadScriptFailure(
+ "Unknown LaunchPad user id '%s'." % (Options.requestor))
Options.requestor = "%s <%s>" % (person.displayname,
person.preferredemail.email)
Options.requestor = Options.requestor.encode("ascii", "replace")
@@ -713,7 +688,7 @@
try:
blacklist_file = open(path)
except IOError:
- dak_utils.warn('Could not find blacklist file on %s' % path)
+ Log.warning('Could not find blacklist file on %s' % path)
return blacklist
for line in blacklist_file:
@@ -781,7 +756,7 @@
# Sanity checks on options
if not Options.all and not self.args:
- dak_utils.fubar(
+ raise LaunchpadScriptFailure(
"Need -a/--all or at least one package name as an argument.")
apt_pkg.init()