tungsten-replicator/builder/extra/tools/ruby-tpm/properties.rb
# Read properties from a file. 
Read properties from a file.
Read properties from a file .
def load(properties_filename)
    file_contents = ""
    File.open(properties_filename, 'r') do |file|
      file.read.each_line do |line|
        line.strip!
        unless (line =~ /^#.*/)
          file_contents = file_contents + line
        end
      end
      begin
        parsed_contents = JSON.parse(file_contents)
      rescue Exception => e
        if file_contents == ""
          parsed_contents = {}
        elsif file_contents[0,1] == "{"
          raise "There was an error parsing the config file: #{e.message}"
        end
      end
      if parsed_contents && parsed_contents.instance_of?(Hash)
        @props = parsed_contents
      elsif @force_json == true
        raise "There was an error parsing the JSON config file: #{properties_filename}.  Try using the migration procedure if you have an old configuration file."
      else
        new_props = {}
        file.rewind()
        file.read.each_line do |line|
          line.strip!
          if (line =~ /^([\w\.]+)\[?([\w\.]+)?\]?\s*=\s*(\S.*)/)
            key = $1
            value = $3
            if $2
              new_props[key] = {} unless new_props[key]
              new_props[key][$2] = value
            else
              new_props[key] = value
            end
          elsif (line =~ /^([\w\.]+)\s*=/)
            key = $1
            value = ""
            new_props[key] = value
          end
        end
        @props = new_props
      end
      original_props = @props.dup
      if original_props != @props
        Configurator.instance.warning("Deprecated keys in the config file were updated")
      end
    end
  end
def load ( properties_filename ) file_contents = "" File . open ( properties_filename , 'r' ) do | file | file . read . each_line do | line | line . strip! unless ( line =~ / ^#.* / ) file_contents = file_contents + line end end begin parsed_contents = JSON . parse ( file_contents ) rescue Exception => e if file_contents == "" parsed_contents = { } elsif file_contents [ 0 , 1 ] == "{" raise "There was an error parsing the config file: #{e.message}" end end if parsed_contents && parsed_contents . instance_of? ( Hash ) @props = parsed_contents elsif @force_json == true raise "There was an error parsing the JSON config file: #{properties_filename}.  Try using the migration procedure if you have an old configuration file." else new_props = { } file . rewind ( ) file . read . each_line do | line | line . strip! if ( line =~ / ^([ \w \. ]+) \[ ?([ \w \. ]+)? \] ? \s *= \s *( \S .*) / ) key = $1 value = $3 if $2 new_props [ key ] = { } unless new_props [ key ] new_props [ key ] [ $2 ] = value else new_props [ key ] = value end elsif ( line =~ / ^([ \w \. ]+) \s *= / ) key = $1 value = "" new_props [ key ] = value end end @props = new_props end original_props = @props . dup if original_props != @props Configurator . instance . warning ( "Deprecated keys in the config file were updated" ) end end end
Read properties from a file.
Read properties from a file .
properties_filename