Module: ScmsUtils
- Defined in:
- lib/scms/scms-utils.rb
Class Method Summary collapse
- .boldlog(msg) ⇒ Object
- .errLog(msg) ⇒ Object
- .getsettings(yamlpath) ⇒ Object
- .log(msg) ⇒ Object
- .port_open?(ip, port, seconds = 1) ⇒ Boolean
- .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
83 84 85 86 87 88 89 90 91 |
# File 'lib/scms/scms-utils.rb', line 83 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
63 64 65 66 67 68 69 70 71 |
# File 'lib/scms/scms-utils.rb', line 63 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 |
.getsettings(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 45 46 47 48 49 50 51 52 53 |
# File 'lib/scms/scms-utils.rb', line 22 def ScmsUtils.getsettings(yamlpath) ScmsUtils.log("Loading Config: #{ScmsUtils.uriEncode("file:///#{yamlpath}")}") config = nil ##http://snk.tuxfamily.org/log/yaml-json-validation-kwalify-ruby19.html #'kwalify' #schema = Kwalify::Yaml.load_file('some_complex_schema.yaml') #validator = Kwalify::Validator.new(schema) #parser = Kwalify::Yaml::Parser.new(validator) #yaml = some_complex_object.to_yaml # machine-generate #data = parser.parse(yaml) # parse & validate <== FAIL 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( "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 |
.log(msg) ⇒ Object
93 94 95 96 97 98 99 100 101 |
# File 'lib/scms/scms-utils.rb', line 93 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 |
.run(cmd, params) ⇒ Object
55 56 57 58 59 60 61 |
# File 'lib/scms/scms-utils.rb', line 55 def ScmsUtils.run(cmd, params) if system("#{cmd} #{params}") ScmsUtils.successLog( "#{cmd} ran successfully" ) else raise "Error running #{cmd}" end end |
.successLog(msg) ⇒ Object
73 74 75 76 77 78 79 80 81 |
# File 'lib/scms/scms-utils.rb', line 73 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
111 112 113 114 115 116 117 118 119 |
# File 'lib/scms/scms-utils.rb', line 111 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
125 126 127 |
# File 'lib/scms/scms-utils.rb', line 125 def ScmsUtils.uriDecode(uri) return uri.gsub("%20", " ") end |
.uriEncode(uri) ⇒ Object
121 122 123 |
# File 'lib/scms/scms-utils.rb', line 121 def ScmsUtils.uriEncode(uri) return uri.gsub(" ", "%20") end |
.writelog(log, pub) ⇒ Object
103 104 105 106 107 108 109 |
# File 'lib/scms/scms-utils.rb', line 103 def ScmsUtils.writelog(log, pub) if !pub.nil? && !log.nil? open(File.join(pub, "_build.log"), 'a') { |f| f.puts log } end end |