/tools/Rake/msdeploy.rb

http://github.com/agross/netopenspace · Ruby · 60 lines · 48 code · 12 blank · 0 comment · 8 complexity · 35fe1ea4f62aea683892063c49608869 MD5 · raw file

  1. class 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. attributes.reject! do |key, value|
  7. key == :tool || key == :log_file
  8. end
  9. switches = generate_switches(attributes)
  10. msdeploy = tool.to_absolute
  11. tee = tee_tool.to_absolute
  12. sh "#{msdeploy.escape} #{switches} 2>&1 | #{tee.escape} -a #{logFile}" do
  13. doc = File.read(logFile)
  14. errors = doc.scan(/(\n|\s)+(error|exception|fehler)/i)
  15. if errors.any?
  16. message = "\nLog string indicating the deployment error: #{errors.first[1]} ...and #{errors.nitems - 1} more"
  17. puts message
  18. raise "\nDeployment errors occurred. Please review #{logFile}." + message
  19. else
  20. puts "\nDeployment successful."
  21. end
  22. end
  23. end
  24. def self.generate_switches(attributes)
  25. switches = ""
  26. attributes.each do |switch, value|
  27. if value.kind_of? Array
  28. switches += value.collect { |element|
  29. generate_switches({ switch => element })
  30. }.join
  31. next
  32. end
  33. switches += "-#{switch}#{":#{value}" unless value.kind_of? Enumerable or value.kind_of? TrueClass or value.kind_of? FalseClass}" if value
  34. if value.kind_of? Enumerable
  35. switches += ":"
  36. switches += value.collect { |key, value|
  37. if value
  38. "#{key}#{"=#{value}" unless value.kind_of? TrueClass or value.kind_of? FalseClass}"
  39. else
  40. key
  41. end
  42. }.join ","
  43. end
  44. switches += " "
  45. end
  46. switches
  47. end
  48. end