builder/extra/cluster-home/lib/ruby/tungsten/util.rb
# Read an INI file and return a hash of the arguments for each section
Read an INI file and return a hash of the arguments for each section
Read an INI file and return a hash of the arguments for each section
def parse_ini_file(file, convert_to_hash = true)
    unless defined?(IniParse)
      require 'tungsten/iniparse'
    end
    unless File.exists?(file)
      return
    end
    options = {}
    ini = IniParse.open(file)
    ini.each{
      |section|
      key = section.key
      unless options.has_key?(key)
        options[key] = []
      end
      section.each{
        |line|
        unless line.is_a?(Array)
          values = [line]
        else
          values = line
        end
        values.each{
          |value|
          if value.value == nil
            options[key] << "#{value.key}"
          else
            options[key] << "#{value.key}=#{value.value.to_s()}"
          end
        }
      }
    }
    if convert_to_hash == true
      return convert_ini_array_to_hash(options)
    else
      return options
    end
  end
def parse_ini_file ( file , convert_to_hash = true ) unless defined? ( IniParse ) require 'tungsten/iniparse' end unless File . exists? ( file ) return end options = { } ini = IniParse . open ( file ) ini . each { | section | key = section . key unless options . has_key? ( key ) options [ key ] = [ ] end section . each { | line | unless line . is_a? ( Array ) values = [ line ] else values = line end values . each { | value | if value . value == nil options [ key ] << "#{value.key}" else options [ key ] << "#{value.key}=#{value.value.to_s()}" end } } } if convert_to_hash == true return convert_ini_array_to_hash ( options ) else return options end end
Read an INI file and return a hash of the arguments for each section
Read an INI file and return a hash of the arguments for each section
# Read each section and turn the lines into an array of arguments as # they would appear in the INI file # Initialize the array only if it doesn't exist # Doing otherwise would overwrite old sections # Most users will want a Hash, but this will allow the main # TungstenScript class to see the parameters in order
file
convert_to_hash