[Pkg-ruby-extras-maintainers] r615 - tools/ruby-pkg-tools/trunk/bin

Esteban Manchado Velázquez zoso at costa.debian.org
Sun Jun 11 15:21:45 UTC 2006


Author: zoso
Date: 2006-06-11 15:21:44 +0000 (Sun, 11 Jun 2006)
New Revision: 615

Modified:
   tools/ruby-pkg-tools/trunk/bin/pkg-ruby-get-sources
Log:
- Drop support for sources file
- Convert every puts "I: ..." and puts "E: ..." to calls to the new functions
  info_msg and error_msg
- Minor cleanups


Modified: tools/ruby-pkg-tools/trunk/bin/pkg-ruby-get-sources
===================================================================
--- tools/ruby-pkg-tools/trunk/bin/pkg-ruby-get-sources	2006-06-11 07:20:13 UTC (rev 614)
+++ tools/ruby-pkg-tools/trunk/bin/pkg-ruby-get-sources	2006-06-11 15:21:44 UTC (rev 615)
@@ -27,14 +27,20 @@
 require 'open-uri'
 require 'rexml/document'
 
-$sources_file = "/usr/share/ruby-pkg-tools/pkg-ruby-extras.sources"
-$sources_url = "http://pkg-ruby-extras.alioth.debian.org/pkg-ruby-extras.sources"
+$watch_file = 'debian/watch'
 $target_directory = "../tarballs"
 $verbose = false
 $list_available = false
 
+def info_msg(text)
+  puts "I: #{text}"
+end
+
+def error_msg(text)
+  puts "E: #{text}"
+end
+
 opts = GetoptLong.new(
-  [ "--sources",           "-s",  GetoptLong::REQUIRED_ARGUMENT ],
   [ "--target-directory",  "-t",  GetoptLong::REQUIRED_ARGUMENT ],
   [ "--verbose",           "-v",  GetoptLong::NO_ARGUMENT ],
   [ "--list-available",    "-l",  GetoptLong::NO_ARGUMENT ],
@@ -43,7 +49,6 @@
 )
 
 help = {
-  "--sources" => "indicates the sources file (defaults to #{$sources_file})",
   "--target-directory" => "indicates where to put downloaded tarballs (defaults to #{$target_directory})",
   "--verbose" => "display verbose information while running",
   "--list-available" => "does not download any file; only list available packages and versions",
@@ -66,8 +71,6 @@
     case opt
       when '--verbose'
         $verbose = true
-      when '--sources'
-        $sources_file = val
       when '--target-directory'
         $target_directory = val
       when '--help'
@@ -88,21 +91,20 @@
   exit 1
 end
 
-puts "I: Running in verbose mode" if $verbose
-puts "I: Reading sources from #{$sources_url}, #{$sources_file}" if $verbose
-puts "I: Downloading files to #{$target_directory}" if $verbose
+info_msg("Running in verbose mode") if $verbose
+info_msg("Downloading files to #{$target_directory}") if $verbose
 
 if (!$list_available and ! (File.directory?($target_directory) and File.writable?($target_directory)))
-  puts "E: #{$target_directory} should be a valid writable directory."
+  error_msg("#{$target_directory} should be a valid writable directory")
   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
+  info_msg("Trying to guess package name and version from debian/changelog ... ") if $verbose
   if !File.readable?("debian/changelog")
-    puts "E: Couldn't read debian/changelog"
+    error_msg("Couldn't read debian/changelog")
     exit 2
   end
 
@@ -111,19 +113,19 @@
   matches = /^(\S+)\s*\(([^-]+)-([^-]+)\)/.match(changelogline)
   package = matches[1]
   version = matches[2]
-  puts "I: Package: #{package}" if $verbose
-  puts "I: Version: #{version}" if $verbose
+  info_msg("Package: #{package}") if $verbose
+  info_msg("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
+  info_msg("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
+    error_msg("#{exception}") if $verbose
     return false
   end
 
@@ -147,7 +149,7 @@
   begin
     response = Net::HTTP.get_response(URI.parse(uri))
   rescue SocketError => error
-    puts "E: #{error}"
+    error_msg("#{error}")
     return false
   end
 
@@ -155,7 +157,7 @@
     when Net::HTTPSuccess then
       return uri
     when Net::HTTPRedirection then
-      puts "I: Redirecting: #{response['location']}" if $verbose
+      info_msg("Redirecting: #{response['location']}") if $verbose
       return follow(response['location'], limit-1)
     else
       raise Net::HTTPFatalError.new(response.message, response.code)
@@ -172,17 +174,17 @@
   begin
     tarball_url = follow(tarball_url)
   rescue Net::HTTPFatalError => error
-    puts "E: HTTP Error: #{error}"
+    error_msg("HTTP Error: #{error}")
     return false
   end
 
   if tarball_url then
     uri = URI.parse(tarball_url)
   else
-    return false;
+    return false
   end
 
-  puts "I: URL: #{tarball_url}" if $verbose
+  info_msg("URL: #{tarball_url}") if $verbose
   
   source = uri.path.split('/').pop
   ext = nil
@@ -190,12 +192,12 @@
   $extensions.each { |key, val|
     if source.index(key) then
       ext = val ? val : key
-      puts "I: Known archive format: #{source}" if $verbose
+      info_msg("Known archive format: #{source}") if $verbose
     end
   }
   
   if not ext then
-    puts "E: Unknown archive type: #{uri.path}"
+    error_msg("Unknown archive type: #{uri.path}")
     return false
   end
 
@@ -215,7 +217,7 @@
         }
         puts
       }
-      puts "I: Saved #{filename}" if $verbose
+      info_msg("Saved #{filename}") if $verbose
     }
   }
 
@@ -226,7 +228,7 @@
       puts "I: Converting #{filename} to #{orig_tarball}" if $verbose
       system "bzcat '#{filename}' | gzip -c > '#{orig_tarball}'"
     else
-      puts "I: Nothing to do for archive type: #{ext}" if $verbose
+      info_msg("Nothing to do for archive type: #{ext}") if $verbose
   end
 
   return true
@@ -238,9 +240,7 @@
 # first try to download a source tarball by looking at the watch file, if the
 # package has one
 begin
-  watch = File.new('debian/watch')
-  puts "I: Using watch file" if $verbose
-  watch.each { |line|
+  File.readlines($watch_file).each { |line|
     if line =~ /(http|ftp):\/\/\S+/ then
       tarball = Regexp.last_match(0)
       tarball.gsub!(/\\/, '')
@@ -248,73 +248,49 @@
 
       if not $list_available then
         if tarball then
-          puts "I: Found source tarball for package #{package}-#{version}: #{tarball}" if $verbose
+          info_msg("Found source tarball for package #{package}-#{version}: #{tarball}") if $verbose
           if download(package,version,tarball) then
-            watch.close
             exit 0
           end
         else
-          puts "I: Found no source tarball by looking at the watch file, continuing." if $verbose
+          info_msg("Found no source tarball by looking at the watch file, continuing") if $verbose
         end
       end
     end
   }
-  watch.close
 rescue
-  puts "I: No watch file for this package." if $verbose
+  info_msg("No watch file for this package") if $verbose
 end
 
 # Now try to use the output of uscan --dehs to get a source tarball URL
-if File::exist?('debian/watch')
+if File.exist?($watch_file)
   begin
-    puts "I: Running uscan --dehs and parsing the output ..." if $verbose
+    info_msg("Running uscan --dehs and parsing the output ...") if $verbose
     i = IO::popen('uscan --dehs')
     d = REXML::Document::new(i.read)
     i.close
     v = d.elements['/dehs/upstream-version'].text
     if v == version
       tarball = d.elements['/dehs/upstream-url'].text
-      puts "I: Found source tarball for package #{package}-#{version}: #{tarball}" if $verbose
+      info_msg("Found source tarball for package #{package}-#{version}: #{tarball}") if $verbose
       if download(package,version,tarball) then
         exit 0
       end
     else
-      puts "I: uscan --dehs only gave us a tarball for v. #{v}, while we were looking for #{version}." if $verbose
+      info_msg("uscan --dehs only gave us a tarball for v. #{v}, while we were looking for #{version}") if $verbose
     end
   rescue
-    puts "I: The uscan --dehs strategy failed." if $verbose
+    info_msg("The uscan --dehs strategy failed") if $verbose
   end
 end
-  
-# Try to get the source URL from a sources file
-[ $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
-}
 
 # don't go beyond here if all we wanted to do was list available packages
 exit if $list_available
 
 if tarball then
-  puts "I: Found source tarball for package #{package}-#{version}: #{tarball}" if $verbose
+  info_msg("Found source tarball for package #{package}-#{version}: #{tarball}") if $verbose
 else
-  puts "E: No source tarball found for package #{package}-#{version}."
+  error_msg("No source tarball found for package #{package}-#{version}")
   exit 2
 end
 




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