lib/foreman/export/base.rb in foreman-0.48.0.pre3 vs lib/foreman/export/base.rb in foreman-0.48.0
- old
+ new
@@ -1,20 +1,48 @@
require "foreman/export"
+require "ostruct"
+require "pathname"
require "shellwords"
class Foreman::Export::Base
attr_reader :location
attr_reader :engine
attr_reader :options
attr_reader :formation
+ # deprecated
+ attr_reader :port
+
def initialize(location, engine, options={})
@location = location
@engine = engine
@options = options.dup
@formation = engine.formation
+
+ # deprecated
+ def port
+ Foreman::Export::Base.warn_deprecation!
+ engine.base_port
+ end
+
+ # deprecated
+ def template
+ Foreman::Export::Base.warn_deprecation!
+ options[:template]
+ end
+
+ # deprecated
+ def @engine.procfile
+ Foreman::Export::Base.warn_deprecation!
+ @processes.map do |process|
+ OpenStruct.new(
+ :name => @names[process],
+ :process => process
+ )
+ end
+ end
end
def export
error("Must specify a location") unless location
FileUtils.mkdir_p(location) rescue error("Could not create: #{location}")
@@ -34,10 +62,22 @@
options[:user] || app
end
private ######################################################################
+ def self.warn_deprecation!
+ @@deprecation_warned ||= false
+ return if @@deprecation_warned
+ puts "WARNING: Using deprecated exporter interface. Please update your exporter"
+ puts "the interface shown in the upstart exporter:"
+ puts
+ puts "https://github.com/ddollar/foreman/blob/master/lib/foreman/export/upstart.rb"
+ puts "https://github.com/ddollar/foreman/blob/master/data/export/upstart/process.conf.erb"
+ puts
+ @@deprecation_warned = true
+ end
+
def error(message)
raise Foreman::Export::Exception.new(message)
end
def say(message)
@@ -52,19 +92,34 @@
def shell_quote(value)
'"' + Shellwords.escape(value) + '"'
end
- def export_template(name)
- name_without_first = name.split("/")[1..-1].join("/")
- matchers = []
- matchers << File.join(options[:template], name_without_first) if options[:template]
- matchers << File.expand_path("~/.foreman/templates/#{name}")
- matchers << File.expand_path("../../../../data/export/#{name}", __FILE__)
- File.read(matchers.detect { |m| File.exists?(m) })
+ # deprecated
+ def old_export_template(exporter, file, template_root)
+ if template_root && File.exist?(file_path = File.join(template_root, file))
+ File.read(file_path)
+ elsif File.exist?(file_path = File.expand_path(File.join("~/.foreman/templates", file)))
+ File.read(file_path)
+ else
+ File.read(File.expand_path("../../../../data/export/#{exporter}/#{file}", __FILE__))
+ end
end
+ def export_template(name, file=nil, template_root=nil)
+ if file && template_root
+ old_export_template name, file, template_root
+ else
+ name_without_first = name.split("/")[1..-1].join("/")
+ matchers = []
+ matchers << File.join(options[:template], name_without_first) if options[:template]
+ matchers << File.expand_path("~/.foreman/templates/#{name}")
+ matchers << File.expand_path("../../../../data/export/#{name}", __FILE__)
+ File.read(matchers.detect { |m| File.exists?(m) })
+ end
+ end
+
def write_template(name, target, binding)
compiled = ERB.new(export_template(name)).result(binding)
write_file target, compiled
end
@@ -79,10 +134,12 @@
end
def write_file(filename, contents)
say "writing: #{filename}"
- File.open(File.join(location, filename), "w") do |file|
+ filename = File.join(location, filename) unless Pathname.new(filename).absolute?
+
+ File.open(filename, "w") do |file|
file.puts contents
end
end
end