[Pkg-ruby-extras-maintainers] r224 - in tools/ruby-pkg-tools/trunk: bin debian

Thierry Reding beatle-guest at costa.debian.org
Thu Jan 5 19:48:19 UTC 2006


Author: beatle-guest
Date: 2006-01-05 19:48:18 +0000 (Thu, 05 Jan 2006)
New Revision: 224

Modified:
   tools/ruby-pkg-tools/trunk/bin/pkg-ruby-get-sources
   tools/ruby-pkg-tools/trunk/debian/changelog
Log:
* pkg-ruby-get-sources:
   + The script is now more modularized, which made the following steps
     easier to implement.
   + Now uses pkg-ruby-extras.sources from the ruby-pkg-tools package as
     default sources file, falling back to the sources file on the project
     website if a tarball URL for the given package is not found in the
     local copy.


Modified: tools/ruby-pkg-tools/trunk/bin/pkg-ruby-get-sources
===================================================================
--- tools/ruby-pkg-tools/trunk/bin/pkg-ruby-get-sources	2006-01-05 02:13:22 UTC (rev 223)
+++ tools/ruby-pkg-tools/trunk/bin/pkg-ruby-get-sources	2006-01-05 19:48:18 UTC (rev 224)
@@ -27,7 +27,7 @@
 require 'open-uri'
 
 $sources_file = "/usr/share/ruby-pkg-tools/pkg-ruby-extras.sources"
-$sources_url = "http://pkg-ruby-extras.alioth.debian.org/sources"
+$sources_url = "http://pkg-ruby-extras.alioth.debian.org/pkg-ruby-extras.sources"
 $target_directory = "../tarballs"
 $verbose = false
 $list_available = false
@@ -86,6 +86,49 @@
   exit 1
 end
 
+# guess package name and version from debian/changelog
+# ex: liblocale-ruby (0.1-2)
+def guess_package()
+  puts "I: Trying to guess package name and version from debian/changelog ... " if $verbose
+  if !File.readable?("debian/changelog")
+    puts "E: Couldn't read debian/changelog"
+    exit 2
+  end
+
+  # guess a package's name and version from debian/changelog
+  changelogline = File.read("debian/changelog").split(/\n/)[0]
+  matches = /^(\S+)\s*\(([^-]+)-([^-]+)\)/.match(changelogline)
+  package = matches[1]
+  version = matches[2]
+  puts "I: Package: #{package}" if $verbose
+  puts "I: Version: #{version}" if $verbose
+
+  return [ package, version ]
+end
+
+# reads a YAML object from a given sources file
+def get_available_sources(source_file)
+  puts "I: Loading available sources from #{source_file} ... " if $verbose
+  begin
+    sources = open(source_file) { |io| YAML::load(io) }
+  rescue Exception => exception
+    puts "E: #{exception}" if $verbose
+    return false
+  end
+
+  return sources
+end
+
+# list available packages from a sources file
+def list_packages(sources)
+  sources.each { |package,versions|
+    versions.each { |version,tarball_url|
+      puts "#{package}-#{version}"
+    }
+  }
+end
+
+# downloads a given package from a specified URL
 def download(package,version,tarball_url)
   uri = URI.parse(tarball_url)
   Net::HTTP.start(uri.host, uri.port) { |http|
@@ -108,60 +151,42 @@
   }
 end
 
-begin
-  print "I: Trying to open #{$sources_url}... " if $verbose
-  sources = open($sources_url) { |io| YAML::load(io) }
-rescue
-  puts "failed" if $verbose
-  begin
-    print "I: Trying to open #{$sources_file}... " if $verbose
-    sources = open($sources_file) { |io| YAML::load(io) }
-  rescue
-    puts "failed" if $verbose
-    exit 2
+package, version = guess_package
+tarball = false
+
+[ $sources_file, $sources_url ].each { |file|
+  sources = get_available_sources(file)
+  if (sources) then
+    if $list_available then
+      list_packages(sources)
+    else
+      if sources[package] then
+        if sources[package][version] then
+          tarball = sources[package][version]
+          break
+        else
+          puts "E: #{package}'s version #{version} is not available (in #{file})."
+        end
+      else
+        puts "E: Package #{package} is not available (in #{file})."
+        next
+      end
+    end
   end
-end
+}
 
-puts "done" if $verbose
+# don't go beyond here if all we wanted to do was list available packages
+exit if $list_available
 
-# only list available packages
-if $list_available
-  sources.each { |package,versions|
-    versions.each { |version,tarball_url|
-      puts "#{package}-#{version}"
-    }
-  }
-  exit 
-end
-
-# guess package name and version from debian/changelog
-# ex: liblocale-ruby (0.1-2)
-puts "I: trying to guess package name and version from debian/changelog ..." if $verbose
-if ! File.readable?("debian/changelog")
-  puts "E: couldn't read debian/changelog"
+if tarball then
+  puts "I: Found source tarball for package #{package}-#{version}: #{tarball}"
+else
+  puts "E: No source tarball found for package #{package}-#{version}."
   exit 2
 end
 
-# guesse package's name and version from debian/changelog
-changelogline = File.read("debian/changelog").split(/\n/)[0]
-matches = /^(\S+)\s*\(([^-]+)-([^-]+)\)/.match(changelogline)
-package = matches[1]
-version = matches[2]
-puts "I: Package: #{package}" if $verbose
-puts "I: Version: #{version}" if $verbose
-
 # actually download package
-if sources[package]
-  if sources[package][version]
-    download(package,version,sources[package][version])
-  else
-    puts "E: #{package}'s version #{version} is not available (in #{$sources_file})"
-    exit 2
-  end
-else
-  puts "E: Package #{package} is not available (in #{$sources_file})"
-  exit 2
-end
+download(package,version,tarball)
 
-# vim: sts=2 ts=2 et
+# vi: sts=2 sw=2 ts=2 et
 

Modified: tools/ruby-pkg-tools/trunk/debian/changelog
===================================================================
--- tools/ruby-pkg-tools/trunk/debian/changelog	2006-01-05 02:13:22 UTC (rev 223)
+++ tools/ruby-pkg-tools/trunk/debian/changelog	2006-01-05 19:48:18 UTC (rev 224)
@@ -5,13 +5,16 @@
 
   [ Thierry Reding ]
   * pkg-ruby-get-sources:
-     + Now defaults to using the sources file at the URL
-       `http://pkg-ruby-extras.alioth.debian.org/sources'. The file at
-       `/usr/share/ruby-pkg-tools/pkg-ruby-extras.sources' is used as
-       fallback.
+     + The script is now more modularized, which made the following steps
+       easier to implement.
+     + Now uses pkg-ruby-extras.sources from the ruby-pkg-tools package as
+       default sources file, falling back to the sources file on the project
+       website if a tarball URL for the given package is not found in the
+       local copy.
      + The `--sources' switch can now also handle HTTP, HTTPS and FTP URLs.
+     + The script now also has a vi modeline. =)
 
- -- Thierry Reding <thierry at doppeltgemoppelt.de>  Thu,  5 Jan 2006 00:47:21 +0100
+ -- Thierry Reding <thierry at doppeltgemoppelt.de>  Thu,  5 Jan 2006 20:45:50 +0100
 
 ruby-pkg-tools (0.5) unstable; urgency=low
 




More information about the pkg-ruby-extras-maintainers mailing list