module Utilities

This module contains further utility methods for Drupal_Clusting class

Private Instance Methods

display_outputs( stack_info ) click to toggle source

Display the creation outputs (basically any hash) by '<key>: <value>' lines

# File lib/etc/utilities.rb, line 43
def display_outputs( stack_info )
  stack_info.each_pair do |key, value|
    puts "#{key}: #{value}"
  end
end
get_comment_above(cmd=nil, file) click to toggle source

Gets either the first comment from the specified source file, if cmd is not defined. or the comment above the method named cmd. If comment/cmd is not found, returns “No help found”.

# File lib/etc/utilities.rb, line 53
def get_comment_above cmd=nil, file
  # RDoc's parse is not too user friendly, so..
  content = File.new(file).read
  regex_str = '##\s*\n((\s*#(| .*)\n)+)'
  regex_str += '\s*def\s+'+cmd+'\b'  if cmd
  regexp = Regexp.new regex_str
  if content =~ regexp
    comment_section = $1
    comment_section.gsub /^\s*#( |$)/, ''
  else
    "No help found for #{cmd}."
  end
end
get_password(for_what="DB") click to toggle source

A password will be asked twice on command line, with noecho, until the repetition coincides the previous one.

# File lib/etc/utilities.rb, line 15
def get_password for_what="DB"
  matching = false
  while not matching do
    pwd = STDIN.getpass "Type a password for #{for_what}: " 
    pwd2 = STDIN.getpass "Repeat it: "
    matching = (pwd == pwd2)
  end
  puts
  pwd.rstrip
end
read_conf_file() click to toggle source

Reads the configuration file

# File lib/etc/utilities.rb, line 28
def read_conf_file
  if not File.exist? @@conf_file
    FileUtils::mkdir_p(File.dirname @@conf_file)
    FileUtils::copy @@conf_default, @@conf_file
  end
  begin 
    @conf = IniFile.load File.new @@conf_file
  rescue SystemCallError => e
    puts e
  end
end