diff options
author | Brice Figureau <brice-puppet@daysofwonder.com> | 2009-02-14 16:17:20 +0100 |
---|---|---|
committer | Brice Figureau <brice-puppet@daysofwonder.com> | 2009-02-16 20:12:10 +0100 |
commit | d51398c3eb3c09a9912fff8b4b7656a9ddb6b873 (patch) | |
tree | 2fda33dbe8cced21f3c377b3d0ca13940b604218 /lib | |
parent | 9b9e5e895bef9e59f7d592d6eb687ab1f683c117 (diff) | |
download | puppet-d51398c3eb3c09a9912fff8b4b7656a9ddb6b873.tar.gz puppet-d51398c3eb3c09a9912fff8b4b7656a9ddb6b873.tar.xz puppet-d51398c3eb3c09a9912fff8b4b7656a9ddb6b873.zip |
Move filebucket to the Application Controller paradigm
Signed-off-by: Brice Figureau <brice-puppet@daysofwonder.com>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/puppet/application/filebucket.rb | 92 |
1 files changed, 92 insertions, 0 deletions
diff --git a/lib/puppet/application/filebucket.rb b/lib/puppet/application/filebucket.rb new file mode 100644 index 000000000..f456e0dcc --- /dev/null +++ b/lib/puppet/application/filebucket.rb @@ -0,0 +1,92 @@ +require 'puppet' +require 'puppet/application' +require 'puppet/network/client' + +Puppet::Application.new(:filebucket) do + + should_not_parse_config + + option("--version", "-V") do |arg| + puts "%s" % Puppet.version + exit + end + + option("--bucket BUCKET","-b") + option("--debug","-d") + option("--local","-l") + option("--remote","-r") + option("--verbose","-v") + + dispatch do + ARGV.shift + end + + command(:get) do + md5 = ARGV.shift + out = @client.getfile(md5) + print out + end + + command(:backup) do + ARGV.each do |file| + unless FileTest.exists?(file) + $stderr.puts "%s: no such file" % file + next + end + unless FileTest.readable?(file) + $stderr.puts "%s: cannot read file" % file + next + end + md5 = @client.backup(file) + puts "%s: %s" % [file, md5] + end + end + + command(:restore) do + file = ARGV.shift + md5 = ARGV.shift + @client.restore(file, md5) + end + + setup do + Puppet::Log.newdestination(:console) + + @client = nil + @server = nil + + trap(:INT) do + $stderr.puts "Cancelling" + exit(1) + end + + if options[:debug] + Puppet::Log.level = :debug + elsif options[:verbose] + Puppet::Log.level = :info + end + + # Now parse the config + Puppet.parse_config + + if Puppet.settings.print_configs? + exit(Puppet.settings.print_configs ? 0 : 1) + end + + begin + if options[:local] or options[:bucket] + path = options[:bucket] || Puppet[:bucketdir] + @client = Puppet::Network::Client.dipper.new(:Path => path) + else + require 'puppet/network/handler' + @client = Puppet::Network::Client.dipper.new(:Server => Puppet[:server]) + end + rescue => detail + $stderr.puts detail + if Puppet[:trace] + puts detail.backtrace + end + exit(1) + end + end + +end
\ No newline at end of file |