Module: ScmsUtils
- Defined in:
- lib/scms/scms-utils.rb
Class Method Summary collapse
- .boldlog(msg) ⇒ Object
- .errLog(msg) ⇒ Object
- .log(msg) ⇒ Object
- .port_open?(ip, port, seconds = 1) ⇒ Boolean
- .readyaml(yamlpath) ⇒ Object
- .run(cmd, params) ⇒ Object
- .successLog(msg) ⇒ Object
- .txt_2_html(rawsnippet) ⇒ Object
- .uriDecode(uri) ⇒ Object
- .uriEncode(uri) ⇒ Object
- .writelog(log, pub) ⇒ Object
Class Method Details
.boldlog(msg) ⇒ Object
74 75 76 77 78 79 80 81 82 |
# File 'lib/scms/scms-utils.rb', line 74 def ScmsUtils.boldlog(msg) if !msg.nil? if ENV["SCMS_HTML_OUT"] == "true" puts "<strong>#{ScmsUtils.txt_2_html(msg)}</strong>" else puts msg end end end |
.errLog(msg) ⇒ Object
54 55 56 57 58 59 60 61 62 |
# File 'lib/scms/scms-utils.rb', line 54 def ScmsUtils.errLog(msg) if !msg.nil? if ENV["SCMS_HTML_OUT"] == "true" puts "<div style='color: red;'>#{ScmsUtils.txt_2_html(msg)}</div>" else puts msg end end end |
.log(msg) ⇒ Object
84 85 86 87 88 89 90 91 92 |
# File 'lib/scms/scms-utils.rb', line 84 def ScmsUtils.log(msg) if !msg.nil? if ENV["SCMS_HTML_OUT"] == "true" puts "<div>#{ScmsUtils.txt_2_html(msg)}</div>" else puts msg end end end |
.port_open?(ip, port, seconds = 1) ⇒ Boolean
9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/scms/scms-utils.rb', line 9 def ScmsUtils.port_open?(ip, port, seconds=1) Timeout::timeout(seconds) do begin TCPSocket.new(ip, port).close true rescue Errno::ECONNREFUSED, Errno::EHOSTUNREACH false end end rescue Timeout::Error false end |
.readyaml(yamlpath) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/scms/scms-utils.rb', line 22 def ScmsUtils.readyaml(yamlpath) config = nil if File.exist?(yamlpath) tree = File.read(yamlpath) begin myconfig = ERB.new(tree).result() #puts "Conf = #{myconfig}" config = YAML.load(myconfig) #config = YAML.load_file(yamlpath) rescue Exception => e ScmsUtils.errLog("Error Loading _config.yml (check there are no tabs in the file)") ScmsUtils.log("Yaml: #{ScmsUtils.uriEncode("file:///#{yamlpath}")}") ScmsUtils.log( "Verify your config") ScmsUtils.log( "http://yaml-online-parser.appspot.com/") ScmsUtils.errLog( e. ) ScmsUtils.errLog( e.backtrace.inspect ) end else ScmsUtils.errLog("Config file does not exist: #{yamlpath}") end return config end |
.run(cmd, params) ⇒ Object
46 47 48 49 50 51 52 |
# File 'lib/scms/scms-utils.rb', line 46 def ScmsUtils.run(cmd, params) if system("#{cmd} #{params}") ScmsUtils.successLog( "#{cmd} ran successfully" ) else raise "Error running #{cmd}" end end |
.successLog(msg) ⇒ Object
64 65 66 67 68 69 70 71 72 |
# File 'lib/scms/scms-utils.rb', line 64 def ScmsUtils.successLog(msg) if !msg.nil? if ENV["SCMS_HTML_OUT"] == "true" puts "<div style='color: green;'>#{ScmsUtils.txt_2_html(msg)}</div>" else puts msg end end end |
.txt_2_html(rawsnippet) ⇒ Object
102 103 104 105 106 107 108 109 110 |
# File 'lib/scms/scms-utils.rb', line 102 def ScmsUtils.txt_2_html(rawsnippet) if rawsnippet != nil rawsnippet.gsub!(/(http:\/\/\S+)/, '<a href="\1" target="_blank" ref="external">\1</a>') rawsnippet.gsub!(/(file:\/\/\/\S+)/, '<a href="\1" target="_blank" ref="external">\1</a>') rawsnippet.gsub!(/\n/, "<br />") end return rawsnippet end |
.uriDecode(uri) ⇒ Object
116 117 118 |
# File 'lib/scms/scms-utils.rb', line 116 def ScmsUtils.uriDecode(uri) return uri.gsub("%20", " ") end |
.uriEncode(uri) ⇒ Object
112 113 114 |
# File 'lib/scms/scms-utils.rb', line 112 def ScmsUtils.uriEncode(uri) return uri.gsub(" ", "%20") end |
.writelog(log, pub) ⇒ Object
94 95 96 97 98 99 100 |
# File 'lib/scms/scms-utils.rb', line 94 def ScmsUtils.writelog(log, pub) if !pub.nil? && !log.nil? open(File.join(pub, "_build.log"), 'a') { |f| f.puts log } end end |