X-Git-Url: https://review.fuel-infra.org/gitweb?a=blobdiff_plain;f=lib%2Fmcollective%2Fpluginpackager.rb;fp=lib%2Fmcollective%2Fpluginpackager.rb;h=d0030908095f9c2c779a8710b5e0fd064c61c0f3;hb=b87d2f4e68281062df1913440ca5753ae63314a9;hp=0000000000000000000000000000000000000000;hpb=ab0ea530b8ac956091f17b104ab2311336cfc250;p=packages%2Fprecise%2Fmcollective.git diff --git a/lib/mcollective/pluginpackager.rb b/lib/mcollective/pluginpackager.rb new file mode 100644 index 0000000..d003090 --- /dev/null +++ b/lib/mcollective/pluginpackager.rb @@ -0,0 +1,68 @@ +module MCollective + module PluginPackager + # Plugin definition classes + autoload :AgentDefinition, "mcollective/pluginpackager/agent_definition" + autoload :StandardDefinition, "mcollective/pluginpackager/standard_definition" + + # Package implementation plugins + def self.load_packagers + PluginManager.find_and_load("pluginpackager") + end + + def self.[](klass) + const_get("#{klass}") + end + + # Fetch and return metadata from plugin DDL + 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 + + # Checks if a directory is present and not empty + def self.check_dir_present(path) + (File.directory?(path) && !Dir.glob(File.join(path, "*")).empty?) + end + + # Quietly calls a block if verbose parameter is false + def self.do_quietly?(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 + + # Checks if a build tool is present on the system + def self.build_tool?(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 + + def self.safe_system(*args) + raise RuntimeError, "Failed: #{args.join(' ')}" unless system *args + end + end +end