Received: from eggs.gnu.org ([208.118.235.92]:44503) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SCaUv-0007ms-Qc for qemu-devel@nongnu.org; Tue, 27 Mar 2012 13:47:59 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SCaUt-0005rX-Vi for qemu-devel@nongnu.org; Tue, 27 Mar 2012 13:47:57 -0400 Received: from roura.ac.upc.es ([147.83.33.10]:60014) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SCaUt-0005mk-L3 for qemu-devel@nongnu.org; Tue, 27 Mar 2012 13:47:55 -0400 From: =?utf-8?Q?Llu=C3=ADs_Vilanova?= References: <20120326173743.20814.3629.stgit@ginnungagap.bsc.es> <20120326173750.20814.75373.stgit@ginnungagap.bsc.es> <20120327151756.GK32389@garlic> Date: Tue, 27 Mar 2012 19:47:51 +0200 In-Reply-To: <20120327151756.GK32389@garlic> (Alon Levy's message of "Tue, 27 Mar 2012 17:17:56 +0200") Message-ID: <87iphq6im0.fsf@ginnungagap.bsc.es> MIME-Version: 1.0 Content-Type: text/plain Subject: Re: [Qemu-devel] [RFC PATCH v2 1/8] tracetool: Rewrite infrastructure as python modules List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: stefanha@gmail.com Alon Levy writes: [...] >> + >> + >> +_SCRIPT = "" > I don't understand the point of this, why not use sys.argv[0] directly? [...] >> +def main(args): >> + global _SCRIPT >> + _SCRIPT = sys.argv[0] >> + Well, my idea is that it must work only with the arguments to 'main', without depending on any other system state. BTW, I fixed main to be "_SCRIPT = args[0]" instead of "sys.argv[0]" (otherwise it makes no sense). [...] >> +def get_list(only_public = False): >> + """Get a list of (name, description) pairs.""" >> + res = [("nop", "Tracing disabled.")] >> + for _, modname, _ in pkgutil.iter_modules(tracetool.backend.__path__): >> + module = tracetool.try_import("tracetool.backend." + modname)[1] >> + > Here module can be None if ImportError was raised in try_import. >> + public = getattr(module, "PUBLIC", False) > public will be False Not really; as it only tries to import files stemming from 'pkgutil.iter_modules', this should always succeed. In any case, I put a guard just in case someone puts a non-module file there (which should never happen). >> + if only_public and not public: >> + continue > continue isn't reached if not only_public (default value) Right, 'only_public' is only used sometimes (when handling "--list-backends" cmdline option). I'll send a new version once I put all the changes into my tree. Thanks for all the catches, Lluis -- "And it's much the same thing with knowledge, for whenever you learn something new, the whole world becomes that much richer." -- The Princess of Pure Reason, as told by Norton Juster in The Phantom Tollbooth