diff mbox

[12/12] trace: [tracetool] Add error-reporting functions

Message ID 20120313200343.24179.70582.stgit@ginnungagap.bsc.es
State New
Headers show

Commit Message

Lluís Vilanova March 13, 2012, 8:03 p.m. UTC
Unifies the print+exit sequence into a single 'error' call.

Signed-off-by: Lluís Vilanova <vilanova@ac.upc.edu>
Signed-off-by: Harsh Prateek Bora <harsh@linux.vnet.ibm.com>
---
 scripts/tracetool.py |   27 +++++++++++++++------------
 1 files changed, 15 insertions(+), 12 deletions(-)

Comments

Stefan Hajnoczi March 19, 2012, 5:45 p.m. UTC | #1
On Tue, Mar 13, 2012 at 09:03:43PM +0100, Lluís Vilanova wrote:
> @@ -514,8 +521,9 @@ def main():
>      try:
>          opts, args = getopt.getopt(sys.argv[1:], "", long_options)
>      except getopt.GetoptError, err:
> -        # print help information and exit:
> -        print str(err) # will print something like "option -a not recognized"
> +        # print help information and exit
> +        # will print something like "option -a not recognized"
> +        error_write(str(err)+"\n")

Please use whitespace in expressions:

error_write(str(err) + "\n")
diff mbox

Patch

diff --git a/scripts/tracetool.py b/scripts/tracetool.py
index 0f76b50..6714466 100755
--- a/scripts/tracetool.py
+++ b/scripts/tracetool.py
@@ -63,6 +63,13 @@  def get_format_descr(format_):
         return ""
 
 
+def error_write(*lines):
+    sys.stderr.writelines(lines)
+
+def error(*lines):
+    error_write(*lines)
+    sys.exit(1)
+
 
 ######################################################################
 # backend auto-registration and format compatibility
@@ -514,8 +521,9 @@  def main():
     try:
         opts, args = getopt.getopt(sys.argv[1:], "", long_options)
     except getopt.GetoptError, err:
-        # print help information and exit:
-        print str(err) # will print something like "option -a not recognized"
+        # print help information and exit
+        # will print something like "option -a not recognized"
+        error_write(str(err)+"\n")
         usage()
         sys.exit(2)
     for opt, arg in opts:
@@ -544,24 +552,19 @@  def main():
             usage()
 
     if format_ not in _formats:
-        print "Unknown format: %s" % format_
-        print
+        error_write("Unknown format: %s\n\n" % format_)
         usage()
     if backend not in _backends:
-        print "Unknown backend: %s" % backend
-        print
+        error_write("Unknown backend: %s\n\n" % backend)
         usage()
 
     if format_ == 'stap':
         if binary == "":
-            print '--binary is required for SystemTAP tapset generator'
-            sys.exit(1)
+            error("--binary is required for SystemTAP tapset generator\n")
         if not probeprefix and  not targettype:
-            print '--target-type is required for SystemTAP tapset generator'
-            sys.exit(1)
+            error("--target-type is required for SystemTAP tapset generator\n")
         if not probeprefix and  not targetarch:
-            print '--target-arch is required for SystemTAP tapset generator'
-            sys.exit(1)
+            error("--target-arch is required for SystemTAP tapset generator\n")
         if probeprefix == "":
             probeprefix = 'qemu.' + targettype + '.' + targetarch