# File lib/librarian/puppet/source/forge.rb, line 16 def initialize(source, name) self.source = source self.name = name # API returned data for this module including all versions and dependencies, indexed by module name # from http://forge.puppetlabs.com/api/v1/releases.json?module=#{name} @api_data = nil # API returned data for this module and a specific version, indexed by version # from http://forge.puppetlabs.com/api/v1/releases.json?module=#{name}&version=#{version} @api_version_data = {} end
# File lib/librarian/puppet/source/forge.rb, line 77 def cache_path @cache_path ||= source.cache_path.join(name) end
# File lib/librarian/puppet/source/forge.rb, line 89 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 . # check_puppet_module_options path.mkpath target = vendored?(name, version) ? vendored_path(name, version).to_s : name command = %{puppet module install --version #{version} --target-dir} command.push(*[path.to_s, "--module_repository", source.to_s, "--modulepath", path.to_s, "--module_working_dir", path.to_s, "--ignore-dependencies", target]) debug { "Executing puppet module install for #{name} #{version}" } begin Librarian::Posix.run!(command) rescue Posix::CommandFailure => e # Rollback the directory if the puppet module had an error begin path.unlink rescue => u warn("Unable to rollback path #{path}: #{u}") end tar = Dir[File.join(path.to_s, "**/*.tar.gz")] msg = "" if e.message =~ /Unexpected EOF in archive/ and !tar.empty? file = tar.first msg = " (looks like an incomplete download of #{file})" end raise Error, "Error executing puppet module install#{msg}:\n#{command.join(" ")}\nError:\n#{e.message}" end end
# File lib/librarian/puppet/source/forge.rb, line 131 def check_puppet_module_options min_version = Gem::Version.create('2.7.13') puppet_version = Gem::Version.create(PUPPET_VERSION.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
# File lib/librarian/puppet/source/forge.rb, line 38 def dependencies(version) api_version_data(name, version)['dependencies'] end
# File lib/librarian/puppet/source/forge.rb, line 73 def environment source.environment end
# File lib/librarian/puppet/source/forge.rb, line 85 def hexdigest(value) Digest::MD5.hexdigest(value) end
# File lib/librarian/puppet/source/forge.rb, line 48 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 cp_r(unpacked_path, install_path) end end
# File lib/librarian/puppet/source/forge.rb, line 42 def manifests versions.map do |version| Manifest.new(source, name, version) end end
# File lib/librarian/puppet/source/forge.rb, line 148 def vendor_cache(name, version) info = api_version_data(name, version) url = "#{source}#{info[name].first['file']}" path = vendored_path(name, version).to_s debug { "Downloading #{url} into #{path}"} File.open(path, 'wb') do |f| open(url, "rb") do |input| f.write(input.read) end end end
# File lib/librarian/puppet/source/forge.rb, line 140 def vendored?(name, version) vendored_path(name, version).exist? end
# File lib/librarian/puppet/source/forge.rb, line 144 def vendored_path(name, version) environment.vendor_cache.join("#{name.sub("/", "-")}-#{version}.tar.gz") end
# File lib/librarian/puppet/source/forge.rb, line 81 def version_unpacked_cache_path(version) cache_path.join('version').join(hexdigest(version.to_s)) end
# File lib/librarian/puppet/source/forge.rb, line 27 def versions return @versions if @versions @versions = api_data(name).map { |r| r['version'] }.reverse if @versions.empty? info { "No versions found for module #{name}" } else debug { " Module #{name} found versions: #{@versions.join(", ")}" } end @versions end
Generated with the Darkfish Rdoc Generator 2.