Class: Debci::Log
- Inherits:
-
Object
- Object
- Debci::Log
- Defined in:
- lib/debci/log.rb
Defined Under Namespace
Classes: Section
Instance Attribute Summary collapse
-
#sections ⇒ Object
readonly
Returns the value of attribute sections.
Instance Method Summary collapse
-
#initialize(logfile) ⇒ Log
constructor
A new instance of Log.
- #parse ⇒ Object
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
#sections ⇒ Object (readonly)
Returns the value of attribute sections.
33 34 35 |
# File 'lib/debci/log.rb', line 33 def sections @sections end |
Instance Method Details
#parse ⇒ Object
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 88 89 |
# File 'lib/debci/log.rb', line 35 def parse section = nil subsection = nil result = false file = File.open(@input) 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") result = true 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 && subsection != section.subsections.last section.subsections << subsection end end subsection.output << line if subsection if section && result && line =~ /^\s*\d+s\s+\S+\s*(PASS|FAIL|SKIP)/ section.result = ::Regexp.last_match(1).downcase result = false end end end |