[DRE-commits] r3362 - tools/ruby-support/trunk/bin

lucas at alioth.debian.org lucas at alioth.debian.org
Sat Apr 4 15:21:31 UTC 2009


Author: lucas
Date: 2009-04-04 15:21:31 +0000 (Sat, 04 Apr 2009)
New Revision: 3362

Modified:
   tools/ruby-support/trunk/bin/ruby-support
Log:
added support for cleaning dirs

Modified: tools/ruby-support/trunk/bin/ruby-support
===================================================================
--- tools/ruby-support/trunk/bin/ruby-support	2009-04-04 14:34:21 UTC (rev 3361)
+++ tools/ruby-support/trunk/bin/ruby-support	2009-04-04 15:21:31 UTC (rev 3362)
@@ -10,6 +10,7 @@
 require 'optparse'
 require 'pp'
 require 'ftools'
+require 'fileutils'
 
 $verbose = (ENV['RS_VERBOSE'] != nil)
 
@@ -38,6 +39,12 @@
 # Path where the real files live
 RS_PATH = '/usr/lib/ruby-support'
 
+# Directories that will be removed from the package if they don't contain any file
+RS_CLEAN_DIRS = [
+  '/usr/lib/ruby',
+  '/usr/lib/jruby'
+]
+
 ### Supported versions management
 def supported_versions_from_string(vlist, rbversions_set = RS_RUBY_VERSIONS)
   my_versions = RS_RUBY_VERSIONS
@@ -231,7 +238,7 @@
   sources = []
   RS_RUBY_LIBDIR.each_pair do |rbv, rbp|
     s = builddir + '/' + rbp
-    next if not Directory::exists?(s)
+    next if not File::directory?(s)
     next if (Dir::entries(s) - [ '.', '..' ]).length == 0
     puts "Found possible source: #{s}"
     sources << s
@@ -256,12 +263,32 @@
 
   source = sources[0]
   target = File::join(builddir, RS_PATH, File::basename(builddir))
+  FileUtils::mkdir_p(target, :verbose => true)
   (Dir::entries(source) - ['.', '..']).each do |e|
     File::move(File::join(source, e), target, true)
   end
   Dir::rmdir(source)
+  RS_CLEAN_DIRS.each do |d|
+    if File::directory?(d)
+      remove_dir_if_empty(builddir + '/' + d)
+    end
+  end
 end
 
+def remove_dir_if_empty(dir)
+  ent = Dir::entries(dir) - ['.', '..']
+  if ent == []
+    Dir::rmdir(dir)
+  else
+    ent.each do |e|
+      if File::directory?(dir + '/' + e)
+        remove_dir_if_empty(dir + '/' + e)
+      end
+    end
+    Dir::rmdir(dir)
+  end
+end
+
 # run tests
 def run_tests
   test_supported_versions




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