-
Notifications
You must be signed in to change notification settings - Fork 3
/
harmerge
executable file
·49 lines (43 loc) · 1.44 KB
/
harmerge
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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os
import sys
import harlib.api
import argparse
import logging
logger = logging.getLogger('harmerge')
def add_arguments(parser):
parser.add_argument('files', default=[], nargs='+')
return parser
def handle(*args, **options):
files = options.get('files', [])
output = None
try:
with open(files[0]) as reader:
output = harlib.api.loads(reader.read())
except Exception as err:
logging.error("%s while reading %s" % (repr(err), filename), exc_info=True)
if not output:
raise ValueError
for filename in files[1:]:
har_file = None
try:
with open(filename) as reader:
har_file = harlib.api.loads(reader.read())
except Exception as err:
logging.error("%s while reading %s" % (repr(err), filename), exc_info=True)
if har_file:
print(type(har_file))
if har_file.log:
print(type(har_file.log))
if har_file.log.entries:
print(type(har_file.log.entries))
output.log.entries += har_file.log.entries
print(harlib.api.dumps(output))
def main():
logging.basicConfig(filename='/dev/stdout', level=logging.DEBUG)
parser = add_arguments(argparse.ArgumentParser())
options = parser.parse_args(sys.argv[1:])
sys.exit(handle(**vars(options)))
if __name__ == '__main__':
main()