[Dehs-devel] SVN devscripts commit: r375 - in trunk: . debian

Julian Gilbey jdg at costa.debian.org
Sun Apr 2 09:42:34 UTC 2006


Author: jdg
Date: 2006-04-02 09:42:30 +0000 (Sun, 02 Apr 2006)
New Revision: 375

Modified:
   trunk/debian/changelog
   trunk/uscan.1
   trunk/uscan.pl
Log:
* uscan: provide downloadurlmangle and filenamemangle options to mangle
  the URL and filename before attempting to perform and save the
  download respectively (Closes: #327404)

Modified: trunk/debian/changelog
===================================================================
--- trunk/debian/changelog	2006-03-31 17:51:03 UTC (rev 374)
+++ trunk/debian/changelog	2006-04-02 09:42:30 UTC (rev 375)
@@ -9,12 +9,13 @@
   * mass-bug: new script (Closes: #355505)
   * pts-subscribe.1: improve the wording of the manpage (Closes: #360027)
   * uscan: *really* fix the uninitialized value bug (Closes: #356959)
-  * uscan: provide filenamemangle option to mangle the filename before
-    attempting to save the download (Closes: #327404)
+  * uscan: provide downloadurlmangle and filenamemangle options to mangle
+    the URL and filename before attempting to perform and save the
+    download respectively (Closes: #327404)
   * who-uploads: new script to determine most recent uploaders of a
     package to the Debian archive (Closes: #347809)
 
- -- Julian Gilbey <jdg at debian.org>  Fri, 31 Mar 2006 18:27:53 +0100
+ -- Julian Gilbey <jdg at debian.org>  Sun,  2 Apr 2006 10:42:14 +0100
 
 devscripts (2.9.16) unstable; urgency=low
 

Modified: trunk/uscan.1
===================================================================
--- trunk/uscan.1	2006-03-31 17:51:03 UTC (rev 374)
+++ trunk/uscan.1	2006-04-02 09:42:30 UTC (rev 375)
@@ -86,7 +86,9 @@
 opts=dversionmangle=s/\\.dfsg\\.\\d+$// \\
   http://some.site.org/some/path/foobar-(.*)\\.tar\\.gz
 
-# Handling cases where the URL would not make a usable filename
+# The filename is found by taking the last component of the URL and
+# removing everything after any '?'.  If this would not make a usable
+# filename, use filenamemangle.  For example,
 # <A href="http://foo.bar.org/download/?path=&amp;download=foo-0.1.1.tar.gz">
 # could be handled as:
 # opts=filenamemangle=s/.*=(.*)/$1/ \
@@ -97,6 +99,14 @@
 # opts=filenamemangle=s/.*=(.*)/foo-$1\.tar\.gz/ \
 #    http://foo.bar.org/download/\?path=&amp;download_version=(.*)
 
+# The option downloadurlmangle can be used to mangle the URL of the file
+# to download.  This can only be used with http:// URLs.  This may be
+# necessary if the link given on the webpage needs to be transformed in
+# some way into one which will work automatically, for example:
+# opts=downloadurlmangle=s/prdownload/download/ \
+#   http://developer.berlios.de/project/showfiles.php?group_id=2051 \
+#   http://prdownload.berlios.de/softdevice/vdr-softdevice-(.*).tgz
+
 .fi
 .PP
 Comment lines may be introduced with a `#' character.  Continuation
@@ -234,7 +244,15 @@
 This is used to mangle the filename with which the downloaded file
 will be saved, and is parsed in the same way as the
 \fBuversionmangle\fR option.  Examples of its use are given in the
-examples above.
+examples section above.
+.TP
+\fBdownloadurlmangle=\fIrules\fR
+This is used to mangle the URL to be used for the download.  The URL
+is first computed based on the homepage downloaded and the pattern
+matched, then the version number is determined from this URL.
+Finally, any rules given by this option are applied before the actual
+download attempt is made. An example of its use is given in the
+examples section above.
 .SH "Directory name checking"
 Similarly to several other scripts in the \fBdevscripts\fR package,
 \fBuscan\fR explores the requested directory trees looking for

Modified: trunk/uscan.pl
===================================================================
--- trunk/uscan.pl	2006-03-31 17:51:03 UTC (rev 374)
+++ trunk/uscan.pl	2006-04-02 09:42:30 UTC (rev 375)
@@ -6,8 +6,7 @@
 # Originally written by Christoph Lameter <clameter at debian.org> (I believe)
 # Modified by Julian Gilbey <jdg at debian.org>
 # HTTP support added by Piotr Roszatycki <dexter at debian.org>
-# Copyright 1999, Julian Gilbey
-# Rewritten in Perl, Copyright 2002, Julian Gilbey
+# Rewritten in Perl, Copyright 2002-2006, Julian Gilbey
 #
 # 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
@@ -122,7 +121,7 @@
 sub version {
     print <<"EOF";
 This is $progname, from the Debian devscripts package, version ###VERSION###
-This code is copyright 1999 by Julian Gilbey, all rights reserved.
+This code is copyright 1999-2006 by Julian Gilbey, all rights reserved.
 Original code by Christoph Lameter.
 This program comes with ABSOLUTELY NO WARRANTY.
 You are free to redistribute this code under the terms of the
@@ -590,7 +589,16 @@
 # as:
 # opts=filenamemangle=s/.*=(.*)/foo-$1\.tar\.gz/ \
 #    http://foo.bar.org/download/\?path=&amp;download_version=(.*)
+# 
+# The option downloadurlmangle can be used to mangle the URL of the file
+# to download.  This can only be used with http:// URLs.  This may be
+# necessary if the link given on the webpage needs to be transformed in
+# some way into one which will work automatically, for example:
+# opts=downloadurlmangle=s/prdownload/download/ \
+#   http://developer.berlios.de/project/showfiles.php?group_id=2051 \
+#   http://prdownload.berlios.de/softdevice/vdr-softdevice-(.*).tgz
 
+
 sub process_watchline ($$$$$$)
 {
     my ($line, $watch_version, $pkg_dir, $pkg, $pkg_version, $watchfile) = @_;
@@ -665,6 +673,9 @@
 		elsif ($opt =~ /^filenamemangle\s*=\s*(.+)/) {
 		    @{$options{'filenamemangle'}} = split /;/, $1;
 		}
+		elsif ($opt =~ /^downloadurlmangle\s*=\s*(.+)/) {
+		    @{$options{'downloadurlmangle'}} = split /;/, $1;
+		}
 		else {
 		    warn "$progname warning: unrecognised option $opt\n";
 		}
@@ -685,6 +696,11 @@
 	    $base =~ s%/[^/]+$%/%;
 	}
 
+	# Check validity of options
+	if ($base =~ /^ftp:/ and exists $options{'downloadurlmangle'}) {
+	    warn "$progname warning: downloadurlmangle option invalid for ftp sites,\n  ignoring in $watchfile:\n  $line\n";
+	}
+
 	# Handle sf.net addresses specially
 	$base =~ s%^http://sf\.net/%http://qa.debian.org/watch/sf.php/%;
 	if ($base =~ m%^(\w+://[^/]+)%) {
@@ -856,17 +872,19 @@
     }
 
     my $newfile_base=basename($newfile);
-    if (exists $options{'filenamemangle'})
-    {
+    if (exists $options{'filenamemangle'}) {
         $newfile_base=$newfile;
     }
     foreach my $pat (@{$options{'filenamemangle'}}) {
 	eval "\$newfile_base =~ $pat;";
     }
     # Remove HTTP header trash
-    if ($site =~ m%^http://%)
-    {
+    if ($site =~ m%^http://%) {
         $newfile_base =~ s/\?.*$//;
+	# just in case this leaves us with nothing
+	if ($newfile_base eq '') {
+	    $newfile_base = "$pkg-$newversion.download";
+	}
     }
     if (! $lastversion or $lastversion eq 'debian') {
 	$lastversion=$pkg_version;
@@ -893,6 +911,14 @@
 	else {
 	    $upstream_url = "$urlbase$newfile";
 	}
+
+	# mangle if necessary
+	$upstream_url =~ s/&amp;/&/g;
+	if (exists $options{'downloadurlmangle'}) {
+	    foreach my $pat (@{$options{'downloadurlmangle'}}) {
+		eval "\$upstream_url =~ $pat;";
+	    }
+	}
     }
     else {
 	# FTP site
@@ -988,7 +1014,6 @@
     if ($upstream_url =~ m%^http://%) {
 	# substitute HTML entities
 	# Is anything else than "&amp;" required?  I doubt it.
-	$upstream_url =~ s/&amp;/&/g;
 	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");
@@ -1376,15 +1401,15 @@
 	if (exists $dehs_tags{$tag}) {
 	    if (ref $dehs_tags{$tag} eq "ARRAY") {
 		foreach my $entry (@{$dehs_tags{$tag}}) {
-            $entry =~ s/</&lt;/g;
-            $entry =~ s/>/&gt;/g;
+		    $entry =~ s/</&lt;/g;
+		    $entry =~ s/>/&gt;/g;
 		    $entry =~ s/&/&amp;/g;
-            print "<$tag>$entry</$tag>\n";
+		    print "<$tag>$entry</$tag>\n";
 		}
 	    } else {
-            $dehs_tags{$tag} =~ s/</&lt;/g;
-            $dehs_tags{$tag} =~ s/>/&gt;/g;
-		    $dehs_tags{$tag} =~ s/&/&amp;/g;
+		$dehs_tags{$tag} =~ s/</&lt;/g;
+		$dehs_tags{$tag} =~ s/>/&gt;/g;
+		$dehs_tags{$tag} =~ s/&/&amp;/g;
 		print "<$tag>$dehs_tags{$tag}</$tag>\n";
 	    }
 	}




More information about the Dehs-devel mailing list