aboutsummaryrefslogtreecommitdiff
path: root/wa/processors/status.py
blob: 9744519f084cabc87041bd84ffc5c04d180547f6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
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
#    Copyright 2013-2015 ARM Limited
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#


# pylint: disable=R0201
import os
import time
from collections import Counter

from wa import ResultProcessor, Status
from wa.utils.misc import write_table


class StatusTxtReporter(ResultProcessor):
    name = 'status'
    description = """
    Outputs a txt file containing general status information about which runs
    failed and which were successful

    """

    def process_run_output(self, output, target_info):
        counter = Counter()
        for jo in output.jobs:
            counter[jo.status] += 1

        outfile = output.get_path('status.txt')
        self.logger.info('Status available in {}'.format(outfile))
        with open(outfile, 'w') as wfh:
            wfh.write('Run name: {}\n'.format(output.info.run_name))
            wfh.write('Run status: {}\n'.format(output.status))
            wfh.write('Date: {}\n'.format(time.strftime("%c")))
            if output.events:
                wfh.write('Events:\n')
                for event in output.events:
                    wfh.write('\t{}\n'.format(event.summary))

            txt = '{}/{} iterations completed without error\n'
            wfh.write(txt.format(counter[Status.OK], len(output.jobs)))
            wfh.write('\n')
            status_lines = [map(str, [o.id, o.label, o.iteration, o.status,
                                      o.event_summary])
                            for o in output.jobs]
            write_table(status_lines, wfh, align='<<>><')

        output.add_artifact('run_status_summary', 'status.txt', 'export')