@api private

 @param [String] file
   File name.

 @return [#readable?, #writable?, nil]
   Struct with two boolean method.
   +nil+ for file not exists or is inaccessible.
346574
def file_permission(file)
      return nil unless File.file?(file)

      stat = File.stat(file)
      # we do a trick here because /proc/[pid]/mem might be marked as readable but fails at sysopen.
      os = OpenStruct.new(readable?: stat.readable_real?, writable?: stat.writable_real?)
      begin
        os.readable? && File.open(file, 'rb').close
      rescue Errno::EACCES
        os[:readable?] = false
      end
      begin
        os.writable? && File.open(file, 'wb').close
      rescue Errno::EACCES
        os[:writable?] = false
      end
      os
    end
492578
def file=(file)
      self.data = file
      dis_set :content_type, file.content_type
      dis_set :filename, file.original_filename
    end
1024658
def values_to_hash(values, file)
      @hash = {}
      values.each do |key, value|
        unless KEYS.include?(key)
          fail "Unrecognized key #{key} for #{feature}, #{name} in #{file}"
        end
        case key
        when 'auto_default'
          @auto_default = value ? true : false
        when 'data_format', 'get_data_format', 'set_data_format'
          @hash[key] = value.to_sym
        when 'default_only'
          @default_only = true
          # default_value overrides default_only
          @hash['default_value'] ||= value
        when 'multiple'
          @multiple = boolean_default_true(value)
        when 'kind'
          fail "Unknown 'kind': '#{value}'" unless KINDS.include?(value)
          @kind = value.to_sym
        when 'os_version'
          @os_version = value
        else
          # default_value overrides default_only
          @default_only = false if key == 'default_value'
          @hash[key] = value
        end
      end

      # Inherit general to specific if needed
      if @hash.key?('data_format')
        @hash['get_data_format'] = @hash['data_format'] \
          unless @hash.key?('get_data_format')
        @hash['set_data_format'] = @hash['data_format'] \
          unless @hash.key?('set_data_format')
      end
      if @hash.key?('context')
        @hash['get_context'] = @hash['context'] unless @hash.key?('get_context')
        @hash['set_context'] = @hash['context'] unless @hash.key?('set_context')
      end
      if @hash.key?('value')
        @hash['get_value'] = @hash['value'] unless @hash.key?('get_value')
        @hash['set_value'] = @hash['value'] unless @hash.key?('set_value')
      end

      @hash.delete_if { |key, _| key != 'default_value' } if @default_only
    end
1332957
def parse_file(self, file_or_fname):
        
        with self._context():
            if hasattr(file_or_fname, 'read'):
                self.filename = getattr(
                    file_or_fname, 'name', file_or_fname.__class__.__name__)
                self.p.ParseFile(file_or_fname)
            else:
                self.filename = file_or_fname
                with open(file_or_fname, 'rb') as f:
                    self.p.ParseFile(f)
        return self._root
457506
def headers(file)
      Array.new(CSV.open(file, &:readline).size) { |i| i.to_s }
    end
147186
def transform_file_name(file)
			if @bind
				variables = file.scan(/{{([^}]*)}}/).flatten

				variables.each do |v|
					file.sub!("{{#{v}}}", @bind.get_binding.eval(v))
				end
			end

			(!@nomodify && file.end_with?(".erb") && !File.directory?(file)) ? File.basename(file, ".*") : file
		end
1033439
def find_file(filenames)
      return nil if filenames.nil?

      filenames.each_value do |value|
        if value.is_a? Array
          value.each do |file|
            file_path = Utils.lookup_file file
            return file_path unless file_path.nil?
          end
        else
          file_path = Utils.lookup_file value
          return file_path unless file_path.nil?
        end
      end

      nil
    end
1159189
def from_file(filename, encoding='utf-8')
      mode = "rb:#{encoding}"
      mode = "rb" if RUBY_VERSION < '1.9'
      input = File.open(filename, mode) {|f| f.read() }
      compile(parse(input), filename, 1)
      return self
    end
841771
def parse_file(self, name):
        
        with open(name, "rb") as fp:
            return self.parse(fp.read())
1125595
def file(name)
      files.find {|file| file.file_ref.name == name or file.file_ref.path == name  }
    end
134170
def readlines(fname, &block)

      i = 0

      File.open(fname, 'rb') do |file|

        loop do

          i = i + 1

          line = file.gets || break

          block.call(line, i)
        end
      end
    end
1044923
def parse(filename=nil)

      self.clear # Needed if you parse multiple times
      @messages = []
      @valid = false

      if filename.nil?
        filename = @filename
      end


      filename = File.realpath(filename)
      @filename = filename
      if filename.nil? or not File.exists? filename
        raise ArgumentError, "Missing ARGOS DS file: \"#{filename}\""
      end
      @sha1 = Digest::SHA1.file(filename).hexdigest

      contact = []
      file = File.open(filename)
      @filesize = file.size
      @updated = file.mtime.utc

      log.debug "Parsing ARGOS DS file #{filename} source:#{sha1} (#{filesize} bytes)"
      if filter?
        log.debug "Using filter: #{@filtername.nil? ? filter : @filtername }"
      end

      firstline = file.readline
      file.rewind

      if firstline =~ START_REGEX_LEGACY
        return parse_legacy(file)
      end

      file.each_with_index do |line, c|
        line = line.strip

        #if (c+1) % 1000 == 0
        #  log.debug "Line: #{c+1}"
        #end

        if line =~ START_REGEX

          @valid = true

          if contact.any?
            item = parse_message(contact)

            if self.class.valid_item? item

              if not filter? or filter.call(item)
                @messages << item
              end

            else
              raise "Argos DS message #{filename}:#{c} lacks required program and/or platform"
            end
          end

          contact = [line]

        else
          # 2010-12-14 15:11:34  1         00           37           01           52
          if contact.any? and line != ""
            contact << line
          end
        end
      end

      if false == @valid
        #log.debug file.read
        message = "Cannot parse file: #{filename}"
        raise ArgumentError, message
      end

      last = parse_message(contact)

      # The last message
      if last
        if not filter? or filter.call(last)
          @messages << last
        end
      end

      log.debug "Parsed #{@messages.size} Argos DS messages into #{self.class.name} Array"
      @segments = @messages.size
      unfold.each do |d|
        self << d
      end

      @multiplicates = group_by { |e| e }.select { |k, v| v.size > 1 }.map(&:first)
      if multiplicates.any?
        log.warn "#{multiplicates.size} multiplicates in source sha1 #{sha1} #{filename}): #{multiplicates.map {|a|a[:id]} }"
        self.uniq!
        log.info "Unique DS messages: #{self.size} sha1: #{sha1} #{filename}"
      end
      self.sort_by! {|ds| ds[:measured]}
      self
    end
575767
def read_file(path, use_method = nil)
      if use_method
        use_method = use_method.to_sym
        raise ArgumentError, "use_method (#{use_method.inspect}) is not a valid method." unless file_methods.include?(use_method)
        raise Shells::ShellError, "The #{use_method} binary is not available with this shell." unless which(use_method)
        send "read_file_#{use_method}", path
      elsif default_file_method
        return send "read_file_#{default_file_method}", path
      else
        raise Shells::ShellError, 'No supported binary to encode/decode files.'
      end
    end
462995
def parse_yaml(file)
      file_content = File.exist?(file) ? ERB.new(File.read(file)).result : '---'

      config = YAML.load(file_content) || {}
      env    = ENV['RAILS_ENV'] || ENV['RACK_ENV'] || ENV['APP_CONFIG_ENV']

      config_from config['default'], config[env]
    end
786048
def load_file(file_name)
      File.open(file_name, "r") do |f|
        f.each_line.collect do |line|
          parse_json(line)
        end
      end
    end
1248420
def parse( file )
      pattern = PATTERNS[ File.extname( file ) ]

      IO.readlines( file ).take_while do |line|
        line =~ pattern
      end.map { |line| line[ pattern, 1 ] }
    end
1055349
def file(name, &block)
      path = @path + name
      unless ::File.file?(path)
        FileUtils.touch(path)
        @ctx.add(path)
      end
      f = File.new(@ctx, path)
      f.instance_eval(&block) if block_given?
      f
    end