Module: ScmsUtils

Defined in:
lib/scms/scms-utils.rb

Class Method Summary collapse

Class Method Details

.errLog(msg) ⇒ Object



39
40
41
42
43
44
45
46
47
# File 'lib/scms/scms-utils.rb', line 39

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



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/scms/scms-utils.rb', line 6

def ScmsUtils.getsettings(yamlpath)
    ScmsUtils.log("Loading Config: #{ScmsUtils.uriEncode("file:///#{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( "Verify your config")
            ScmsUtils.log( "http://yaml-online-parser.appspot.com/")
            ScmsUtils.errLog( e.message )
            ScmsUtils.errLog( e.backtrace.inspect )
        end
    else
        ScmsUtils.errLog("Config file does not exist: #{yamlpath}")
    end
    
    return config
end

.log(msg) ⇒ Object



59
60
61
62
63
64
65
66
67
# File 'lib/scms/scms-utils.rb', line 59

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

.run(cmd, params) ⇒ Object



31
32
33
34
35
36
37
# File 'lib/scms/scms-utils.rb', line 31

def ScmsUtils.run(cmd, params)
    if system("#{cmd} #{params}")
        ScmsUtils.successLog( "#{cmd} ran successfully" )
    else
        raise "Error running #{cmd}"
    end
end

.successLog(msg) ⇒ Object



49
50
51
52
53
54
55
56
57
# File 'lib/scms/scms-utils.rb', line 49

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



77
78
79
80
81
82
83
84
85
# File 'lib/scms/scms-utils.rb', line 77

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



91
92
93
# File 'lib/scms/scms-utils.rb', line 91

def ScmsUtils.uriDecode(uri)
    return uri.gsub("%20", " ")
end

.uriEncode(uri) ⇒ Object



87
88
89
# File 'lib/scms/scms-utils.rb', line 87

def ScmsUtils.uriEncode(uri)
    return uri.gsub(" ", "%20")
end

.writelog(pub, log) ⇒ Object



69
70
71
72
73
74
75
# File 'lib/scms/scms-utils.rb', line 69

def ScmsUtils.writelog(pub, log)
       if !pub.nil? && !log.nil? 
           open(File.join(pub, "build.log"), 'a') { |f|
             f.puts log
           }
       end
end