Module: SixCore

Defined in:
lib/sixcore.rb,
lib/sixcore/ftp.rb,
lib/sixcore/svn.rb,
lib/sixcore/nsis.rb

Overview

Core Module

Defined Under Namespace

Classes: ConfigCore, ConfigNsis, ConfigSvn, Ftp, Nsis, Svn

Constant Summary collapse

MAINDIR =
Dir.pwd
COMPONENT =
'SixCore'
TITLE =
'6thSense.eu Core'
VERSION =
'0.4.1'
@@config =
read_config('core', 'sixcore/config')
@@log =
Log4r::Logger.new(COMPONENT)

Class Method Summary collapse

Class Method Details

.clean(str) ⇒ Object

Cleans string (chomp and strip) Returns: Cleaned string

str

String, Input



70
71
72
73
74
# File 'lib/sixcore.rb', line 70

def clean(str)
  str.chomp!
  str.strip!
  str
end

.configObject



29
30
31
# File 'lib/sixcore.rb', line 29

def config
  @@config
end

.eval_cmd(cmd) ⇒ Object

Evals command and logs to debug if enabled

cmd

String, command to eval



111
112
113
114
# File 'lib/sixcore.rb', line 111

def eval_cmd(cmd)
  eval cmd unless @@config.debug or cmd.empty?
  @@log.debug prep_msg('Eval Command', :component => COMPONENT, :verbose => cmd)
end

.filemirror(source, destination, extra = '') ⇒ Object

Uses Roboycopy to mirror folders from source to destination

source

String, Source folder

destination

String, Destination folder

extra

Extra parameters to supply to Robocopy



141
142
143
144
# File 'lib/sixcore.rb', line 141

def filemirror(source, destination, extra = '')
  @@log.debug prep_msg('Mirroring Files...', :component => COMPONENT, :verbose => [source, destination, extra])
  proc_cmd("robocopy #{source} #{destination} /MIR /TIMFIX /ZB /R:5 /W:5 #{extra}")
end

.fileupdate(source, destination, extra = '') ⇒ Object

Uses Roboycopy to update folders from source to destination

source

String, Source folder

destination

String, Destination folder

extra

Extra parameters to supply to Robocopy



132
133
134
135
# File 'lib/sixcore.rb', line 132

def fileupdate(source, destination, extra = '')
  @@log.debug prep_msg('Updating Files...', :component => COMPONENT, :verbose => [source, destination, extra])
  proc_cmd("robocopy #{source} #{destination} /S /TIMFIX /ZB /R:5 /W:5 #{extra}")
end

.gsub_ar(string, replace) ⇒ Object

Replaces all search strings with replace strings from replace array

string

String, Input

replace

Array, per entry: [Search, Replace]



97
98
99
100
# File 'lib/sixcore.rb', line 97

def gsub_ar(string, replace)
  replace.each do |r| string.gsub!(r[0], r[1]) end
  string
end

.haltObject

Halts operation waiting for user input <enter>



61
62
63
64
65
# File 'lib/sixcore.rb', line 61

def halt()
  puts
  puts 'Press enter to continue'
  gets
end

.logObject



56
57
58
# File 'lib/sixcore.rb', line 56

def log()
  @@log
end

.prep_msg(str, options = {}) ⇒ Object

Prepares string for output to logger

str

String, Input

options

Hash, :component, :verbose, :format



79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/sixcore.rb', line 79

def prep_msg(str, options = {})
  unless str.empty?
    str = "#{options[:component]} - #{str}" if options[:component]
    case options[:format]
    when 'title'
      str += ' - ' + options[:verbose].to_s if options[:verbose] and @@config.verbose
      str = "=== #{str} ==="
      puts # FIXME: NASTY!

    else
      str += ' - ' + options[:verbose].to_s if options[:verbose] and @@config.verbose
    end
  end
  str
end

.proc_cmd(cmd) ⇒ Object

Executes system command and logs to debug if enabled

cmd

String, command to execute



118
119
120
121
122
123
124
# File 'lib/sixcore.rb', line 118

def proc_cmd(cmd)
  unless @@config.debug or cmd.empty?
    r = (%x[#{cmd}])
    @@log.debug prep_msg('Proc Command', :component => COMPONENT, :verbose => [cmd, r])
    return r
  end
end

.quote(str) ⇒ Object

Put quotes around string Returns quoted string

str

String, Input



105
106
107
# File 'lib/sixcore.rb', line 105

def quote(str)
  "\"#{str}\""
end

.read_config(config, path) ⇒ Object



18
19
20
21
22
23
24
25
26
# File 'lib/sixcore.rb', line 18

def read_config(config, path)
  obj = nil
  if FileTest.exist?("config/#{config}.yaml")
    File.open("config/#{config}.yaml") { |yf| obj = YAML::load( yf ) }
  else
    File.open("#{File.dirname(__FILE__)}/#{path}/#{config}.yaml") { |yf| obj = YAML::load( yf ) }
  end
  obj
end