From aed440e061d6faacefa1f75c04884a604f1041a2 Mon Sep 17 00:00:00 2001
From: Mitchel Humpherys <mitchelh@codeaurora.org>
Date: Mon, 12 May 2014 10:56:42 -0700
Subject: [PATCH] lrdp-v2: provide method for flushing outfile

Sometimes it's useful to force a flush of the global outfile. Provide a
method to do so and use it in the main parser loop.

Change-Id: I18e9a07345c852d498b131b442df5a0c95bbcf98
---
 linux-ramdump-parser-v2/print_out.py | 7 ++++++-
 linux-ramdump-parser-v2/ramparse.py  | 3 ++-
 2 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/linux-ramdump-parser-v2/print_out.py b/linux-ramdump-parser-v2/print_out.py
index 9a2698e..2f5635d 100644
--- a/linux-ramdump-parser-v2/print_out.py
+++ b/linux-ramdump-parser-v2/print_out.py
@@ -1,4 +1,4 @@
-# Copyright (c) 2012-2013, The Linux Foundation. All rights reserved.
+# Copyright (c) 2012-2014, The Linux Foundation. All rights reserved.
 #
 # This program is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License version 2 and
@@ -14,6 +14,11 @@ from contextlib import contextmanager
 
 out_file = None
 
+def flush_outfile():
+    if out_file is None:
+        sys.stdout.flush()
+    else:
+        out_file.flush()
 
 def set_outfile(path):
     global out_file
diff --git a/linux-ramdump-parser-v2/ramparse.py b/linux-ramdump-parser-v2/ramparse.py
index 0fe0c08..d437120 100755
--- a/linux-ramdump-parser-v2/ramparse.py
+++ b/linux-ramdump-parser-v2/ramparse.py
@@ -26,7 +26,7 @@ from optparse import OptionParser
 
 import parser_util
 from ramdump import RamDump
-from print_out import print_out_str, set_outfile, print_out_section, print_out_exception
+from print_out import print_out_str, set_outfile, print_out_section, print_out_exception, flush_outfile
 
 # Please update version when something is changed!'
 VERSION = '2.0'
@@ -322,6 +322,7 @@ if __name__ == '__main__':
                 sys.stderr.write("FAILED! ")
         sys.stderr.write("%fs\n" % (time.time() - before))
         sys.stderr.flush()
+        flush_outfile()
 
     sys.stderr.write("\n")
 
-- 
GitLab