module MCollective::PluginPackager
Public Class Methods
[](klass)
click to toggle source
# File lib/mcollective/pluginpackager.rb, line 12 def self.[](klass) const_get("#{klass}") end
check_dir_present(path)
click to toggle source
Checks if a directory is present and not empty
# 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)
click to toggle source
Checks if a build tool is present on the system
# 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) if File.exists?(builder) return true end end false end
execute_verbosely(verbose, &block)
click to toggle source
Quietly calls a block if verbose parameter is false
# File lib/mcollective/pluginpackager.rb, line 36 def self.execute_verbosely(verbose, &block) unless verbose old_stdout = $stdout.clone $stdout.reopen(File.new("/dev/null", "w")) begin block.call rescue Exception => e $stdout.reopen old_stdout raise e ensure $stdout.reopen old_stdout end else block.call end end
filter_dependencies(prefix, dependencies)
click to toggle source
Filter out platform specific dependencies Given a list of dependencies named - debian::foo redhat::bar ::filter_dependencies(‘debian’, dependencies) will return foo.
# File lib/mcollective/pluginpackager.rb, line 74 def self.filter_dependencies(prefix, dependencies) dependencies.map do |dependency| if dependency[:name] =~ /^(\w+)::(\w+)/ if prefix == $1 dependency[:name] = $2 dependency else nil end else dependency end end.reject{ |dependency| dependency == nil } end
get_metadata(path, type)
click to toggle source
Fetch and return metadata from plugin DDL
# File lib/mcollective/pluginpackager.rb, line 17 def self.get_metadata(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 raise "failed to load ddl file in plugin directory : #{File.join(path, type)}" end ddl.instance_eval ddl_file return ddl.meta, ddl.requirements[:mcollective] end
get_plugin_path(target)
click to toggle source
Return the path to a plugin’s core directories
# File lib/mcollective/pluginpackager.rb, line 90 def self.get_plugin_path(target) if (File.exists?(File.join(target, "lib", "mcollective"))) return File.join(target, "lib", "mcollective") end return target end
load_packagers()
click to toggle source
Package implementation plugins
# File lib/mcollective/pluginpackager.rb, line 8 def self.load_packagers PluginManager.find_and_load("pluginpackager") end
safe_system(*args)
click to toggle source
# File lib/mcollective/pluginpackager.rb, line 64 def self.safe_system(*args) raise(RuntimeError, "Failed: #{args.join(' ')}") unless system *args end