Package: devscripts
Version: 2.10.7
Severity: wishlist
Tags: patch

Hello.

Is there something like a critical wish? 

Please adopt my patch that adds a --destdir option to uscan. It caters
for an improved integration of uscan with source code management systems
(SCMs) for the sponsoring of packages or general updates. My motivation
was an easier working with svn-buildpackage. However, other SCMs will
have equivalent issues.

I did not call the option "--origDir" since the variable origdir is already
used internally to uscan for something different. What is meant instead
is the directory at which the downloaded tar files should be expected for the
build process. For the routine of svn-buildpackge this is ../tarballs.
Exceptions to that rule are expected to be specified in the file
.svn/deb-layout by a line origDir=../../tarballs or whatever.

This patch does not read the deb-layout file. I thought it may not be
too nice to have a general tool like uscan to be adapted too much to
a particular scm system. But the path can be passed as value to the
--destdir option. This option is required since the internal chdirs
of uscan renders it invariant to the cwd it is executed from. That is
why I feel critical about this wish. Any wrapper of uscan moving the
downloaded files to the intended destination would impede the
functionality of uscan to sense presence of the wumpus.

Sorry for this long redundant description. I am tired. The patch better,
so I am confident, as it only substitutes the hard coded ".." with
"$destdir" and does the usual getopt bits to parse the arguments.

Kind regards

Steffen

--- uscan       2007-08-10 00:36:53.000000000 +0200
+++ uscan.pl    2007-08-21 23:24:52.000000000 +0200
@@ -77,6 +77,7 @@
                    Report status of packages, but do not download
     --debug        Dump the downloaded web pages to stdout for debugging
                    your watch file.
+    --destdir      Path of directory to which to download.
     --download     Report on newer and absent versions, and download (default)
     --force-download
                    Always download the upstream release, even if up to date
@@ -130,7 +131,7 @@
 
 sub version {
     print <<"EOF";
-This is $progname, from the Debian devscripts package, version 2.10.7
+This is $progname, from the Debian devscripts package, version ###VERSION###
 This code is copyright 1999-2006 by Julian Gilbey, all rights reserved.
 Original code by Christoph Lameter.
 This program comes with ABSOLUTELY NO WARRANTY.
@@ -145,6 +146,7 @@
 # Now start by reading configuration files and then command line
 # The next stuff is boilerplate
 
+my $destdir = "..";
 my $download = 1;
 my $force_download = 0;
 my $report = 0; # report even on up-to-date packages?
@@ -158,7 +160,7 @@
 my $dehs_start_output = 0;
 my $pkg_report_header = '';
 my $timeout = 20;
-my $user_agent_string = 'Debian uscan 2.10.7';
+my $user_agent_string = 'Debian uscan ###VERSION###';
 
 if (@ARGV and $ARGV[0] =~ /^--no-?conf$/) {
     $modified_conf_msg = "  (no configuration files read)";
@@ -167,6 +169,7 @@
     my @config_files = ('/etc/devscripts.conf', '~/.devscripts');
     my %config_vars = (
                       'USCAN_TIMEOUT' => 20,
+                      'USCAN_DESTDIR' => '..',
                       'USCAN_DOWNLOAD' => 'yes',
                       'USCAN_PASV' => 'default',
                       'USCAN_SYMLINK' => 'symlink',
@@ -191,6 +194,8 @@
     @config_vars{keys %config_vars} = split /\n/, $shell_out, -1;
 
     # Check validity
+    $config_vars{'USCAN_DESTDIR'} =~ /^\s*(\S+)\s*$/
+       or $config_vars{'USCAN_DESTDIR'}='..';
     $config_vars{'USCAN_DOWNLOAD'} =~ /^(yes|no)$/
        or $config_vars{'USCAN_DOWNLOAD'}='yes';
     $config_vars{'USCAN_PASV'} =~ /^(yes|no|default)$/
@@ -217,6 +222,8 @@
     $modified_conf_msg ||= "  (none)\n";
     chomp $modified_conf_msg;
 
+    $destdir = $config_vars{'USCAN_DESTDIR'}
+       if defined $config_vars{'USCAN_DESTDIR'};
     $download = $config_vars{'USCAN_DOWNLOAD'} eq 'no' ? 0 : 1;
     $passive = $config_vars{'USCAN_PASV'} eq 'yes' ? 1 :
        $config_vars{'USCAN_PASV'} eq 'no' ? 0 : 'default';
@@ -232,13 +239,15 @@
 
 # Now read the command line arguments
 my $debug = 0;
-my ($opt_h, $opt_v, $opt_download, $opt_force_download, $opt_report, 
$opt_passive, $opt_symlink);
+my ($opt_h, $opt_v, $opt_destdir, $opt_download, $opt_force_download,
+    $opt_report, $opt_passive, $opt_symlink);
 my ($opt_verbose, $opt_ignore, $opt_level, $opt_regex, $opt_noconf);
 my ($opt_package, $opt_uversion, $opt_watchfile, $opt_dehs, $opt_timeout);
 my $opt_user_agent;
 
 GetOptions("help" => \$opt_h,
           "version" => \$opt_v,
+          "destdir=s" => \$opt_destdir,
           "download!" => \$opt_download,
           "force-download" => \$opt_force_download,
           "report" => sub { $opt_download = 0; },
@@ -271,6 +280,7 @@
 
 # Now we can set the other variables according to the command line options
 
+$destdir = $opt_destdir if defined $opt_destdir;
 $download = $opt_download if defined $opt_download;
 $force_download = $opt_force_download if defined $opt_force_download;
 $report = $opt_report if defined $opt_report;
@@ -1019,18 +1029,22 @@
     }
 
     if (defined $pkg_dir) {
-       if (-f "../$newfile_base") {
+       if (! -d "$destdir") {
+           print "Package directory '$destdir to store downloaded file is not 
existing\n";
+           return 1;
+       }
+       if (-f "$destdir/$newfile_base") {
            print " => $newfile_base already in package directory\n"
                if $verbose or ($download == 0 and ! $dehs);
            return 0;
        }
-       if (-f "../${pkg}_${newversion}.orig.tar.gz") {
-           print " => ${pkg}_${newversion}.orig.tar.gz already in package 
directory\n"
+       if (-f "$destdir/${pkg}_${newversion}.orig.tar.gz") {
+           print " => ${pkg}_${newversion}.orig.tar.gz already in package 
directory '$destdir'\n"
                if $verbose or ($download == 0 and ! $dehs);
            return 0;
        }
-       elsif (-f "../${pkg}_${newversion}.orig.tar.bz2") {
-           print " => ${pkg}_${newversion}.orig.tar.bz2 already in package 
directory\n"
+       elsif (-f "$destdir/${pkg}_${newversion}.orig.tar.bz2") {
+           print " => ${pkg}_${newversion}.orig.tar.bz2 already in package 
directory '$destdir'\n"
                if $verbose or ($download == 0 and ! $dehs);
            return 0;
        }
@@ -1063,6 +1077,10 @@
     return 0 unless $download;
 
     print "-- Downloading updated package $newfile_base\n" if $verbose;
+    if (! -d "$destdir") {
+        print "Package directory '$destdir to store downloaded file is not 
existing\n";
+        return 1;
+    }
     # Download newer package
     if ($upstream_url =~ m%^http(s)?://%) {
        if (defined($1) and !$haveSSL) {
@@ -1072,7 +1090,7 @@
        # Is anything else than "&amp;" required?  I doubt it.
        print STDERR "$progname debug: requesting URL $upstream_url\n" if 
$debug;
        $request = HTTP::Request->new('GET', $upstream_url);
-       $response = $user_agent->request($request, "../$newfile_base");
+       $response = $user_agent->request($request, "$destdir/$newfile_base");
        if (! $response->is_success) {
            if (defined $pkg_dir) {
                warn "$progname warning: In directory $pkg_dir, downloading\n  
$upstream_url failed: " . $response->status_line . "\n";
@@ -1089,7 +1107,7 @@
        }
        print STDERR "$progname debug: requesting URL $upstream_url\n" if 
$debug;
        $request = HTTP::Request->new('GET', "$upstream_url");
-       $response = $user_agent->request($request, "../$newfile_base");
+       $response = $user_agent->request($request, "$destdir/$newfile_base");
        if (exists $options{'pasv'}) {
            if (defined $passive) { $ENV{'FTP_PASSIVE'}=$passive; }
            else { delete $ENV{'FTP_PASSIVE'}; }
@@ -1105,26 +1123,26 @@
     }
 
     if ($newfile_base =~ /\.(tar\.gz|tgz|tar\.bz2|tbz2?)$/) {
-       my $filetype = `file ../$newfile_base`;
+       my $filetype = `file $destdir/$newfile_base`;
        $filetype =~ s%^\.\./\Q$newfile_base\E: %%;
        unless ($filetype =~ /compressed data/) {
-           warn "$progname warning: ../$newfile_base does not appear to be a 
compressed file;\nthe file command says: $filetype\nNot processing this file 
any further!\n";
+           warn "$progname warning: $destdir/$newfile_base does not appear to 
be a compressed file;\nthe file command says: $filetype\nNot processing this 
file any further!\n";
            return 1;
        }
     }
 
     if ($newfile_base =~ /\.(tar\.gz|tgz)$/) {
        if ($symlink eq 'symlink') {
-           symlink $newfile_base, "../${pkg}_${newversion}.orig.tar.gz";
+           symlink $newfile_base, "$destdir/${pkg}_${newversion}.orig.tar.gz";
        } elsif ($symlink eq 'rename') {
-           move "../$newfile_base", "../${pkg}_${newversion}.orig.tar.gz";
+           move "$destdir/$newfile_base", 
"$destdir/${pkg}_${newversion}.orig.tar.gz";
        }
     }
     elsif ($newfile_base =~ /\.(tar\.bz2|tbz2?)$/) {
        if ($symlink eq 'symlink') {
-           symlink $newfile_base, "../${pkg}_${newversion}.orig.tar.bz2";
+           symlink $newfile_base, "$destdir/${pkg}_${newversion}.orig.tar.bz2";
        } elsif ($symlink eq 'rename') {
-           move "../$newfile_base", "../${pkg}_${newversion}.orig.tar.bz2";
+           move "$destdir/$newfile_base", 
"$destdir/${pkg}_${newversion}.orig.tar.bz2";
        }
     }
 
@@ -1181,14 +1199,14 @@
 
     # Do whatever the user wishes to do
     if ($action) {
-       my $usefile = "../$newfile_base";
+       my $usefile = "$destdir/$newfile_base";
        if ($symlink =~ /^(symlink|rename)$/
            and $newfile_base =~ /\.(tar\.gz|tgz)$/) {
-           $usefile = "../${pkg}_${newversion}.orig.tar.gz";
+           $usefile = "$destdir/${pkg}_${newversion}.orig.tar.gz";
        }
        elsif ($symlink =~ /^(symlink|rename)$/
            and $newfile_base =~ /\.(tar\.bz2|tbz2)$/) {
-           $usefile = "../${pkg}_${newversion}.orig.tar.bz2";
+           $usefile = "$destdir/${pkg}_${newversion}.orig.tar.bz2";
        }
 
        # Any symlink requests are already handled by uscan
--- uscan       2007-08-10 00:36:53.000000000 +0200
+++ uscan.pl    2007-08-21 23:24:52.000000000 +0200
@@ -77,6 +77,7 @@
                    Report status of packages, but do not download
     --debug        Dump the downloaded web pages to stdout for debugging
                    your watch file.
+    --destdir      Path of directory to which to download.
     --download     Report on newer and absent versions, and download (default)
     --force-download
                    Always download the upstream release, even if up to date
@@ -130,7 +131,7 @@
 
 sub version {
     print <<"EOF";
-This is $progname, from the Debian devscripts package, version 2.10.7
+This is $progname, from the Debian devscripts package, version ###VERSION###
 This code is copyright 1999-2006 by Julian Gilbey, all rights reserved.
 Original code by Christoph Lameter.
 This program comes with ABSOLUTELY NO WARRANTY.
@@ -145,6 +146,7 @@
 # Now start by reading configuration files and then command line
 # The next stuff is boilerplate
 
+my $destdir = "..";
 my $download = 1;
 my $force_download = 0;
 my $report = 0; # report even on up-to-date packages?
@@ -158,7 +160,7 @@
 my $dehs_start_output = 0;
 my $pkg_report_header = '';
 my $timeout = 20;
-my $user_agent_string = 'Debian uscan 2.10.7';
+my $user_agent_string = 'Debian uscan ###VERSION###';
 
 if (@ARGV and $ARGV[0] =~ /^--no-?conf$/) {
     $modified_conf_msg = "  (no configuration files read)";
@@ -167,6 +169,7 @@
     my @config_files = ('/etc/devscripts.conf', '~/.devscripts');
     my %config_vars = (
                       'USCAN_TIMEOUT' => 20,
+                      'USCAN_DESTDIR' => '..',
                       'USCAN_DOWNLOAD' => 'yes',
                       'USCAN_PASV' => 'default',
                       'USCAN_SYMLINK' => 'symlink',
@@ -191,6 +194,8 @@
     @config_vars{keys %config_vars} = split /\n/, $shell_out, -1;
 
     # Check validity
+    $config_vars{'USCAN_DESTDIR'} =~ /^\s*(\S+)\s*$/
+       or $config_vars{'USCAN_DESTDIR'}='..';
     $config_vars{'USCAN_DOWNLOAD'} =~ /^(yes|no)$/
        or $config_vars{'USCAN_DOWNLOAD'}='yes';
     $config_vars{'USCAN_PASV'} =~ /^(yes|no|default)$/
@@ -217,6 +222,8 @@
     $modified_conf_msg ||= "  (none)\n";
     chomp $modified_conf_msg;
 
+    $destdir = $config_vars{'USCAN_DESTDIR'}
+       if defined $config_vars{'USCAN_DESTDIR'};
     $download = $config_vars{'USCAN_DOWNLOAD'} eq 'no' ? 0 : 1;
     $passive = $config_vars{'USCAN_PASV'} eq 'yes' ? 1 :
        $config_vars{'USCAN_PASV'} eq 'no' ? 0 : 'default';
@@ -232,13 +239,15 @@
 
 # Now read the command line arguments
 my $debug = 0;
-my ($opt_h, $opt_v, $opt_download, $opt_force_download, $opt_report, 
$opt_passive, $opt_symlink);
+my ($opt_h, $opt_v, $opt_destdir, $opt_download, $opt_force_download,
+    $opt_report, $opt_passive, $opt_symlink);
 my ($opt_verbose, $opt_ignore, $opt_level, $opt_regex, $opt_noconf);
 my ($opt_package, $opt_uversion, $opt_watchfile, $opt_dehs, $opt_timeout);
 my $opt_user_agent;
 
 GetOptions("help" => \$opt_h,
           "version" => \$opt_v,
+          "destdir=s" => \$opt_destdir,
           "download!" => \$opt_download,
           "force-download" => \$opt_force_download,
           "report" => sub { $opt_download = 0; },
@@ -271,6 +280,7 @@
 
 # Now we can set the other variables according to the command line options
 
+$destdir = $opt_destdir if defined $opt_destdir;
 $download = $opt_download if defined $opt_download;
 $force_download = $opt_force_download if defined $opt_force_download;
 $report = $opt_report if defined $opt_report;
@@ -1019,18 +1029,22 @@
     }
 
     if (defined $pkg_dir) {
-       if (-f "../$newfile_base") {
+       if (! -d "$destdir") {
+           print "Package directory '$destdir to store downloaded file is not 
existing\n";
+           return 1;
+       }
+       if (-f "$destdir/$newfile_base") {
            print " => $newfile_base already in package directory\n"
                if $verbose or ($download == 0 and ! $dehs);
            return 0;
        }
-       if (-f "../${pkg}_${newversion}.orig.tar.gz") {
-           print " => ${pkg}_${newversion}.orig.tar.gz already in package 
directory\n"
+       if (-f "$destdir/${pkg}_${newversion}.orig.tar.gz") {
+           print " => ${pkg}_${newversion}.orig.tar.gz already in package 
directory '$destdir'\n"
                if $verbose or ($download == 0 and ! $dehs);
            return 0;
        }
-       elsif (-f "../${pkg}_${newversion}.orig.tar.bz2") {
-           print " => ${pkg}_${newversion}.orig.tar.bz2 already in package 
directory\n"
+       elsif (-f "$destdir/${pkg}_${newversion}.orig.tar.bz2") {
+           print " => ${pkg}_${newversion}.orig.tar.bz2 already in package 
directory '$destdir'\n"
                if $verbose or ($download == 0 and ! $dehs);
            return 0;
        }
@@ -1063,6 +1077,10 @@
     return 0 unless $download;
 
     print "-- Downloading updated package $newfile_base\n" if $verbose;
+    if (! -d "$destdir") {
+        print "Package directory '$destdir to store downloaded file is not 
existing\n";
+        return 1;
+    }
     # Download newer package
     if ($upstream_url =~ m%^http(s)?://%) {
        if (defined($1) and !$haveSSL) {
@@ -1072,7 +1090,7 @@
        # Is anything else than "&amp;" required?  I doubt it.
        print STDERR "$progname debug: requesting URL $upstream_url\n" if 
$debug;
        $request = HTTP::Request->new('GET', $upstream_url);
-       $response = $user_agent->request($request, "../$newfile_base");
+       $response = $user_agent->request($request, "$destdir/$newfile_base");
        if (! $response->is_success) {
            if (defined $pkg_dir) {
                warn "$progname warning: In directory $pkg_dir, downloading\n  
$upstream_url failed: " . $response->status_line . "\n";
@@ -1089,7 +1107,7 @@
        }
        print STDERR "$progname debug: requesting URL $upstream_url\n" if 
$debug;
        $request = HTTP::Request->new('GET', "$upstream_url");
-       $response = $user_agent->request($request, "../$newfile_base");
+       $response = $user_agent->request($request, "$destdir/$newfile_base");
        if (exists $options{'pasv'}) {
            if (defined $passive) { $ENV{'FTP_PASSIVE'}=$passive; }
            else { delete $ENV{'FTP_PASSIVE'}; }
@@ -1105,26 +1123,26 @@
     }
 
     if ($newfile_base =~ /\.(tar\.gz|tgz|tar\.bz2|tbz2?)$/) {
-       my $filetype = `file ../$newfile_base`;
+       my $filetype = `file $destdir/$newfile_base`;
        $filetype =~ s%^\.\./\Q$newfile_base\E: %%;
        unless ($filetype =~ /compressed data/) {
-           warn "$progname warning: ../$newfile_base does not appear to be a 
compressed file;\nthe file command says: $filetype\nNot processing this file 
any further!\n";
+           warn "$progname warning: $destdir/$newfile_base does not appear to 
be a compressed file;\nthe file command says: $filetype\nNot processing this 
file any further!\n";
            return 1;
        }
     }
 
     if ($newfile_base =~ /\.(tar\.gz|tgz)$/) {
        if ($symlink eq 'symlink') {
-           symlink $newfile_base, "../${pkg}_${newversion}.orig.tar.gz";
+           symlink $newfile_base, "$destdir/${pkg}_${newversion}.orig.tar.gz";
        } elsif ($symlink eq 'rename') {
-           move "../$newfile_base", "../${pkg}_${newversion}.orig.tar.gz";
+           move "$destdir/$newfile_base", 
"$destdir/${pkg}_${newversion}.orig.tar.gz";
        }
     }
     elsif ($newfile_base =~ /\.(tar\.bz2|tbz2?)$/) {
        if ($symlink eq 'symlink') {
-           symlink $newfile_base, "../${pkg}_${newversion}.orig.tar.bz2";
+           symlink $newfile_base, "$destdir/${pkg}_${newversion}.orig.tar.bz2";
        } elsif ($symlink eq 'rename') {
-           move "../$newfile_base", "../${pkg}_${newversion}.orig.tar.bz2";
+           move "$destdir/$newfile_base", 
"$destdir/${pkg}_${newversion}.orig.tar.bz2";
        }
     }
 
@@ -1181,14 +1199,14 @@
 
     # Do whatever the user wishes to do
     if ($action) {
-       my $usefile = "../$newfile_base";
+       my $usefile = "$destdir/$newfile_base";
        if ($symlink =~ /^(symlink|rename)$/
            and $newfile_base =~ /\.(tar\.gz|tgz)$/) {
-           $usefile = "../${pkg}_${newversion}.orig.tar.gz";
+           $usefile = "$destdir/${pkg}_${newversion}.orig.tar.gz";
        }
        elsif ($symlink =~ /^(symlink|rename)$/
            and $newfile_base =~ /\.(tar\.bz2|tbz2)$/) {
-           $usefile = "../${pkg}_${newversion}.orig.tar.bz2";
+           $usefile = "$destdir/${pkg}_${newversion}.orig.tar.bz2";
        }
 
        # Any symlink requests are already handled by uscan

Reply via email to