class Librarian::Puppet::Source::Forge::Repo

Public Instance Methods

cache_version_unpacked!(version) click to toggle source
# File lib/librarian/puppet/source/forge/repo.rb, line 72
def cache_version_unpacked!(version)
  path = version_unpacked_cache_path(version)
  return if path.directory?

  path.mkpath

  target = vendored?(name, version) ? vendored_path(name, version).to_s : name

  module_repository = source.uri.to_s

  command = %W{puppet module install --version #{version} --target-dir}
  command.push(*[path.to_s, "--module_repository", module_repository, "--modulepath", path.to_s, "--module_working_dir", path.to_s, "--ignore-dependencies", target])
  debug { "Executing puppet module install for #{name} #{version}: #{command.join(" ").gsub(module_repository, source.to_s)}" }

  begin
    Librarian::Posix.run!(command)
  rescue Posix::CommandFailure => e
    # Rollback the directory if the puppet module had an error
    begin
      path.unlink
    rescue => u
      debug("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}. Check that this command succeeds:\n#{command.join(" ")}\nError:\n#{e.message}"
  end

end
dependencies(version) click to toggle source

return map with dependencies in the form {module_name => version,…} version: Librarian::Manifest::Version

# File lib/librarian/puppet/source/forge/repo.rb, line 31
def dependencies(version)
  # implement in subclasses
end
get_versions() click to toggle source

fetch list of versions ordered for newer to older

# File lib/librarian/puppet/source/forge/repo.rb, line 25
def get_versions
  # implement in subclasses
end
install_version!(version, install_path) click to toggle source
# File lib/librarian/puppet/source/forge/repo.rb, line 47
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? && rsync? != true
    install_path.rmtree
  end

  unpacked_path = version_unpacked_cache_path(version).join(module_name(name))

  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
manifests() click to toggle source
# File lib/librarian/puppet/source/forge/repo.rb, line 41
def manifests
  versions.map do |version|
    Manifest.new(source, name, version)
  end
end
url(name, version) click to toggle source

return the url for a specific version tarball version: Librarian::Manifest::Version

# File lib/librarian/puppet/source/forge/repo.rb, line 37
def url(name, version)
  # implement in subclasses
end
vendor_cache(name, version) click to toggle source
# File lib/librarian/puppet/source/forge/repo.rb, line 106
def vendor_cache(name, version)
  url = url(name, version)
  path = vendored_path(name, version).to_s
  debug { "Downloading #{url} into #{path}"}
  environment.vendor!
  File.open(path, 'wb') do |f|
    URI.open(url, 'rb') do |input|
      f.write(input.read)
    end
  end
end
versions() click to toggle source
# File lib/librarian/puppet/source/forge/repo.rb, line 13
def versions
  return @versions if @versions
  @versions = get_versions
  if @versions.empty?
    info { "No versions found for module #{name}" }
  else
    debug { "  Module #{name} found versions: #{@versions.join(", ")}" }
  end
  @versions
end