Class: Autoproj::Ops::PhaseReporting

Inherits:
Object
  • Object
show all
Defined in:
lib/autoproj/ops/phase_reporting.rb

Overview

Common logic to generate build/import/utility reports

Instance Method Summary collapse

Constructor Details

#initialize(name, path, metadata_get) ⇒ PhaseReporting

Returns a new instance of PhaseReporting.



5
6
7
8
9
# File 'lib/autoproj/ops/phase_reporting.rb', line 5

def initialize(name, path, )
    @name = name
    @path = path
    @metadata_get = 
end

Instance Method Details

#create_report(autobuild_packages) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/autoproj/ops/phase_reporting.rb', line 11

def create_report(autobuild_packages)
    info = autobuild_packages.each_with_object({}) do |p, map|
        map[p.name] = @metadata_get.call(p)
    end

    dump = JSON.dump(
        "#{@name}_report" => {
            "timestamp" => Time.now,
            "packages" => info
        }
    )

    FileUtils.mkdir_p File.dirname(@path)
    File.open(@path, "w") do |io|
        io.write dump
    end
end

#initialize_incremental_reportObject



29
30
31
32
# File 'lib/autoproj/ops/phase_reporting.rb', line 29

def initialize_incremental_report
    FileUtils.mkdir_p File.dirname(@path)
    @incremental_report = ""
end

#report_incremental(autobuild_package) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/autoproj/ops/phase_reporting.rb', line 34

def report_incremental(autobuild_package)
     = @metadata_get.call(autobuild_package)
    prefix = @incremental_report.empty? ? "\n" : ",\n"
    @incremental_report.concat(
        "#{prefix}\"#{autobuild_package.name}\": #{JSON.dump()}"
    )
    File.open(@path, "w") do |io|
        io.write "{ \"#{@name}_report\": "\
                 "{\"timestamp\": #{JSON.dump(Time.now)}, \"packages\": {"
        io.write(@incremental_report)
        io.write "}}}"
    end
end