Class: Librarian::Puppet::Source::Forge::Repo
- Inherits:
-
Object
- Object
- Librarian::Puppet::Source::Forge::Repo
- Defined in:
- lib/librarian/puppet/source/forge.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#source ⇒ Object
readonly
Returns the value of attribute source.
Instance Method Summary collapse
- #cache_path ⇒ Object
- #cache_version_unpacked!(version) ⇒ Object
- #check_puppet_module_options ⇒ Object
- #debug(*args, &block) ⇒ Object
- #dependencies(version) ⇒ Object
- #environment ⇒ Object
- #hexdigest(value) ⇒ Object
-
#initialize(source, name) ⇒ Repo
constructor
A new instance of Repo.
- #install_version!(version, install_path) ⇒ Object
- #manifests ⇒ Object
- #vendor_cache(name, version) ⇒ Object
- #vendored?(name, version) ⇒ Boolean
- #vendored_path(name, version) ⇒ Object
- #version_unpacked_cache_path(version) ⇒ Object
- #versions ⇒ Object
Constructor Details
#initialize(source, name) ⇒ Repo
Returns a new instance of Repo.
13 14 15 16 17 |
# File 'lib/librarian/puppet/source/forge.rb', line 13 def initialize(source, name) self.source = source self.name = name @api_data = nil end |
Instance Attribute Details
#name ⇒ Object
Returns the value of attribute name.
10 11 12 |
# File 'lib/librarian/puppet/source/forge.rb', line 10 def name @name end |
#source ⇒ Object
Returns the value of attribute source.
10 11 12 |
# File 'lib/librarian/puppet/source/forge.rb', line 10 def source @source end |
Instance Method Details
#cache_path ⇒ Object
65 66 67 |
# File 'lib/librarian/puppet/source/forge.rb', line 65 def cache_path @cache_path ||= source.cache_path.join(name) end |
#cache_version_unpacked!(version) ⇒ Object
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/librarian/puppet/source/forge.rb', line 77 def cache_version_unpacked!(version) path = version_unpacked_cache_path(version) return if path.directory? # The puppet module command is only available from puppet versions >= 2.7.13 # # Specifying the version in the gemspec would force people to upgrade puppet while it's still usable for git # So we do some more clever checking # # Executing older versions or via puppet-module tool gives an exit status = 0 . # path.mkpath target = vendored?(name, version) ? vendored_path(name, version) : name command = "puppet module install --version #{version} --target-dir '#{path}' --module_repository '#{source}' --modulepath '#{path}' --ignore-dependencies '#{target}'" debug { "Executing puppet module install for #{name} #{version}" } output = `#{command}` # Check for bad exit code unless $? == 0 # Rollback the directory if the puppet module had an error path.unlink raise Error, "Error executing puppet module install:\n#{command}\nError:\n#{output}" end end |
#check_puppet_module_options ⇒ Object
108 109 110 111 112 113 114 115 |
# File 'lib/librarian/puppet/source/forge.rb', line 108 def min_version = Gem::Version.create('2.7.13') puppet_version = Gem::Version.create(`puppet --version`.split(' ').first.strip.gsub('-', '.')) if puppet_version < min_version raise Error, "To get modules from the forge, we use the puppet faces module command. For this you need at least puppet version 2.7.13 and you have #{puppet_version}" end end |
#debug(*args, &block) ⇒ Object
136 137 138 |
# File 'lib/librarian/puppet/source/forge.rb', line 136 def debug(*args, &block) environment.logger.debug(*args, &block) end |
#dependencies(version) ⇒ Object
26 27 28 |
# File 'lib/librarian/puppet/source/forge.rb', line 26 def dependencies(version) api_data[name].detect{|x| x['version'] == version.to_s}['dependencies'] end |
#environment ⇒ Object
61 62 63 |
# File 'lib/librarian/puppet/source/forge.rb', line 61 def environment source.environment end |
#hexdigest(value) ⇒ Object
73 74 75 |
# File 'lib/librarian/puppet/source/forge.rb', line 73 def hexdigest(value) Digest::MD5.hexdigest(value) end |
#install_version!(version, install_path) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/librarian/puppet/source/forge.rb', line 36 def install_version!(version, install_path) if environment.local? && !vendored?(name, version) raise Error, "Could not find a local copy of #{name} at #{version}." end if environment.vendor? vendor_cache(name, version) unless vendored?(name, version) end cache_version_unpacked! version if install_path.exist? install_path.rmtree end unpacked_path = version_unpacked_cache_path(version).join(name.split('/').last) unless unpacked_path.exist? raise Error, "#{unpacked_path} does not exist, something went wrong. Try removing it manually" else FileUtils.cp_r(unpacked_path, install_path) end end |
#manifests ⇒ Object
30 31 32 33 34 |
# File 'lib/librarian/puppet/source/forge.rb', line 30 def manifests versions.map do |version| Manifest.new(source, name, version) end end |
#vendor_cache(name, version) ⇒ Object
125 126 127 128 129 130 131 132 133 134 |
# File 'lib/librarian/puppet/source/forge.rb', line 125 def vendor_cache(name, version) info = api_data[name].detect {|h| h['version'] == version.to_s } File.open(vendored_path(name, version).to_s, 'w') do |f| open("#{source}#{info['file']}") do |input| while (buffer = input.read) f.write(buffer) end end end end |
#vendored?(name, version) ⇒ Boolean
117 118 119 |
# File 'lib/librarian/puppet/source/forge.rb', line 117 def vendored?(name, version) vendored_path(name, version).exist? end |
#vendored_path(name, version) ⇒ Object
121 122 123 |
# File 'lib/librarian/puppet/source/forge.rb', line 121 def vendored_path(name, version) environment.vendor_cache.join("#{name.sub("/", "-")}-#{version}.tar.gz") end |
#version_unpacked_cache_path(version) ⇒ Object
69 70 71 |
# File 'lib/librarian/puppet/source/forge.rb', line 69 def version_unpacked_cache_path(version) cache_path.join('version').join(hexdigest(version.to_s)) end |
#versions ⇒ Object
19 20 21 22 23 24 |
# File 'lib/librarian/puppet/source/forge.rb', line 19 def versions return @versions if @versions @versions = api_data[name].map { |r| r['version'] }.reverse debug { " Module #{name} found versions: #{@versions.join(", ")}" } @versions end |