class Roby::DRoby::Logfile::Reader

A class that reads log files generated by {Writer}

Constants

FORMAT_VERSION

The current log format version

Attributes

event_io[R]

Public Class Methods

new(event_io) click to toggle source
# File lib/roby/droby/logfile/reader.rb, line 14
def initialize(event_io)
    @event_io = event_io
    event_io.rewind
    options_hash = read_header
    self.class.process_options_hash(options_hash)
end
open(path) { |io| ... } click to toggle source
# File lib/roby/droby/logfile/reader.rb, line 123
def self.open(path)
    io = new(File.open(path))
    if block_given?
        begin
            yield(io)
        ensure
            io.close unless io.closed?
        end
    else
        io
    end
end
process_options_hash(options_hash) click to toggle source
# File lib/roby/droby/logfile/reader.rb, line 68
def self.process_options_hash(options_hash)
    if options_hash[:plugins]
        options_hash[:plugins].each do |plugin_name|
            begin
                Roby.app.using plugin_name
            rescue ArgumentError => e
                Roby.warn "the log file mentions the #{plugin_name} plugin, but it is not available on this system. Some information might not be displayed"
            end
        end
    end
end

Public Instance Methods

close() click to toggle source
# File lib/roby/droby/logfile/reader.rb, line 38
def close
    event_io.close
end
closed?() click to toggle source
# File lib/roby/droby/logfile/reader.rb, line 46
def closed?
    event_io.closed?
end
dup() click to toggle source
# File lib/roby/droby/logfile/reader.rb, line 30
def dup
    Reader.new(event_io.dup)
end
eof?() click to toggle source
# File lib/roby/droby/logfile/reader.rb, line 42
def eof?
    event_io.eof?
end
index(path = index_path, rebuild: true) click to toggle source

Returns the index object for this event log

# File lib/roby/droby/logfile/reader.rb, line 98
def index(path = index_path, rebuild: true)
    if @index
        return @index
    elsif !File.file?(path)
        if !rebuild
            raise IndexMissing, "there's no file #{path}"
        end
        rebuild_index(path)
    end

    index =
        begin Index.read(path)
        rescue Exception => e
            raise e, "while reading index file #{path}: #{e.message}", e.backtrace
        end
    if index.valid_for?(event_io.path)
        @index = index
    elsif !rebuild
        raise IndexInvalid, "#{path} is not a valid index for #{self}"
    else
        rebuild_index(path)
        @index = Index.read(path)
    end
end
index_path() click to toggle source

The standard Roby index path, inferred from the log file's own path

@return [String]

# File lib/roby/droby/logfile/reader.rb, line 84
def index_path
    event_io.path.gsub(/\.log$/, '') + ".idx"
end
load_one_cycle() click to toggle source
# File lib/roby/droby/logfile/reader.rb, line 54
def load_one_cycle
    if chunk = Logfile.read_one_chunk(event_io)
        begin ::Marshal.load_with_missing_constants(chunk)
        rescue ArgumentError => e
            if e.message == "marshal data too short"
                raise TruncatedFileError, "marshal data invalid"
            else raise
            end
        end
    end
rescue Exception => e
    raise e, "#{e.message}, running roby-log repair might repair the file", e.backtrace
end
read_header() click to toggle source
# File lib/roby/droby/logfile/reader.rb, line 21
def read_header
    Logfile.read_prologue(event_io)
    if chunk = Logfile.read_one_chunk(event_io)
        ::Marshal.load(chunk)
    else
        raise InvalidFileError, "expected the prologue to be followed by one chunk, but got nothing"
    end
end
rebuild_index(path = index_path) click to toggle source
# File lib/roby/droby/logfile/reader.rb, line 88
def rebuild_index(path = index_path)
    Logfile.warn "rebuilding index file for #{event_io.path}"
    File.open(path, 'w') do |index_io|
        event_io = self.event_io.dup
        Index.rebuild(File.open(event_io.path), index_io)
    end
    @index = nil
end
seek(pos) click to toggle source
# File lib/roby/droby/logfile/reader.rb, line 50
def seek(pos)
    event_io.seek(pos)
end
tell() click to toggle source
# File lib/roby/droby/logfile/reader.rb, line 34
def tell
    event_io.tell
end