From 2c84b5db5b8e5a0282cc76c47c7f2436beac3177 Mon Sep 17 00:00:00 2001 From: Stefano Rivera Date: Sat, 22 Jan 2011 20:58:52 +0200 Subject: [PATCH 1/3] pull-debian-source: Rewritten in Python to take advantage of the new ubuntutools library functions. --- debian/changelog | 4 +- debian/copyright | 4 +- doc/pull-debian-source.1 | 57 +++++---- pull-debian-source | 249 +++++++++++---------------------------- 4 files changed, 107 insertions(+), 207 deletions(-) diff --git a/debian/changelog b/debian/changelog index 235490a..5b5822a 100644 --- a/debian/changelog +++ b/debian/changelog @@ -12,8 +12,10 @@ ubuntu-dev-tools (0.113) UNRELEASED; urgency=low * pbuilder-dist: Use ubuntutools.logger. * pbuilder-dist-simple: Remove all mention of supporting Debian. (LP: #481223) + * pull-debian-source: Rewritten in Python to take advantage of the new + ubuntutools library functions. - -- Stefano Rivera Sat, 22 Jan 2011 18:22:55 +0200 + -- Stefano Rivera Sat, 22 Jan 2011 20:55:57 +0200 ubuntu-dev-tools (0.112) unstable; urgency=low diff --git a/debian/copyright b/debian/copyright index d61234a..9c1a70e 100644 --- a/debian/copyright +++ b/debian/copyright @@ -133,7 +133,6 @@ Files: dch-repeat, doc/lp-list-bugs.1, doc/manage-credentials.1, doc/mk-sbuild.1, - doc/pull-debian-source.1, doc/pull-lp-source.1, doc/pull-revu-source.1, doc/ubuntu-build.1, @@ -143,7 +142,6 @@ Files: dch-repeat, lp-list-bugs, manage-credentials, mk-sbuild, - pull-debian-source, pull-lp-source, pull-revu-source, ubuntu-build, @@ -180,6 +178,7 @@ Files: data/*, doc/debian-distro-info.1, doc/distro-info.1, doc/pull-debian-debdiff.1, + doc/pull-debian-source.1, doc/sponsor-patch.1, doc/suspicious-source.1, doc/ubuntu-dev-tools.5, @@ -187,6 +186,7 @@ Files: data/*, doc/update-maintainer.1, doc/wrap-and-sort.1, pull-debian-debdiff, + pull-debian-source, sponsor-patch, suspicious-source, test-data/*, diff --git a/doc/pull-debian-source.1 b/doc/pull-debian-source.1 index da61637..89812b4 100644 --- a/doc/pull-debian-source.1 +++ b/doc/pull-debian-source.1 @@ -1,29 +1,39 @@ -.TH PULL\-DEBIAN\-SOURCE "1" "20 December 2008" "ubuntu-dev-tools" +.\" Copyright (C) 2011, Stefano Rivera +.\" +.\" Permission to use, copy, modify, and/or distribute this software for any +.\" purpose with or without fee is hereby granted, provided that the above +.\" copyright notice and this permission notice appear in all copies. +.\" +.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH +.\" REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY +.\" AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, +.\" INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM +.\" LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR +.\" OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR +.\" PERFORMANCE OF THIS SOFTWARE. +.TH PULL\-DEBIAN\-SOURCE "1" "22 January 2011" "ubuntu\-dev\-tools" .SH NAME -pull\-debian\-source \- download a source package from Debian +pull\-debian\-source \- download and extract a source package from Debian .SH SYNOPSIS -.B pull\-debian\-source \fR[\fIoptions\fR] <\fIsource package\fR> [\fItarget release\fR] +.B pull\-debian\-source \fR[\fIoptions\fR] <\fIsource package\fR> [\fIrelease\fR] .SH DESCRIPTION -\fBpull\-debian\-source\fR downloads and extracts the latest version of -<\fBsource package\fR> from Debian. -If the optional parameter [\fItarget release\fR] is specified, the latest -version in that release will be downloaded instead. +\fBpull\-debian\-source\fR downloads and extracts the current version of +\fIsource package\fR in the specified Debian \fIrelease\fR. .SH OPTIONS -Listed below are the command line options for pull\-debian\-source: .TP .I source package -This is the source package that you would like to be downloaded from Debian. +The source package to download from Debian. .TP -.I target release -This is the release that you would like the source package to be downloaded from. -This value defaults to 'unstable'. +.I release +The release to download the source package from. Defaults to +\fBunstable\fR. .TP -.BR \-h ", " \-\-help -Display the usage instructions and exit. +.BR \-d ", " \-\-download\-only +Do not extract the source package. .TP .B \-m \fIDEBIAN_MIRROR\fR, \fB\-\-mirror\fR=\fIDEBIAN_MIRROR\fR Use the specified mirror. @@ -31,9 +41,18 @@ Should be in the form \fBhttp://ftp.debian.org/debian\fR. If the package isn't found on this mirror, \fBpull\-debian\-source\fR will fall back to the default mirror. .TP +.B \-s \fIDEBSEC_MIRROR\fR, \fB\-\-security\-mirror\fR=\fIDEBSEC_MIRROR\fR +Use the specified mirror. +Should be in the form \fBhttp://security.debian.org\fR. +If the package isn't found on this mirror, \fBpull\-debian\-source\fR +will fall back to the default mirror. +.TP .B \-\-no\-conf Do not read any configuration files, or configuration from environment variables. +.TP +.BR \-h ", " \-\-help +Display the usage instructions and exit. .SH ENVIRONMENT All of the \fBCONFIGURATION VARIABLES\fR below are also supported as @@ -50,16 +69,12 @@ package\-wide variable. .TP .BR PULL_DEBIAN_SOURCE_DEBIAN_MIRROR ", " UBUNTUTOOLS_DEBIAN_MIRROR The default value for \fB\-\-mirror\fR. +.TP +.BR PULL_DEBIAN_SOURCE_DEBSEC_MIRROR ", " UBUNTUTOOLS_DEBSEC_MIRROR +The default value for \fB\-\-security\-mirror\fR. .SH SEE ALSO .BR dget (1), .BR pull\-debian\-debdiff (1), .BR pull\-lp\-source (1), .BR ubuntu\-dev\-tools (5) - -.SH AUTHOR -.PP -\fBpull\-debian\-source\fR and this manual page were written by Nathan Handler -. The manual page was based on Iain Lane's manual page for -pull-lp-source. -Both are released under the GNU General Public License, version 3 or later. diff --git a/pull-debian-source b/pull-debian-source index 8e3daea..f4004f2 100755 --- a/pull-debian-source +++ b/pull-debian-source @@ -1,194 +1,77 @@ -#!/usr/bin/perl -# Script Name: pull-debian-source -# Author: Nathan Handler -# Usage: pull-debian-source [release] -# Copyright (C) 2008-2009 Nathan Handler , -# 2010 Stefano Rivera -# License: GNU General Public License -# 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 3 of the License, or -# (at your option) any later version. +#!/usr/bin/python # -# 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. +# pull-debian-source -- pull a source package from Launchpad +# Inspired by a tool of the same name by Nathan Handler. # -# On Debian GNU/Linux systems, the complete text of the GNU General -# Public License can be found in the /usr/share/common-licenses/GPL-3 file. +# Permission to use, copy, modify, and/or distribute this software for any +# purpose with or without fee is hereby granted, provided that the above +# copyright notice and this permission notice appear in all copies. +# +# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH +# REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY +# AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, +# INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM +# LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR +# OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR +# PERFORMANCE OF THIS SOFTWARE. -use warnings; -use strict; -use LWP::Simple; -use File::Basename; -use Getopt::Long; -use AptPkg::Version; +import sys +from optparse import OptionParser -my($name) = basename($0); -my($help, $mirror, $no_conf); -GetOptions('h|help' => \$help, - 'm|mirror=s' => \$mirror, - 'no-conf' => \$no_conf, - ); -&usage(0) if($help); -my($package) = $ARGV[0] || &usage(2); +from ubuntutools.archive import DebianSourcePackage, rmadison +from ubuntutools.config import UDTConfig +from ubuntutools.logger import Logger -if (! $no_conf) { - my($shell_cmd); - $shell_cmd .= "[ -f /etc/devscripts.conf ] && . /etc/devscripts.conf\n"; - $shell_cmd .= "[ -f ~/.devscripts ] && . ~/.devscripts\n"; - foreach my $var qw(PULL_DEBIAN_SOURCE_DEBIAN_MIRROR - UBUNTUTOOLS_DEBIAN_MIRROR - PULL_DEBIAN_SOURCE_MIRROR_FALLBACK - UBUNTUTOOLS_MIRROR_FALLBACK) { - $shell_cmd .= "echo $var=\$$var\n"; - } - my $shell_out = `/bin/bash -c '$shell_cmd'`; - my %config_values; - foreach my $line (split /\n/, $shell_out) { - my($k, $v) = split /=/, $line, 2; - $config_values{$k} = $v; - } - $mirror = $config_values{'PULL_DEBIAN_SOURCE_DEBIAN_MIRROR'} - || $config_values{'UBUNTUTOOLS_DEBIAN_MIRROR'} - if (! $mirror); -} -my($default_mirror) = 'http://ftp.debian.org/debian'; -my(@mirrors); -push @mirrors, $mirror if $mirror && $mirror ne $default_mirror; -push @mirrors, $default_mirror; +def main(): + usage = 'Usage: %prog [release]' + parser = OptionParser(usage) + parser.add_option('-d', '--download-only', + dest='download_only', default=False, action='store_true', + help='Do not extract the source package') + parser.add_option('-m', '--mirror', metavar='UBUNTU_MIRROR', + dest='debian_mirror', + help='Preferred Debian mirror (default: %s)' + % UDTConfig.defaults['DEBIAN_MIRROR']) + parser.add_option('-s', '--security-mirror', metavar='DEBSEC_MIRROR', + dest='debsec_mirror', + help='Preferred Debian Security mirror (default: %s)' + % UDTConfig.defaults['DEBSEC_MIRROR']) + parser.add_option('--no-conf', + dest='no_conf', default=False, action='store_true', + help="Don't read config files or environment variables") + (options, args) = parser.parse_args() + if not args: + parser.error('Must specify package name') + elif len(args) > 2: + parser.error('Too many arguments. ' + 'Must only specify package and (optionally) release.') -my($release)=$ARGV[1] || 'unstable'; -$release=&convertCodeName($release); -&checkRelease($release); -my($madison) = &getMadison(&getURL($package,$release)); + config = UDTConfig(options.no_conf) + if options.debian_mirror is None: + options.debian_mirror = config.get_value('DEBIAN_MIRROR') + if options.debsec_mirror is None: + options.debsec_mirror = config.get_value('DEBSEC_MIRROR') -foreach my $mirror (@mirrors) { - my($dsc)=&getDSC($madison, $mirror); - print "$dsc\n"; - system("dget -xu $dsc"); - exit(0) if ($? == 0); -} -exit(1); + package = args[0].lower() -sub convertCodeName { - my($release)=shift || die("No Release Passed To convertCodeName!\n"); - chomp $release; - if($release=~m/^lenny$/i) { - return "stable"; - } - elsif($release=~m/^squeeze$/i) { - return "testing"; - } - elsif($release=~m/^sid$/i) { - return "unstable"; - } - elsif($release=~m/^etch$/i) { - return "oldstable"; - } - return $release; -} -sub checkRelease { - my($release)=shift || die("No Release Passed To checkRelease!\n"); - chomp $release; - my %releases=( - 'stable' => 1, - 'testing' => 1, - 'unstable' => 1, - 'experimental' => 1, - 'oldstable' => 1 - ); - &invalidRelease(\%releases) unless $releases{$release} -} -sub getURL{ - my($package)=shift || die("No Package Passed To getURL: $!\n"); - my($release)=shift || die("No Release Passed to getURL: $!\n"); - chomp $package; - chomp $release; - $package=lc($package); - $package=~s/\+/%2b/g; - $release=lc($release); - my($baseURL)='http://qa.debian.org/madison.php?text=on&a=source'; - my($url)=$baseURL . '&package=' . $package . '&s=' . $release; - return $url; -} -sub getMadison { - my($url)=shift || die("No URL Passed to getMadison: $!\n"); - chomp $url; - my($madison)=get($url); - die("The source package $package isn't available in Debian testing.\nRun $name $package unstable if the package has not yet migrated from Debian unstable to Debian testing.\n") if ($release=~m/testing/ && $madison=~m/^\s*$/); - return $madison; -} -sub getDSC { - my($madison)=shift || die("No madison Passed to getDSC: $!\n"); - if($madison=~m/^[WE]:/i) { - die("$madison"); - } - my($baseURL)=shift || die ("No baseURL Passed to getDSC: $!\n"); - my(@madison)=split(/\n/,$madison); - my %urls; - my $url; - foreach my $line (@madison) { - $url = $baseURL . '/pool/'; - my($package,$version,$release,$archs)=split(/\|/,$line,4); - $package=~s/\s*//g; - $version=~s/\s*//g; - $release=~s/\s*//g; - $archs=~s/\s*//g; - $version=~s/^.*?\://; - if($archs=~m/source/) { - print "Package: $package\nVersion: $version\nRelease: $release\nArchitectures: $archs\n"; - my($firstLetter); - if($package=~m/^lib/) { - $firstLetter="lib" . substr($package,3,1); - } - else { - $firstLetter=substr($package,0,1); - } - if($release=~m/contrib/) { - $url .= 'contrib/'; - } - elsif($release=~m/non\-free/) { - $url .= 'non-free/'; - } - else { - $url .= 'main/'; - } - $url .= $firstLetter . '/' . $package . '/' . $package . '_' . $version . '.dsc'; - $urls{$version} = $url; - } + if len(args) > 1: + suite = args[1].lower() + else: + suite = 'unstable' - } + line = list(rmadison('debian', package, suite, 'source')) + if not line: + Logger.error('Unable to find %s in %s.', package, suite) + sys.exit(1) - my @vers = reverse sort AptPkg::Version::CmpVersion keys %urls; + line = line[-1] + srcpkg = DebianSourcePackage(package, line['version'], + component=line['component'], + mirrors=[options.debian_mirror, + options.debsec_mirror]) + srcpkg.pull() + if not options.download_only: + srcpkg.unpack() - return $urls{$vers[0]} or die("Unable To Find Source Package On Madison\n"); - -} -sub usage { - my($exit)=shift; - print <<"EOF"; -USAGE: $name [options] [target release] - -Options: - -h, --help Show this help message and exit - -m DEBIAN_MIRROR, --mirror=DEBIAN_MIRROR - Preferred Debian mirror - (default: http://ftp.debian.org/debian) - --no-conf Don't read config files or environment variables -EOF - exit($exit); -} -sub invalidRelease { - my($releases)=shift || die("Invalid Release!"); - my(%releases)=%$releases; - my($validReleases); - while ( my ($key, $value) = each(%releases) ) { - if($value) { - $validReleases .= $key . ", "; - } - } - $validReleases=~s/,\s*$//; - die("Invalid Release!\nValid Releases: $validReleases\n"); -} +if __name__ == '__main__': + main() From eeb8efc0b15cd6549e8aed42cf1f21935c27fa3d Mon Sep 17 00:00:00 2001 From: Stefano Rivera Date: Sat, 22 Jan 2011 21:17:39 +0200 Subject: [PATCH 2/3] Copyright lines --- doc/pull-debian-source.1 | 2 +- pull-debian-source | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/doc/pull-debian-source.1 b/doc/pull-debian-source.1 index 89812b4..4b0d49e 100644 --- a/doc/pull-debian-source.1 +++ b/doc/pull-debian-source.1 @@ -1,4 +1,4 @@ -.\" Copyright (C) 2011, Stefano Rivera +.\" Copyright (C) 2010-2011, Stefano Rivera .\" .\" Permission to use, copy, modify, and/or distribute this software for any .\" purpose with or without fee is hereby granted, provided that the above diff --git a/pull-debian-source b/pull-debian-source index f4004f2..35cabb9 100755 --- a/pull-debian-source +++ b/pull-debian-source @@ -1,6 +1,7 @@ #!/usr/bin/python # # pull-debian-source -- pull a source package from Launchpad +# Copyright (C) 2011, Stefano Rivera # Inspired by a tool of the same name by Nathan Handler. # # Permission to use, copy, modify, and/or distribute this software for any From b248387f325673935bba2e87361712b55c901be4 Mon Sep 17 00:00:00 2001 From: Stefano Rivera Date: Sat, 22 Jan 2011 21:21:29 +0200 Subject: [PATCH 3/3] import optparse, without from --- pull-debian-source | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pull-debian-source b/pull-debian-source index 35cabb9..8a884fb 100755 --- a/pull-debian-source +++ b/pull-debian-source @@ -16,8 +16,8 @@ # OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR # PERFORMANCE OF THIS SOFTWARE. +import optparse import sys -from optparse import OptionParser from ubuntutools.archive import DebianSourcePackage, rmadison from ubuntutools.config import UDTConfig @@ -25,7 +25,7 @@ from ubuntutools.logger import Logger def main(): usage = 'Usage: %prog [release]' - parser = OptionParser(usage) + parser = optparse.OptionParser(usage) parser.add_option('-d', '--download-only', dest='download_only', default=False, action='store_true', help='Do not extract the source package')