Class: Puppet::Module::Tool::Applications::Unpacker
- Inherits:
-
Application
- Object
- Application
- Puppet::Module::Tool::Applications::Unpacker
- Defined in:
- lib/puppet/module/tool/applications/unpacker.rb
Instance Attribute Summary
Attributes inherited from Application
Instance Method Summary collapse
- #force? ⇒ Boolean
-
#initialize(filename, environment_path, options = {}) ⇒ Unpacker
constructor
A new instance of Unpacker.
- #run ⇒ Object
Methods inherited from Application
#discuss, #load_modulefile!, #metadata, #parse_filename!, #repository, run
Methods included from Utils::Interrogation
#confirms?, #header, #prompt, #say, #subheader
Constructor Details
#initialize(filename, environment_path, options = {}) ⇒ Unpacker
Returns a new instance of Unpacker.
10 11 12 13 14 15 |
# File 'lib/puppet/module/tool/applications/unpacker.rb', line 10 def initialize(filename, environment_path, = {}) @filename = Pathname.new(filename) @environment_path = Pathname.new(environment_path) parse_filename! super() end |
Instance Method Details
#force? ⇒ Boolean
17 18 19 |
# File 'lib/puppet/module/tool/applications/unpacker.rb', line 17 def force? [:force] end |
#run ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/puppet/module/tool/applications/unpacker.rb', line 21 def run # Check if the module directory already exists. if File.exist?(@module_name) || File.symlink?(@module_name) then if force? then FileUtils.rm_rf @module_name rescue nil else check_clobber! # JJM 2011-06-20 And remove it anyway (This is a dumb way to do it, but... it works.) FileUtils.rm_rf @module_name rescue nil end end build_dir = Puppet::Module::Tool::Cache.base_path + "tmp-unpacker-#{Digest::SHA1.hexdigest(@filename.basename.to_s)}" build_dir.mkpath begin FileUtils.cp @filename, build_dir Dir.chdir(build_dir) do unless system "tar xzf #{@filename.basename}" abort "Could not extract contents of module archive." end end # grab the first directory extracted = build_dir.children.detect { |c| c.directory? } # Nothing should exist at this point named @module_name FileUtils.cp_r extracted, @module_name tag_revision ensure build_dir.rmtree end say "Installed #{@release_name.inspect} into directory: #{@module_name}" end |