PageRenderTime 71ms CodeModel.GetById 53ms app.highlight 15ms RepoModel.GetById 1ms app.codeStats 0ms

/tools/Rake/msdeploy.rb

http://github.com/agross/netopenspace
Ruby | 60 lines | 48 code | 12 blank | 0 comment | 8 complexity | 35fe1ea4f62aea683892063c49608869 MD5 | raw file
 1class MSDeploy
 2	def self.run(attributes)
 3		tool = attributes.fetch(:tool)
 4		tee_tool = attributes.fetch(:tee_tool, "tee.exe".in(tool.dirname))
 5		logFile = attributes.fetch(:log_file, "msdeploy.log")
 6		
 7		attributes.reject! do |key, value|
 8			key == :tool || key == :log_file
 9		end
10		
11		switches = generate_switches(attributes)
12		
13		msdeploy = tool.to_absolute
14		tee = tee_tool.to_absolute
15		
16		sh "#{msdeploy.escape} #{switches} 2>&1 | #{tee.escape} -a #{logFile}" do
17			doc = File.read(logFile)
18			errors = doc.scan(/(\n|\s)+(error|exception|fehler)/i)
19			
20			if errors.any?
21				message = "\nLog string indicating the deployment error: #{errors.first[1]} ...and #{errors.nitems - 1} more"
22				puts message
23				raise "\nDeployment errors occurred. Please review #{logFile}." + message
24			else
25				puts "\nDeployment successful."
26			end
27		end
28	end
29	
30	def self.generate_switches(attributes)
31		switches = ""
32		
33		attributes.each do |switch, value|
34			if value.kind_of? Array
35				switches += value.collect { |element|
36					generate_switches({ switch => element })
37				}.join
38				
39				next
40			end
41			
42			switches += "-#{switch}#{":#{value}" unless value.kind_of? Enumerable or value.kind_of? TrueClass or value.kind_of? FalseClass}" if value		
43			
44			if value.kind_of? Enumerable
45				switches += ":"
46				switches += value.collect { |key, value|
47					if value
48						"#{key}#{"=#{value}" unless value.kind_of? TrueClass or value.kind_of? FalseClass}"
49					else
50						key
51					end
52				}.join ","
53			end
54			
55			switches += " "
56		end
57		
58		switches
59	end
60end