aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar David Leverton <levertond@googlemail.com> 2008-01-04 22:13:51 +0000
committerAvatar David Leverton <levertond@googlemail.com> 2008-01-04 22:13:51 +0000
commit25b149ccab1a7321795f610b56fe850f38aaca0e (patch)
tree3254d5843c9501b694c767e1743c70e4171a3cc9
parent913279cc629ab079a1d9a1adcdbdf574330733d8 (diff)
downloadpaludis-25b149ccab1a7321795f610b56fe850f38aaca0e.tar.gz
paludis-25b149ccab1a7321795f610b56fe850f38aaca0e.tar.xz
(ruby) Add options to not delete files that are too big or too new to find_unused_distfiles.rb.
-rwxr-xr-xruby/demos/find_unused_distfiles.rb42
1 files changed, 40 insertions, 2 deletions
diff --git a/ruby/demos/find_unused_distfiles.rb b/ruby/demos/find_unused_distfiles.rb
index 65f106c..813d962 100755
--- a/ruby/demos/find_unused_distfiles.rb
+++ b/ruby/demos/find_unused_distfiles.rb
@@ -11,9 +11,12 @@ opts = GetoptLong.new(
[ '--help', '-h', GetoptLong::NO_ARGUMENT ],
[ '--version', '-V', GetoptLong::NO_ARGUMENT ],
[ '--log-level', GetoptLong::REQUIRED_ARGUMENT ],
- [ '--environment', '-E', GetoptLong::REQUIRED_ARGUMENT ])
+ [ '--environment', '-E', GetoptLong::REQUIRED_ARGUMENT ],
+ [ '--size-limit', '-s', GetoptLong::REQUIRED_ARGUMENT ],
+ [ '--time-limit', '-t', GetoptLong::REQUIRED_ARGUMENT ])
env_spec = ""
+size_limit = time_limit = nil
opts.each do | opt, arg |
case opt
when '--help'
@@ -25,6 +28,9 @@ opts.each do | opt, arg |
puts
puts " --log-level level Set log level (debug, qa, warning, silent)"
puts " --environment env Environment specification (class:suffix, both parts optional)"
+ puts
+ puts " --size-limit limit Don't delete anything bigger than limit (number followed by one of g, m, k, b)"
+ puts " --time-limit limit Don't delete anything newer than limit (number followed by one of h, d, w, m, y)"
exit 0
when '--version'
@@ -49,6 +55,35 @@ opts.each do | opt, arg |
when '--environment'
env_spec = arg
+ when '--size-limit'
+ if arg =~ /^[0-9]+[gmkb]$/i then
+ size_limit = arg[0..-2].to_i *
+ case arg.downcase[-1]
+ when ?b: 1
+ when ?k: 1024
+ when ?m: 1024 * 1024
+ when ?g: 1024 * 1024 * 1024
+ end
+ else
+ puts "Bad --size-limit value " + arg
+ exit 1
+ end
+
+ when '--time-limit'
+ if arg =~ /^[0-9]+[ymwdh]/ then
+ time_limit = Time.now - arg[0..-2].to_i *
+ case arg.downcase[-1]
+ when ?h: 60 * 60
+ when ?d: 60 * 60 * 24
+ when ?w: 60 * 60 * 24 * 7
+ when ?m: 60 * 60 * 24 * 30
+ when ?y: 60 * 60 * 24 * 365
+ end
+ else
+ puts "Bad --time-limit value " + arg
+ exit 1
+ end
+
end
end
@@ -95,7 +130,10 @@ end
# display each unused distfile
distdirs.each do | dir |
Dir.new(dir).sort.each do | file |
- File.new(dir + "/" + file).stat.file? or next
+ stat = File.new(dir + "/" + file).stat
+ stat.file? or next
+ stat.size >= size_limit and next unless size_limit.nil?
+ stat.mtime >= time_limit and next unless time_limit.nil?
puts dir + "/" + file unless parts[file]
end
end