Class: R10K::Forge::ModuleRelease
- Inherits:
-
Object
- Object
- R10K::Forge::ModuleRelease
- Includes:
- Logging, Settings::Mixin
- Defined in:
- lib/r10k/forge/module_release.rb
Overview
Download, unpack, and install modules from the Puppet Forge
Constant Summary
Constants included from Logging
Instance Attribute Summary collapse
-
#download_path ⇒ Pathname
Where the module tarball will be downloaded to.
-
#forge_release ⇒ Object
readonly
Returns the value of attribute forge_release.
-
#unpack_path ⇒ Pathname
Where the module will be unpacked to.
Instance Method Summary collapse
-
#cleanup ⇒ Object
Remove all files created while downloading and unpacking the module.
-
#cleanup_download_path ⇒ Object
Remove the downloaded module release.
-
#cleanup_unpack_path ⇒ Object
Remove the temporary directory used for unpacking the module.
-
#download ⇒ void
Download the module release to #download_path.
-
#initialize(full_name, version) ⇒ ModuleRelease
constructor
A new instance of ModuleRelease.
-
#install(target_dir) ⇒ void
Download, unpack, and install this module release to the target directory.
-
#unpack(target_dir) ⇒ void
Unpack the module release at #download_path into the given target_dir.
-
#verify ⇒ void
Verify the module release downloaded to #download_path against the module release checksum given by the Puppet Forge.
Methods included from Logging
debug_formatter, default_formatter, default_outputter, #logger, #logger_name, parse_level
Methods included from Settings::Mixin
Constructor Details
#initialize(full_name, version) ⇒ ModuleRelease
Returns a new instance of ModuleRelease.
36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/r10k/forge/module_release.rb', line 36 def initialize(full_name, version) @full_name = PuppetForge::V3.normalize_name(full_name) @version = version # Copy the PuppetForge base connection to the release class; the connection # objects are created in the class instances and thus are not shared with # subclasses. PuppetForge::V3::Release.conn = PuppetForge::V3::Base.conn @forge_release = PuppetForge::V3::Release.new({ :name => @full_name, :version => @version, :slug => "#{@full_name}-#{@version}" }) @download_path = Pathname.new(Dir.mktmpdir) + (@forge_release.slug + '.tar.gz') @unpack_path = Pathname.new(Dir.mktmpdir) + @forge_release.slug end |
Instance Attribute Details
#download_path ⇒ Pathname
Returns Where the module tarball will be downloaded to.
28 29 30 |
# File 'lib/r10k/forge/module_release.rb', line 28 def download_path @download_path end |
#forge_release ⇒ Object (readonly)
Returns the value of attribute forge_release.
24 25 26 |
# File 'lib/r10k/forge/module_release.rb', line 24 def forge_release @forge_release end |
#unpack_path ⇒ Pathname
Returns Where the module will be unpacked to.
32 33 34 |
# File 'lib/r10k/forge/module_release.rb', line 32 def unpack_path @unpack_path end |
Instance Method Details
#cleanup ⇒ Object
Remove all files created while downloading and unpacking the module.
106 107 108 109 |
# File 'lib/r10k/forge/module_release.rb', line 106 def cleanup cleanup_unpack_path cleanup_download_path end |
#cleanup_download_path ⇒ Object
Remove the downloaded module release.
119 120 121 122 123 |
# File 'lib/r10k/forge/module_release.rb', line 119 def cleanup_download_path if download_path.exist? download_path.delete end end |
#cleanup_unpack_path ⇒ Object
Remove the temporary directory used for unpacking the module.
112 113 114 115 116 |
# File 'lib/r10k/forge/module_release.rb', line 112 def cleanup_unpack_path if unpack_path.exist? unpack_path.rmtree end end |
#download ⇒ void
This method returns an undefined value.
Download the module release to #download_path
71 72 73 74 |
# File 'lib/r10k/forge/module_release.rb', line 71 def download logger.debug1 "Downloading #{@forge_release.slug} from #{PuppetForge::Release.conn.url_prefix} to #{@download_path}" @forge_release.download(download_path) end |
#install(target_dir) ⇒ void
This method returns an undefined value.
Download, unpack, and install this module release to the target directory.
60 61 62 63 64 65 66 |
# File 'lib/r10k/forge/module_release.rb', line 60 def install(target_dir) download verify unpack(target_dir) ensure cleanup end |
#unpack(target_dir) ⇒ void
This method returns an undefined value.
Unpack the module release at #download_path into the given target_dir
93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/r10k/forge/module_release.rb', line 93 def unpack(target_dir) logger.debug1 _("Unpacking %{download_path} to %{target_dir} (with tmpdir %{tmp_path})") % {download_path: download_path, target_dir: target_dir, tmp_path: unpack_path} file_lists = PuppetForge::Unpacker.unpack(download_path.to_s, target_dir.to_s, unpack_path.to_s) logger.debug2 _("Valid files unpacked: %{valid_files}") % {valid_files: file_lists[:valid]} if !file_lists[:invalid].empty? logger.debug1 _("These files existed in the module's tar file, but are invalid filetypes and were not unpacked: %{invalid_files}") % {invalid_files: file_lists[:invalid]} end if !file_lists[:symlinks].empty? logger.warn _("Symlinks are unsupported and were not unpacked from the module tarball. %{release_slug} contained these ignored symlinks: %{symlinks}") % {release_slug: @forge_release.slug, symlinks: file_lists[:symlinks]} end end |
#verify ⇒ void
This method returns an undefined value.
Verify the module release downloaded to #download_path against the module release checksum given by the Puppet Forge
83 84 85 86 |
# File 'lib/r10k/forge/module_release.rb', line 83 def verify logger.debug1 "Verifying that #{download_path} matches checksum #{@forge_release.file_md5}" @forge_release.verify(download_path) end |