pull-debian-source: Rewritten in Python to take advantage of the new

ubuntutools library functions.
This commit is contained in:
Stefano Rivera 2011-01-22 20:58:52 +02:00
parent a1cafe8843
commit 2c84b5db5b
4 changed files with 107 additions and 207 deletions

4
debian/changelog vendored
View File

@ -12,8 +12,10 @@ ubuntu-dev-tools (0.113) UNRELEASED; urgency=low
* pbuilder-dist: Use ubuntutools.logger. * pbuilder-dist: Use ubuntutools.logger.
* pbuilder-dist-simple: Remove all mention of supporting Debian. * pbuilder-dist-simple: Remove all mention of supporting Debian.
(LP: #481223) (LP: #481223)
* pull-debian-source: Rewritten in Python to take advantage of the new
ubuntutools library functions.
-- Stefano Rivera <stefanor@ubuntu.com> Sat, 22 Jan 2011 18:22:55 +0200 -- Stefano Rivera <stefanor@ubuntu.com> Sat, 22 Jan 2011 20:55:57 +0200
ubuntu-dev-tools (0.112) unstable; urgency=low ubuntu-dev-tools (0.112) unstable; urgency=low

4
debian/copyright vendored
View File

@ -133,7 +133,6 @@ Files: dch-repeat,
doc/lp-list-bugs.1, doc/lp-list-bugs.1,
doc/manage-credentials.1, doc/manage-credentials.1,
doc/mk-sbuild.1, doc/mk-sbuild.1,
doc/pull-debian-source.1,
doc/pull-lp-source.1, doc/pull-lp-source.1,
doc/pull-revu-source.1, doc/pull-revu-source.1,
doc/ubuntu-build.1, doc/ubuntu-build.1,
@ -143,7 +142,6 @@ Files: dch-repeat,
lp-list-bugs, lp-list-bugs,
manage-credentials, manage-credentials,
mk-sbuild, mk-sbuild,
pull-debian-source,
pull-lp-source, pull-lp-source,
pull-revu-source, pull-revu-source,
ubuntu-build, ubuntu-build,
@ -180,6 +178,7 @@ Files: data/*,
doc/debian-distro-info.1, doc/debian-distro-info.1,
doc/distro-info.1, doc/distro-info.1,
doc/pull-debian-debdiff.1, doc/pull-debian-debdiff.1,
doc/pull-debian-source.1,
doc/sponsor-patch.1, doc/sponsor-patch.1,
doc/suspicious-source.1, doc/suspicious-source.1,
doc/ubuntu-dev-tools.5, doc/ubuntu-dev-tools.5,
@ -187,6 +186,7 @@ Files: data/*,
doc/update-maintainer.1, doc/update-maintainer.1,
doc/wrap-and-sort.1, doc/wrap-and-sort.1,
pull-debian-debdiff, pull-debian-debdiff,
pull-debian-source,
sponsor-patch, sponsor-patch,
suspicious-source, suspicious-source,
test-data/*, test-data/*,

View File

@ -1,29 +1,39 @@
.TH PULL\-DEBIAN\-SOURCE "1" "20 December 2008" "ubuntu-dev-tools" .\" Copyright (C) 2011, Stefano Rivera <stefanor@ubuntu.com>
.\"
.\" 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 .SH NAME
pull\-debian\-source \- download a source package from Debian pull\-debian\-source \- download and extract a source package from Debian
.SH SYNOPSIS .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 .SH DESCRIPTION
\fBpull\-debian\-source\fR downloads and extracts the latest version of \fBpull\-debian\-source\fR downloads and extracts the current version of
<\fBsource package\fR> from Debian. \fIsource package\fR in the specified Debian \fIrelease\fR.
If the optional parameter [\fItarget release\fR] is specified, the latest
version in that release will be downloaded instead.
.SH OPTIONS .SH OPTIONS
Listed below are the command line options for pull\-debian\-source:
.TP .TP
.I source package .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 .TP
.I target release .I release
This is the release that you would like the source package to be downloaded from. The release to download the source package from. Defaults to
This value defaults to 'unstable'. \fBunstable\fR.
.TP .TP
.BR \-h ", " \-\-help .BR \-d ", " \-\-download\-only
Display the usage instructions and exit. Do not extract the source package.
.TP .TP
.B \-m \fIDEBIAN_MIRROR\fR, \fB\-\-mirror\fR=\fIDEBIAN_MIRROR\fR .B \-m \fIDEBIAN_MIRROR\fR, \fB\-\-mirror\fR=\fIDEBIAN_MIRROR\fR
Use the specified mirror. 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 If the package isn't found on this mirror, \fBpull\-debian\-source\fR
will fall back to the default mirror. will fall back to the default mirror.
.TP .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 .B \-\-no\-conf
Do not read any configuration files, or configuration from environment Do not read any configuration files, or configuration from environment
variables. variables.
.TP
.BR \-h ", " \-\-help
Display the usage instructions and exit.
.SH ENVIRONMENT .SH ENVIRONMENT
All of the \fBCONFIGURATION VARIABLES\fR below are also supported as All of the \fBCONFIGURATION VARIABLES\fR below are also supported as
@ -50,16 +69,12 @@ package\-wide variable.
.TP .TP
.BR PULL_DEBIAN_SOURCE_DEBIAN_MIRROR ", " UBUNTUTOOLS_DEBIAN_MIRROR .BR PULL_DEBIAN_SOURCE_DEBIAN_MIRROR ", " UBUNTUTOOLS_DEBIAN_MIRROR
The default value for \fB\-\-mirror\fR. 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 .SH SEE ALSO
.BR dget (1), .BR dget (1),
.BR pull\-debian\-debdiff (1), .BR pull\-debian\-debdiff (1),
.BR pull\-lp\-source (1), .BR pull\-lp\-source (1),
.BR ubuntu\-dev\-tools (5) .BR ubuntu\-dev\-tools (5)
.SH AUTHOR
.PP
\fBpull\-debian\-source\fR and this manual page were written by Nathan Handler
<nhandler@ubuntu.com>. 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.

View File

@ -1,194 +1,77 @@
#!/usr/bin/perl #!/usr/bin/python
# Script Name: pull-debian-source
# Author: Nathan Handler <nhandler@ubuntu.com>
# Usage: pull-debian-source <source package> [release]
# Copyright (C) 2008-2009 Nathan Handler <nhandler@ubuntu.com>,
# 2010 Stefano Rivera <stefanor@ubuntu.com>
# 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.
# #
# This program is distributed in the hope that it will be useful, # pull-debian-source -- pull a source package from Launchpad
# but WITHOUT ANY WARRANTY; without even the implied warranty of # Inspired by a tool of the same name by Nathan Handler.
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# #
# On Debian GNU/Linux systems, the complete text of the GNU General # Permission to use, copy, modify, and/or distribute this software for any
# Public License can be found in the /usr/share/common-licenses/GPL-3 file. # 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; import sys
use strict; from optparse import OptionParser
use LWP::Simple;
use File::Basename;
use Getopt::Long;
use AptPkg::Version;
my($name) = basename($0); from ubuntutools.archive import DebianSourcePackage, rmadison
my($help, $mirror, $no_conf); from ubuntutools.config import UDTConfig
GetOptions('h|help' => \$help, from ubuntutools.logger import Logger
'm|mirror=s' => \$mirror,
'no-conf' => \$no_conf,
);
&usage(0) if($help);
my($package) = $ARGV[0] || &usage(2);
if (! $no_conf) { def main():
my($shell_cmd); usage = 'Usage: %prog <package> [release]'
$shell_cmd .= "[ -f /etc/devscripts.conf ] && . /etc/devscripts.conf\n"; parser = OptionParser(usage)
$shell_cmd .= "[ -f ~/.devscripts ] && . ~/.devscripts\n"; parser.add_option('-d', '--download-only',
foreach my $var qw(PULL_DEBIAN_SOURCE_DEBIAN_MIRROR dest='download_only', default=False, action='store_true',
UBUNTUTOOLS_DEBIAN_MIRROR help='Do not extract the source package')
PULL_DEBIAN_SOURCE_MIRROR_FALLBACK parser.add_option('-m', '--mirror', metavar='UBUNTU_MIRROR',
UBUNTUTOOLS_MIRROR_FALLBACK) { dest='debian_mirror',
$shell_cmd .= "echo $var=\$$var\n"; help='Preferred Debian mirror (default: %s)'
} % UDTConfig.defaults['DEBIAN_MIRROR'])
my $shell_out = `/bin/bash -c '$shell_cmd'`; parser.add_option('-s', '--security-mirror', metavar='DEBSEC_MIRROR',
my %config_values; dest='debsec_mirror',
foreach my $line (split /\n/, $shell_out) { help='Preferred Debian Security mirror (default: %s)'
my($k, $v) = split /=/, $line, 2; % UDTConfig.defaults['DEBSEC_MIRROR'])
$config_values{$k} = $v; parser.add_option('--no-conf',
} dest='no_conf', default=False, action='store_true',
$mirror = $config_values{'PULL_DEBIAN_SOURCE_DEBIAN_MIRROR'} help="Don't read config files or environment variables")
|| $config_values{'UBUNTUTOOLS_DEBIAN_MIRROR'} (options, args) = parser.parse_args()
if (! $mirror); if not args:
} parser.error('Must specify package name')
my($default_mirror) = 'http://ftp.debian.org/debian'; elif len(args) > 2:
my(@mirrors); parser.error('Too many arguments. '
push @mirrors, $mirror if $mirror && $mirror ne $default_mirror; 'Must only specify package and (optionally) release.')
push @mirrors, $default_mirror;
my($release)=$ARGV[1] || 'unstable'; config = UDTConfig(options.no_conf)
$release=&convertCodeName($release); if options.debian_mirror is None:
&checkRelease($release); options.debian_mirror = config.get_value('DEBIAN_MIRROR')
my($madison) = &getMadison(&getURL($package,$release)); if options.debsec_mirror is None:
options.debsec_mirror = config.get_value('DEBSEC_MIRROR')
foreach my $mirror (@mirrors) { package = args[0].lower()
my($dsc)=&getDSC($madison, $mirror);
print "$dsc\n";
system("dget -xu $dsc");
exit(0) if ($? == 0);
}
exit(1);
sub convertCodeName { if len(args) > 1:
my($release)=shift || die("No Release Passed To convertCodeName!\n"); suite = args[1].lower()
chomp $release; else:
if($release=~m/^lenny$/i) { suite = 'unstable'
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;
}
} 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"); if __name__ == '__main__':
main()
}
sub usage {
my($exit)=shift;
print <<"EOF";
USAGE: $name [options] <source package> [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");
}