Module: Puppet::ModuleTool

Extended by:
Util::Colors
Defined in:
lib/vendor/puppet/module_tool.rb,
lib/vendor/puppet/module_tool/errors.rb,
lib/vendor/puppet/module_tool/metadata.rb,
lib/vendor/puppet/module_tool/skeleton.rb,
lib/vendor/puppet/module_tool/checksums.rb,
lib/vendor/puppet/module_tool/dependency.rb,
lib/vendor/puppet/module_tool/modulefile.rb,
lib/vendor/puppet/module_tool/applications.rb,
lib/vendor/puppet/module_tool/applications/builder.rb,
lib/vendor/puppet/module_tool/contents_description.rb,
lib/vendor/puppet/module_tool/applications/searcher.rb,
lib/vendor/puppet/module_tool/applications/unpacker.rb,
lib/vendor/puppet/module_tool/applications/upgrader.rb,
lib/vendor/puppet/module_tool/applications/generator.rb,
lib/vendor/puppet/module_tool/applications/installer.rb,
lib/vendor/puppet/module_tool/applications/application.rb,
lib/vendor/puppet/module_tool/applications/checksummer.rb,
lib/vendor/puppet/module_tool/applications/uninstaller.rb

Defined Under Namespace

Modules: Applications, Errors, Shared Classes: Checksums, ContentsDescription, Dependency, Metadata, ModulefileReader, Skeleton

Constant Summary collapse

ARTIFACTS =

Directory and names that should not be checksummed.

['pkg', /^\./, /^~/, /^#/, 'coverage', 'metadata.json', 'REVISION']
FULL_MODULE_NAME_PATTERN =
/\A([^-\/|.]+)[-|\/](.+)\z/
REPOSITORY_URL =

Constants included from Util::Colors

Util::Colors::BG_BLUE, Util::Colors::BG_CYAN, Util::Colors::BG_GREEN, Util::Colors::BG_HBLUE, Util::Colors::BG_HCYAN, Util::Colors::BG_HGREEN, Util::Colors::BG_HMAGENTA, Util::Colors::BG_HRED, Util::Colors::BG_HWHITE, Util::Colors::BG_HYELLOW, Util::Colors::BG_MAGENTA, Util::Colors::BG_RED, Util::Colors::BG_WHITE, Util::Colors::BG_YELLOW, Util::Colors::BLACK, Util::Colors::BLUE, Util::Colors::CYAN, Util::Colors::Colormap, Util::Colors::GREEN, Util::Colors::HBLACK, Util::Colors::HBLUE, Util::Colors::HCYAN, Util::Colors::HGREEN, Util::Colors::HMAGENTA, Util::Colors::HRED, Util::Colors::HWHITE, Util::Colors::HYELLOW, Util::Colors::MAGENTA, Util::Colors::RED, Util::Colors::RESET, Util::Colors::WHITE, Util::Colors::YELLOW

Class Method Summary collapse

Methods included from Util::Colors

colorize, console_color, console_has_color?, html_color

Class Method Details

.artifact?(path) ⇒ Boolean

Is this a directory that shouldn’t be checksummed?

TODO: Should this be part of Checksums? TODO: Rename this method to reflect it’s purpose? TODO: Shouldn’t this be used when building packages too?

Returns:

  • (Boolean)


22
23
24
25
26
27
28
29
# File 'lib/vendor/puppet/module_tool.rb', line 22

def self.artifact?(path)
  case File.basename(path)
  when *ARTIFACTS
    true
  else
    false
  end
end

.build_tree(mods, dir) ⇒ Object



72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/vendor/puppet/module_tool.rb', line 72

def self.build_tree(mods, dir)
  mods.each do |mod|
    version_string = mod[:version][:vstring].sub(/^(?!v)/, 'v')

    if mod[:action] == :upgrade
      previous_version = mod[:previous_version].sub(/^(?!v)/, 'v')
      version_string = "#{previous_version} -> #{version_string}"
    end

    mod[:text] = "#{mod[:module]} (#{colorize(:cyan, version_string)})"
    mod[:text] += " [#{mod[:path]}]" unless mod[:path] == dir
    build_tree(mod[:dependencies], dir)
  end
end

.find_module_root(path) ⇒ Object

Raises:

  • (ArgumentError)


41
42
43
44
45
46
47
48
# File 'lib/vendor/puppet/module_tool.rb', line 41

def self.find_module_root(path)
  for dir in [path, Dir.pwd].compact
    if File.exist?(File.join(dir, 'Modulefile'))
      return dir
    end
  end
  raise ArgumentError, "Could not find a valid module at #{path ? path.inspect : 'current directory'}"
end

.format_tree(nodes, level = 0) ⇒ Object

Builds a formatted tree from a list of node hashes containing :text and :dependencies keys.



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/vendor/puppet/module_tool.rb', line 52

def self.format_tree(nodes, level = 0)
  str = ''
  nodes.each_with_index do |node, i|
    last_node = nodes.length - 1 == i
    deps = node[:dependencies] || []

    str << (indent = "  " * level)
    str << (last_node ? "" : "")
    str << ""
    str << (deps.empty? ? "" : "")
    str << " #{node[:text]}\n"

    branch = format_tree(deps, level + 1)
    branch.gsub!(/^#{indent} /, indent + '') unless last_node
    str << branch
  end

  return str
end

.username_and_modname_from(full_module_name) ⇒ Object

Return the username and modname for a given full_module_name, or raise an ArgumentError if the argument isn’t parseable.



33
34
35
36
37
38
39
# File 'lib/vendor/puppet/module_tool.rb', line 33

def self.username_and_modname_from(full_module_name)
  if matcher = full_module_name.match(FULL_MODULE_NAME_PATTERN)
    return matcher.captures
  else
    raise ArgumentError, "Not a valid full name: #{full_module_name}"
  end
end