[DRE-commits] [SCM] pkg-ruby-extras.git branch, master, updated. aac2be6f2015ef2fc242a1e8310f95157e440a30

Antonio Terceiro terceiro at softwarelivre.org
Fri Jul 29 06:49:58 UTC 2011


The following commit has been merged in the master branch:
commit 843dec7d8bbefc9175c045855d8e5d72df0efe02
Author: Antonio Terceiro <terceiro at softwarelivre.org>
Date:   Thu Jul 28 23:41:11 2011 -0700

    cache rmadison results for 1 hour

diff --git a/pkg-overview b/pkg-overview
index d1c32b4..9e384a5 100755
--- a/pkg-overview
+++ b/pkg-overview
@@ -2,6 +2,8 @@
 
 require 'peach'
 require 'pp'
+require 'time'
+require 'fileutils'
 
 class DebVersion
   include Comparable
@@ -29,16 +31,37 @@ module Enumerable
   end
 end
 
+$CACHE_DIR = File.join(ENV['HOME'], '.cache', 'pkg-ruby-extras', 'pkg-overview')
+$CACHE_TAG = Time.now.strftime('%y%m%d%H') # keep the cache for 1 hour
+
+def initialize_cache
+  FileUtils.mkdir_p($CACHE_DIR)
+  Dir.glob(File.join($CACHE_DIR, '*')).each do |f|
+    if f !~ /\.#{$CACHE_TAG}$/
+      File.unlink(f)
+    end
+  end
+end
+
 def rmadison_to_version(src)
   ok = false
-  begin
-    s = `rmadison #{src}`
-    if s =~ /Internal Server Error/
-      STDERR.puts "WARNING: `rmadison #{src}` Failed. Retrying."
-    else
-      ok = true
-    end
-  end while not ok
+  cache_file = File.join($CACHE_DIR, src + '.' + $CACHE_TAG)
+  s = nil
+  if File.exists?(cache_file)
+    s = File.read(cache_file)
+  else
+    begin
+      s = `rmadison #{src}`
+      if s =~ /Internal Server Error/
+        STDERR.puts "WARNING: `rmadison #{src}` Failed. Retrying."
+      else
+        File.open(cache_file, 'w') do |f|
+          f.write(s)
+        end
+        ok = true
+      end
+    end while not ok
+  end
   return nil if s == ""
   return s.lines.grep(/ sid( |\/).* source/) \
     .map { |l| l.gsub(/^[^|]*\|\s*([^ ]*)\s*\|.*/, '\1').chomp } \
@@ -97,6 +120,8 @@ def compute_status(src, cv, tv, av)
   return '0 ERROR: unknown status'
 end
 
+initialize_cache
+
 # get source packages from command line, or all available ones of none passed.
 source_packages = ARGV.size > 0 ? ARGV : Dir.glob('*/debian/changelog').map { |f| File.dirname(File.dirname(f)) }.sort
 #

-- 
pkg-ruby-extras.git



More information about the Pkg-ruby-extras-commits mailing list