aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Richard Brown <rbrown@exherbo.org> 2007-01-09 21:35:23 +0000
committerAvatar Richard Brown <rbrown@exherbo.org> 2007-01-09 21:35:23 +0000
commit6148bd0ac128ebc07c7d37a097b316cc3a41e410 (patch)
treeacd5d7d43b5a793331b94621098e5c1979978987
parentaabd5975f3e1167f4845c4794f99d0a7c1722f4d (diff)
downloadpaludis-6148bd0ac128ebc07c7d37a097b316cc3a41e410.tar.gz
paludis-6148bd0ac128ebc07c7d37a097b316cc3a41e410.tar.xz
Add ruby demo to find files not installed by package manager.
-rw-r--r--ruby/demos/find_unmanaged_files.rb103
1 files changed, 103 insertions, 0 deletions
diff --git a/ruby/demos/find_unmanaged_files.rb b/ruby/demos/find_unmanaged_files.rb
new file mode 100644
index 0000000..4ef3e42
--- /dev/null
+++ b/ruby/demos/find_unmanaged_files.rb
@@ -0,0 +1,103 @@
+#!/usr/bin/env ruby
+# vim: set sw=4 sts=4 et tw=80 :
+#
+['Paludis','find','getoptlong'].each {|x| require x}
+
+include Paludis
+
+Log.instance.log_level = LogLevel::Warning
+Log.instance.program_name = $0
+
+def get_contents(repo, files)
+ in_contents= []
+ repo.category_names do |cat|
+ repo.package_names(cat) do |pkg|
+ repo.version_specs(pkg) do |ver|
+ contents = repo.contents(pkg,ver)
+ contents.each do |entry|
+ next if entry.kind_of? ContentsMiscEntry
+ files.each do |file|
+ if entry.name[0,file.length] == file
+ in_contents << entry.name
+ break;
+ end
+ end
+ end
+ end
+ end
+ end
+ return in_contents
+end
+
+opts = GetoptLong.new(
+ [ '--help', '-h', GetoptLong::NO_ARGUMENT ],
+ [ '--version', '-V', GetoptLong::NO_ARGUMENT ],
+ [ '--log-level', GetoptLong::REQUIRED_ARGUMENT ],
+ [ '--config-suffix', '-c', GetoptLong::REQUIRED_ARGUMENT ])
+
+config_suffix = ""
+opts.each do | opt, arg |
+ case opt
+ when '--help'
+ puts "Usage: " + $0 + " [options] directory1 [directory2 ...]"
+ puts
+ puts "Options:"
+ puts " --help Display a help message"
+ puts " --version Display program version"
+ puts
+ puts " --log-level level Set log level (debug, qa, warning, silent)"
+ puts " --config-suffix suffix Set configuration suffix)"
+ exit 0
+
+ when '--version'
+ puts $0.to_s.split(/\//).last + " " + Paludis::Version
+ exit 0
+
+ when '--log-level'
+ case arg
+ when 'debug'
+ Paludis::Log.instance.log_level = Paludis::LogLevel::Debug
+ when 'qa'
+ Paludis::Log.instance.log_level = Paludis::LogLevel::Qa
+ when 'warning'
+ Paludis::Log.instance.log_level = Paludis::LogLevel::Warning
+ when 'silent'
+ Paludis::Log.instance.log_level = Paludis::LogLevel::Silent
+ else
+ puts "Bad --log-level value " + arg
+ exit 1
+ end
+
+ when '--config-suffix'
+ config_suffix = arg
+
+ end
+end
+
+files = []
+
+if ARGV.empty?
+ puts "No directory to check"
+ exit 1
+else
+ ARGV.each do |file|
+ unless File.directory? file
+ puts "#{file} is not a directory."
+ exit 1
+ end
+ files << (file[-1] == ?/ ? file.chop : file)
+ end
+end
+
+in_fs = []
+Find.find(*files) {|file| in_fs << file}
+
+Paludis::DefaultConfig::config_suffix = config_suffix
+db = DefaultEnvironment.instance.package_database
+
+db.repositories.each do |repo|
+ next unless repo.installed_interface
+ in_fs-= get_contents(repo, files)
+end
+
+puts in_fs