Module: ScmsUtils
- Defined in:
- lib/scms/scms-utils.rb
Class Method Summary collapse
- .boldlog(msg) ⇒ Object
- .errLog(msg) ⇒ Object
- .log(msg) ⇒ Object
- .makeSafe(txt) ⇒ Object
- .port_open?(ip, port, seconds = 1) ⇒ Boolean
- .readyaml(yamlpath) ⇒ Object
- .run(cmd, params) ⇒ Object
- .successLog(msg) ⇒ Object
- .toUTF8(txt) ⇒ 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 |
.makeSafe(txt) ⇒ Object
102 103 104 |
# File 'lib/scms/scms-utils.rb', line 102 def ScmsUtils.makeSafe(txt) return txt.gsub(/\u2018/, "'") 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 |
.toUTF8(txt) ⇒ Object
117 118 119 120 |
# File 'lib/scms/scms-utils.rb', line 117 def ScmsUtils.toUTF8(txt) txt.force_encoding('binary') return txt.encode('UTF-8', :invalid => :replace, :undef => :replace, :replace => "?") end |
.txt_2_html(rawsnippet) ⇒ Object
106 107 108 109 110 111 112 113 114 115 |
# File 'lib/scms/scms-utils.rb', line 106 def ScmsUtils.txt_2_html(rawsnippet) if rawsnippet != nil rawsnippet = ScmsUtils.toUTF8(rawsnippet) 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
126 127 128 |
# File 'lib/scms/scms-utils.rb', line 126 def ScmsUtils.uriDecode(uri) return uri.gsub("%20", " ") end |
.uriEncode(uri) ⇒ Object
122 123 124 |
# File 'lib/scms/scms-utils.rb', line 122 def ScmsUtils.uriEncode(uri) return uri.gsub(" ", "%20") end |