Unifies the print+exit sequence into a single 'error' call. Signed-off-by: Lluís Vilanova <vilan...@ac.upc.edu> Signed-off-by: Harsh Prateek Bora <ha...@linux.vnet.ibm.com> --- scripts/tracetool.py | 27 +++++++++++++++------------ 1 files changed, 15 insertions(+), 12 deletions(-)
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