From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:54985) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SDX3v-0001Hz-Gv for qemu-devel@nongnu.org; Fri, 30 Mar 2012 04:20:04 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SDX3s-0004ah-7G for qemu-devel@nongnu.org; Fri, 30 Mar 2012 04:19:59 -0400 Received: from mail-wi0-f181.google.com ([209.85.212.181]:61781) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SDX3r-0004Xu-Tu for qemu-devel@nongnu.org; Fri, 30 Mar 2012 04:19:56 -0400 Received: by mail-wi0-f181.google.com with SMTP id hr17so287951wib.10 for ; Fri, 30 Mar 2012 01:19:55 -0700 (PDT) Date: Fri, 30 Mar 2012 08:27:16 +0100 From: Stefan Hajnoczi Message-ID: <20120330072716.GA16437@stefanha-thinkpad.localdomain> References: <20120327194910.7241.47693.stgit@ginnungagap.bsc.es> <20120327194918.7241.10931.stgit@ginnungagap.bsc.es> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20120327194918.7241.10931.stgit@ginnungagap.bsc.es> Subject: Re: [Qemu-devel] [RFC PATCH v3 1/8] tracetool: Rewrite infrastructure as python modules List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: =?iso-8859-1?Q?Llu=EDs?= Vilanova Cc: qemu-devel@nongnu.org On Tue, Mar 27, 2012 at 09:49:18PM +0200, Lluís Vilanova wrote: > diff --git a/scripts/tracetool.py b/scripts/tracetool.py > new file mode 100755 > index 0000000..70bf79a > --- /dev/null > +++ b/scripts/tracetool.py > @@ -0,0 +1,110 @@ > +#!/usr/bin/env python > +# -*- coding: utf-8 -*- > + > +""" > +Command-line wrapper for the tracetool machinery. > +""" > + > +__author__ = "Lluís Vilanova " > +__copyright__ = "Copyright 2012, Lluís Vilanova " > +__license__ = "GPL version 2 or (at your option) any later version" > + > +__maintainer__ = "Stefan Hajnoczi" > +__email__ = "stefanha@linux.vnet.ibm.com" > + > + > +import sys > +import getopt > + > +from tracetool import error_write, out > +import tracetool.backend > +import tracetool.format > + > + > +_SCRIPT = "" > + > +def error_opt(msg = None): > + if msg is not None: > + error_write("Error: " + msg + "\n") > + > + backend_descr = "\n".join([ " %-15s %s" % (n, d) > + for n,d in tracetool.backend.get_list() ]) > + format_descr = "\n".join([ " %-15s %s" % (n, d) > + for n,d in tracetool.format.get_list() ]) > + error_write("""\ > +Usage: %(script)s --format= --backend= [] > + > +Backends: > +%(backends)s > + > +Formats: > +%(formats)s > + > +Options: > + --help This help message. > + --list-backends Print list of available backends. > + --check-backend Check if the given backend is valid. > +""" % { > + "script" : _SCRIPT, > + "backends" : backend_descr, > + "formats" : format_descr, > + }) > + > + if msg is None: > + sys.exit(0) > + else: > + sys.exit(1) > + > + > +def main(args): > + global _SCRIPT > + _SCRIPT = args[0] > + > + long_opts = [ "backend=", "format=", "help", "list-backends", "check-backend" ] > + long_opts += [ "binary=", "target-type=", "target-arch=", "probe-prefix=" ] > + > + try: > + opts, args = getopt.getopt(args[1:], "", long_opts) > + except getopt.GetoptError as err: > + error_opt(str(err)) > + > + check_backend = False > + arg_backend = "" > + arg_format = "" > + for opt, arg in opts: > + if opt == "--help": > + error_opt() > + > + elif opt == "--backend": > + arg_backend = arg > + elif opt == "--format": > + arg_format = arg > + > + elif opt == "--list-backends": > + public_backends = tracetool.backend.get_list(only_public = True) > + out(", ".join([ b for b,_ in public_backends ])) > + sys.exit(0) > + elif opt == "--check-backend": > + check_backend = True > + > + else: > + error_opt("unhandled option: %s" % opt) > + > + if arg_backend is None: > + error_opt("backend not set") > + > + if check_backend: > + if tracetool.backend.exists(arg_backend): > + sys.exit(0) > + else: > + sys.exit(1) > + > + kwargs = {} > + > + try: > + tracetool.generate(sys.stdin, arg_format, arg_backend, **kwargs) If forgot to ask what kwargs is doing here? Can we default to {}? Otherwise let's drop it for now since there are no options defined yet. Stefan