From 3989034737a727a31804572e9ba9af289d9c797c Mon Sep 17 00:00:00 2001 From: Laszlo Nagy Date: Mon, 14 Nov 2016 21:28:44 +1100 Subject: [PATCH] simplify JSON read/write on libscanbuild side --- libscanbuild/intercept.py | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/libscanbuild/intercept.py b/libscanbuild/intercept.py index 3e2cd68..bf2dab1 100644 --- a/libscanbuild/intercept.py +++ b/libscanbuild/intercept.py @@ -161,10 +161,9 @@ def write_exec_trace(filename, entry): :param filename: path to the output execution trace file, :param entry: the Execution object to append to that file. """ + call = {'pid': entry.pid, 'cwd': entry.cwd, 'cmd': entry.cmd} with open(filename, 'w') as handler: - call = {'pid': entry.pid, 'cwd': entry.cwd, 'cmd': entry.cmd} - line = json.dumps(call) - handler.write(line) + json.dump(call, handler) def parse_exec_trace(filename): @@ -178,12 +177,11 @@ def parse_exec_trace(filename): logging.debug(filename) with open(filename, 'r') as handler: - for line in handler: - entry = json.loads(line.strip()) - return Execution( - pid=entry['pid'], - cwd=entry['cwd'], - cmd=entry['cmd']) + entry = json.load(handler) + return Execution( + pid=entry['pid'], + cwd=entry['cwd'], + cmd=entry['cmd']) def exec_trace_files(directory):