From d5c7de285e42a45afcef59df9c93826f4171ef70 Mon Sep 17 00:00:00 2001 From: Stefano Rivera Date: Thu, 23 Dec 2010 23:12:24 +0200 Subject: [PATCH] Configurable mirror support for pull-debian-source --- debian/copyright | 1 + doc/pull-debian-source.1 | 48 +++++++++++++++++++++---- doc/ubuntu-dev-tools.5 | 12 +++++++ pull-debian-source | 75 ++++++++++++++++++++++++++++++++++------ ubuntutools/config.py | 2 ++ 5 files changed, 121 insertions(+), 17 deletions(-) diff --git a/debian/copyright b/debian/copyright index 45f4cea..de9030b 100644 --- a/debian/copyright +++ b/debian/copyright @@ -166,6 +166,7 @@ Copyright: 2007, Albin Tonnerre (Lutin) 2009-2010, Michael Bienia 2009, Nathan Handler 2007-2008, Siegfried-Angel Gevatter Pujals + 2010, Stefano Rivera License: GPL-3+ 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 diff --git a/doc/pull-debian-source.1 b/doc/pull-debian-source.1 index 11e48ae..89ea6ee 100644 --- a/doc/pull-debian-source.1 +++ b/doc/pull-debian-source.1 @@ -4,7 +4,7 @@ pull\-debian\-source \- download a source package from Debian .SH SYNOPSIS -.B pull\-debian\-source \fR[\fB\-h\fR]\fB <\fBsource package\fR> [\fItarget release\fR] +.B pull\-debian\-source \fR[\fIoptions\fR] <\fIsource package\fR> [\fItarget release\fR] .SH DESCRIPTION \fBpull\-debian\-source\fR downloads and extracts the latest version of @@ -15,15 +15,51 @@ version in that release will be downloaded instead. .SH OPTIONS Listed below are the command line options for pull\-debian\-source: .TP -.B \-h, \-\-help -Display the usage instructions and exit. -.TP -.B +.I source package This is the source package that you would like to be downloaded from Debian. .TP -.B [target release] +.I target release This is the release that you would like the source package to be downloaded from. This value defaults to 'unstable'. +.TP +.BR \-h ", " \-\-help +Display the usage instructions and exit. +.TP +.B \-m \fIDEBMIRROR\fR, \fB\-\-mirror\fR=\fIDEBMIRROR\fR +Use the specified mirror. +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 +.BR \-n ", " \-\-no\-fallback +If specified, \fBpull\-debian\-source\fR won't fall back to the default +mirror, should it encounter an error. +.TP +.B \-\-no\-conf +Do not read any configuration files, or configuration from environment +variables. + +.SH ENVIRONMENT +All of the \fBCONFIGURATION VARIABLES\fR below are also supported as +environment variables. +Variables in the environment take precedence to those in configuration +files. + +.SH CONFIGURATION VARIABLES +The following variables can be set in the environment or in +.BR ubuntu\-dev\-tools (5) +configuration files. +In each case, the script\-specific variable takes precedence over the +package\-wide variable. +.TP +.BR PULL_DEBIAN_SOURCE_DEBMIRROR ", " UBUNTUTOOLS_DEBMIRROR +The default value for \fB\-\-mirror\fR. +.TP +.BR PULL_DEBIAN_SOURCE_MIRROR_FALLBACK ", " UBUNTUTOOLS_MIRROR_FALLBACK +The default value for \fB\-\-no\-fallback\fR. + +.SH SEE ALSO +.BR ubuntu\-dev\-tools (5) .SH AUTHOR .PP diff --git a/doc/ubuntu-dev-tools.5 b/doc/ubuntu-dev-tools.5 index 270f76f..9b05573 100644 --- a/doc/ubuntu-dev-tools.5 +++ b/doc/ubuntu-dev-tools.5 @@ -56,10 +56,22 @@ The currently recognised package\-wide variables are: This specifies the preferred test\-builder, one of .BR pbuilder " (default), " sbuild ", " pbuilder\-dist . .TP +.B UBUNTUTOOLS_DEBMIRROR +The preferred Debian archive mirror. +Should be of the form \fBhttp://ftp.debian.org/debian\fR. +If not specified, the master will be used. +.TP .B UBUNTUTOOLS_LPINSTANCE The launchpad instance to communicate with. e.g. \fBproduction\fR (default) or \fBstaging\fR. .TP +.B UBUNTUTOOLS_MIRROR_FALLBACK +Whether or not to fall\-back to the master archive mirror. +This is usually the desired behaviour, as mirrors can lag the masters. +If on a private network with only a local mirror, you may want to set +this to \fBno\fR. +.RB "One of " yes " (default) or " no . +.TP .B UBUNTUTOOLS_UPDATE_BUILDER Whether or not to update the test\-builder before each test build. .RB "One of " yes " or " no " (default). diff --git a/pull-debian-source b/pull-debian-source index 297324f..6305eee 100755 --- a/pull-debian-source +++ b/pull-debian-source @@ -2,7 +2,8 @@ # Script Name: pull-debian-source # Author: Nathan Handler # Usage: pull-debian-source [release] -# Copyright (C) 2008, 2009 Nathan Handler +# 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 @@ -26,17 +27,58 @@ use AptPkg::Version; die("Please install 'devscripts'\n") if(! grep -x "$_/dget", split(':',$ENV{'PATH'})); -my($name)=basename($0); -my($package)=$ARGV[0] || &usage(2); -my($help)=0; -GetOptions('help' => \$help); +my($name) = basename($0); +my($help, $mirror, $no_fallback, $no_conf); +GetOptions('h|help' => \$help, + 'm|mirror=s' => \$mirror, + 'n|no-fallback' => \$no_fallback, + 'no-conf' => \$no_conf, + ); +my($package) = $ARGV[0] || &usage(2); &usage(0) if($help); + +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_DEBMIRROR UBUNTUTOOLS_DEBMIRROR + 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; + $config_values{$k} = $v; + } + $mirror = $config_values{'PULL_DEBIAN_SOURCE_DEBMIRROR'} + || $config_values{'UBUNTUTOOLS_DEBMIRROR'} + if (! $mirror); + if (! $no_fallback) { + my($v) = $config_values{'PULL_DEBIAN_SOURCE_MIRROR_FALLBACK'} + || $config_values{'UBUNTUTOOLS_MIRROR_FALLBACK'}; + $no_fallback = 1 if $v eq "no"; + } +} +my($default_mirror) = 'http://ftp.debian.org/debian'; +my(@mirrors); +push @mirrors, $mirror if $mirror; +push @mirrors, $default_mirror if $mirror ne $default_mirror and !$no_fallback; + my($release)=$ARGV[1] || 'unstable'; $release=&convertCodeName($release); &checkRelease($release); -my($dsc)=&getDSC(&getMadison(&getURL($package,$release))); -print "$dsc\n"; -exec("dget -xu $dsc"); +my($madison) = &getMadison(&getURL($package,$release)); + +foreach my $mirror (@mirrors) { + my($dsc)=&getDSC($madison, $mirror); + print "$dsc\n"; + system("dget -xu $dsc"); + exit(0) if ($? == 0); +} +exit(1); + sub convertCodeName { my($release)=shift || die("No Release Passed To convertCodeName!\n"); chomp $release; @@ -90,12 +132,12 @@ sub getDSC { if($madison=~m/^[WE]:/i) { die("$madison"); } - my($baseURL)='http://ftp.debian.org/debian/pool/'; + 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; + $url = $baseURL . '/pool/'; my($package,$version,$release,$archs)=split(/\|/,$line,4); $package=~s/\s*//g; $version=~s/\s*//g; @@ -133,7 +175,18 @@ sub getDSC { } sub usage { my($exit)=shift; - print("USAGE: $name [-h] [target release]\n"); + print <<"EOF"; +USAGE: $name [options] [target release] + +Options: + -h, --help Show this help message and exit + -m DEBMIRROR, --mirror=DEBMIRROR + Preferred Debian mirror + (default: http://ftp.debian.org/debian/) + -n, --no-fallback If a custom mirror is provided and an error occurs + while downloading, don't fall back to the default. + --no-conf Don't read config files or environment variables +EOF exit($exit); } sub invalidRelease { diff --git a/ubuntutools/config.py b/ubuntutools/config.py index df28724..2454713 100644 --- a/ubuntutools/config.py +++ b/ubuntutools/config.py @@ -34,7 +34,9 @@ class UDTConfig(object): # These are reqired to be used by at least two scripts. defaults = { 'BUILDER': 'pbuilder', + 'DEBMIRROR': None, 'LPINSTANCE': 'production', + 'MIRROR_FALLBACK': True, 'UPDATE_BUILDER': False, 'WORKDIR': None, }