Class: Debci::Log

Inherits:
Object
  • Object
show all
Defined in:
lib/debci/log.rb

Defined Under Namespace

Classes: Section

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(logfile) ⇒ Log

Returns a new instance of Log.



28
29
30
31
# File 'lib/debci/log.rb', line 28

def initialize(logfile)
  @input = logfile
  @sections = []
end

Instance Attribute Details

#sectionsObject (readonly)

Returns the value of attribute sections.



33
34
35
# File 'lib/debci/log.rb', line 33

def sections
  @sections
end

Instance Method Details

#parseObject



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/debci/log.rb', line 35

def parse
  section = nil
  subsection = nil
  File.open(@input) do |file|
    if @input =~ /\.gz/
      file = Zlib::GzipReader.new(file)
    end
    file.readlines.each do |line|
      line = line.scrub unless line.valid_encoding?
      case line
      when /^\s*\d+s autopkgtest \[\d\d:\d\d:\d\d\]: starting date and time/
        section = Section.new("Preparation")
        subsection = Section.new("start run")
      when /^\s*\d+s autopkgtest \[\d\d:\d\d:\d\d\]: @@@@@@@@@@@@@@@@@@@@ apt-source/
        subsection = Section.new("apt-source")
      when /^\s*\d+s autopkgtest \[\d\d:\d\d:\d\d\]: @@@@@@@@@@@@@@@@@@@@ test bed setup/
        subsection = Section.new("test bed setup")

      when /^\s*\d+s autopkgtest \[\d\d:\d\d:\d\d\]: test (.*): preparing testbed/
        section = Section.new("test #{::Regexp.last_match(1)}")
        subsection = Section.new("preparing testbed")
      when /^\s*\d+s autopkgtest \[\d\d:\d\d:\d\d\]: test (.*): \[-----------------------/
        subsection = Section.new("test run")
      when /^\s*\d+s autopkgtest \[[0-9:]+\]: test (\S+):  - - - - - - - - - - results - - - - - - - - - -/
        subsection = Section.new("test results")
      when /^\s*\d+s autopkgtest \[\d\d:\d\d:\d\d\]: @@@@@@@@@@@@@@@@@@@@ (summary)/
        section = Section.new("Closing")
        subsection = Section.new("summary")
      when /^\s*\d+s\s+badpkg:\s+/
        section.result = "fail" unless section.name == "Closing"
      else
        # first line of non-autopkgtest log
        unless section
          section = Section.new("Log contents")
          subsection = section
        end
      end
      if section
        if section != self.sections.last
          self.sections << section
        end
        if subsection && subsection != section.subsections.last
          section.subsections << subsection
        end
      end
      subsection.output << line if subsection

      if section && line =~ /^\s*\d+s\s+\S+\s*(PASS|FAIL|SKIP)/
        section.result = ::Regexp.last_match(1).downcase
      end
    end
  end
end