Module: Helper

Defined in:
lib/depengine/helper/smb.rb,
lib/depengine/helper/mail.rb,
lib/depengine/helper/yaml.rb,
lib/depengine/helper/hudson.rb,
lib/depengine/helper/properties.rb,
lib/depengine/helper/validations.rb

Defined Under Namespace

Classes: Mail, Properties, Smb

Class Method Summary collapse

Class Method Details

.absolute_path?(path) ⇒ Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/depengine/helper/validations.rb', line 24

def absolute_path?(path)
  path.start_with? "/"
end

.cleanup_workspace!(workspace, sub_dirs = nil) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/depengine/helper/hudson.rb', line 29

def cleanup_workspace!(workspace, sub_dirs=nil)
  Helper.validates_presence_of workspace

  begin
    unless sub_dirs.respond_to?(:each)
      sub_dirs = ["**/*"]
    end
    sub_dirs.each do |sub_dir|
      FileUtils.rm_rf Dir.glob("#{workspace}/#{sub_dir}")
      $log.writer.debug "Cleaning Workspace #{workspace}/#{sub_dir}"
    end

  rescue Exception => e
    $log.writer.error "Can not cleanup Workspace!"
    $log.writer.error e.message
    exit 1
  end
end

.get_environemnt_variables(exception = []) ⇒ Object



2
3
4
5
6
7
8
9
10
11
12
13
# File 'lib/depengine/helper/hudson.rb', line 2

def get_environemnt_variables(exception=[])
  result = {}

  ENV.each do |key, value|
    unless (exception || []).include? key
      $log.writer.debug "Add environment variable #{key} with value #{value} to configuration hash"
      result[key] = value
    end
  end

  result
end

.init_workspace(workspace) ⇒ Object



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/depengine/helper/hudson.rb', line 49

def init_workspace(workspace)
  Helper.validates_presence_of workspace

  $log.writer.debug "Initialize Workspace"
  initial_dirs = %w{source target config keep log}
  begin
    initial_dirs.each do |dir|
      FileUtils.mkdir_p( File.join(workspace, dir) )
      $log.writer.debug "Create directory #{File.join(workspace, dir)}"
    end
  rescue Exception => e
    $log.writer.error "Can not create initial directories in workspace!"
    $log.writer.error e.message
    exit 1
  end
end

.parse_version(version) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
# File 'lib/depengine/helper/hudson.rb', line 16

def parse_version(version)
  result = {}
  begin
    result = JSON.parse(version)
  rescue
    $log.writer.debug "Given version string is not a JSON object"
    result = {"app" => version, "cdb" => "", "depsw" => ""}
  end

  result
end

.path_in_deploy_home(path) ⇒ Object



14
15
16
# File 'lib/depengine/helper/validations.rb', line 14

def path_in_deploy_home(path)
  absolute_path?(path) ? path : File.join($recipe_config[:deploy_home] || "", path)
end

.path_in_recipe_base_dir(path) ⇒ Object



19
20
21
# File 'lib/depengine/helper/validations.rb', line 19

def path_in_recipe_base_dir(path)
  absolute_path?(path) ? path : File.join($recipe_config[:recipe_base_dir] || "", path)
end

.validates_not_empty(attribute, message = nil) ⇒ Object

Raises:

  • (ArgumentError)


8
9
10
11
# File 'lib/depengine/helper/validations.rb', line 8

def validates_not_empty(attribute, message=nil)
  raise ArgumentError, message || "Parameter is empty", caller \
     if attribute.nil?
end

.validates_presence_of(attribute, message = nil) ⇒ Object

Raises:

  • (ArgumentError)


2
3
4
5
# File 'lib/depengine/helper/validations.rb', line 2

def validates_presence_of(attribute, message=nil)
  raise ArgumentError, message || "Missing parameter", caller \
     if attribute.nil?
end

.yaml_parse(filename) ⇒ Object



2
3
4
5
6
7
8
9
10
11
12
# File 'lib/depengine/helper/yaml.rb', line 2

def yaml_parse(filename)
  if File.file? filename
    begin
      YAML::load_file(filename)
    rescue Exception => e
      $log.writer.error "YAML parsing in #{filename}"
      $log.writer.error e.message
      exit 1
    end
  end
end