Module: MCollective::PluginPackager

Defined in:
lib/mcollective/pluginpackager.rb,
lib/mcollective/pluginpackager/forge_packager.rb,
lib/mcollective/pluginpackager/agent_definition.rb,
lib/mcollective/pluginpackager/standard_definition.rb

Defined Under Namespace

Classes: AgentDefinition, ForgePackager, StandardDefinition

Class Method Summary collapse

Class Method Details

.[](klass) ⇒ Object



12
13
14
# File 'lib/mcollective/pluginpackager.rb', line 12

def self.[](klass)
  const_get(klass.to_s)
end

.check_dir_present(path) ⇒ Object

Checks if a directory is present and not empty



31
32
33
# File 'lib/mcollective/pluginpackager.rb', line 31

def self.check_dir_present(path)
  (File.directory?(path) && !Dir.glob(File.join(path, "*")).empty?)
end

.command_available?(build_tool) ⇒ Boolean

Checks if a build tool is present on the system

Returns:

  • (Boolean)


54
55
56
57
58
59
60
# File 'lib/mcollective/pluginpackager.rb', line 54

def self.command_available?(build_tool)
  ENV["PATH"].split(File::PATH_SEPARATOR).each do |path|
    builder = File.join(path, build_tool)
    return true if File.exist?(builder)
  end
  false
end

.execute_verbosely(verbose, &block) ⇒ Object

Quietly calls a block if verbose parameter is false



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/mcollective/pluginpackager.rb', line 36

def self.execute_verbosely(verbose, &block)
  if verbose
    block.call
  else
    old_stdout = $stdout.clone
    $stdout.reopen(File.new("/dev/null", "w"))
    begin
      block.call
    rescue Exception # rubocop:disable Lint/RescueException
      $stdout.reopen old_stdout
      raise
    ensure
      $stdout.reopen old_stdout
    end
  end
end

.filter_dependencies(prefix, dependencies) ⇒ Object

Filter out platform specific dependencies Given a list of dependencies named - debian::foo redhat::bar PluginPackager.filter_dependencies(‘debian’, dependencies) will return foo.



72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/mcollective/pluginpackager.rb', line 72

def self.filter_dependencies(prefix, dependencies)
  dependencies.map do |dependency|
    if dependency[:name] =~ /^(\w+)::(\w+)/
      if prefix == $1
        dependency[:name] = $2
        dependency
      end
    else
      dependency
    end
  end.reject(&:nil?)
end

.get_metadata(path, type) ⇒ Object

Fetch and return metadata from plugin DDL



17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/mcollective/pluginpackager.rb', line 17

def self.(path, type)
  ddl = DDL.new("package", type.to_sym, false)

  begin
    ddl_file = File.read(Dir.glob(File.join(path, type, "*.ddl")).first)
  rescue Exception # rubocop:disable Lint/RescueException
    raise "failed to load ddl file in plugin directory : #{File.join(path, type)}"
  end
  ddl.instance_eval ddl_file

  [ddl.meta, ddl.requirements[:mcollective]]
end

.get_plugin_path(target) ⇒ Object

Return the path to a plugin’s core directories



86
87
88
89
90
# File 'lib/mcollective/pluginpackager.rb', line 86

def self.get_plugin_path(target)
  return File.join(target, "lib", "mcollective") if File.exist?(File.join(target, "lib", "mcollective"))

  target
end

.load_packagersObject

Package implementation plugins



8
9
10
# File 'lib/mcollective/pluginpackager.rb', line 8

def self.load_packagers
  PluginManager.find_and_load("pluginpackager")
end

.safe_system(*args) ⇒ Object



62
63
64
# File 'lib/mcollective/pluginpackager.rb', line 62

def self.safe_system(*args)
  raise("Failed: #{args.join(' ')}") unless system(*args)
end