Total Complexity | 10 |
Total Lines | 33 |
Duplicated Lines | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | |||
8 | class FileReportBackend(BaseReportBackend): |
||
9 | def __init__(self, config): |
||
10 | super(FileReportBackend, self).__init__(config) |
||
11 | self.storage = Storage(config.getoption("benchmark_storage"), |
||
12 | default_machine_id=self.machine_id, |
||
13 | logger=self.logger) |
||
14 | |||
15 | @property |
||
16 | def _next_num(self): |
||
17 | files = self.storage.query("[0-9][0-9][0-9][0-9]_*") |
||
18 | files.sort(reverse=True) |
||
19 | if not files: |
||
20 | return "0001" |
||
21 | for f in files: |
||
22 | try: |
||
23 | return "%04i" % (int(str(f.name).split('_')[0]) + 1) |
||
24 | except ValueError: |
||
25 | raise |
||
26 | |||
27 | def _save(self, output_json, save): |
||
28 | output_file = self.storage.get("%s_%s.json" % (self._next_num, save)) |
||
29 | self.logger.info("output_file " + str(output_file)) |
||
30 | self.logger.info("save " + str(save)) |
||
31 | assert not output_file.exists() |
||
32 | with output_file.open('wb') as fh: |
||
33 | fh.write(safe_dumps(output_json, ensure_ascii=True, indent=4).encode()) |
||
34 | self.logger.info("Saved benchmark data in: %s" % output_file) |
||
35 | |||
36 | def _load(self, id_prefix=None): |
||
37 | if id_prefix is None: |
||
38 | return self.storage.load('[0-9][0-9][0-9][0-9]_') |
||
39 | else: |
||
40 | return self.storage.load(id_prefix) |
||
41 | |||
42 |