forked from awslabs/damo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
damo_convert_record_format.py
42 lines (33 loc) · 1.24 KB
/
damo_convert_record_format.py
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
# SPDX-License-Identifier: GPL-2.0
import os
import _damon_result
def set_argparser(parser):
parser.add_argument('--record_file', metavar='<file>',
default='damon.data', help='the record file')
parser.add_argument('--format',
choices=_damon_result.self_write_supported_file_types,
default=_damon_result.file_type_json_compressed,
help='new file format')
parser.add_argument('--output_file', metavar='<file>',
help='the path to converted file')
def main(args=None):
if not args:
parser = argparse.ArgumentParser()
set_argparser(parser)
args = parser.parse_args()
if not os.path.isfile(args.record_file):
print('record file (%s) is not exist' % args.record_file)
exit(1)
if not args.output_file:
args.output_file = args.record_file
records, err = _damon_result.parse_records_file(args.record_file, None)
if err != None:
print('parsing record file failed (%s)' % err)
exit(1)
err = _damon_result.write_damon_records(records, args.output_file,
args.format)
if err != None:
print('writing records again failed (%s)' % err)
exit(1)
if __name__ == '__main__':
main()