From patchwork Mon Oct 17 15:29:34 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Capitulino X-Patchwork-Id: 120235 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [140.186.70.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 94DA6B6F6B for ; Tue, 18 Oct 2011 02:30:19 +1100 (EST) Received: from localhost ([::1]:41237 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RFp8q-0001ga-BV for incoming@patchwork.ozlabs.org; Mon, 17 Oct 2011 11:30:16 -0400 Received: from eggs.gnu.org ([140.186.70.92]:42866) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RFp8a-0001UU-UG for qemu-devel@nongnu.org; Mon, 17 Oct 2011 11:30:02 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RFp8T-0006Bk-AP for qemu-devel@nongnu.org; Mon, 17 Oct 2011 11:30:00 -0400 Received: from mx1.redhat.com ([209.132.183.28]:18584) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RFp8S-0006BH-Vj for qemu-devel@nongnu.org; Mon, 17 Oct 2011 11:29:53 -0400 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id p9HFTh81029430 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Mon, 17 Oct 2011 11:29:43 -0400 Received: from localhost (ovpn-113-62.phx2.redhat.com [10.3.113.62]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id p9HFTgcd010539; Mon, 17 Oct 2011 11:29:42 -0400 From: Luiz Capitulino To: mdroth@linux.vnet.ibm.com Date: Mon, 17 Oct 2011 13:29:34 -0200 Message-Id: <1318865377-3328-2-git-send-email-lcapitulino@redhat.com> In-Reply-To: <1318865377-3328-1-git-send-email-lcapitulino@redhat.com> References: <1318865377-3328-1-git-send-email-lcapitulino@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.12 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-Received-From: 209.132.183.28 Cc: aliguori@us.ibm.com, qemu-devel@nongnu.org Subject: [Qemu-devel] [PATCH 1/4] qapi-types.py: Add a main() like function X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Makes it easier to read the code. Signed-off-by: Luiz Capitulino Reviewed-by: Michael Roth --- scripts/qapi-types.py | 230 ++++++++++++++++++++++++------------------------ 1 files changed, 115 insertions(+), 115 deletions(-) diff --git a/scripts/qapi-types.py b/scripts/qapi-types.py index f64d84c..986ff1e 100644 --- a/scripts/qapi-types.py +++ b/scripts/qapi-types.py @@ -161,118 +161,118 @@ void qapi_free_%(type)s(%(c_type)s obj) c_type=c_type(name),type=name) return ret - -try: - opts, args = getopt.gnu_getopt(sys.argv[1:], "p:o:", ["prefix=", "output-dir="]) -except getopt.GetoptError, err: - print str(err) - sys.exit(1) - -output_dir = "" -prefix = "" -c_file = 'qapi-types.c' -h_file = 'qapi-types.h' - -for o, a in opts: - if o in ("-p", "--prefix"): - prefix = a - elif o in ("-o", "--output-dir"): - output_dir = a + "/" - -c_file = output_dir + prefix + c_file -h_file = output_dir + prefix + h_file - -try: - os.makedirs(output_dir) -except os.error, e: - if e.errno != errno.EEXIST: - raise - -fdef = open(c_file, 'w') -fdecl = open(h_file, 'w') - -fdef.write(mcgen(''' -/* AUTOMATICALLY GENERATED, DO NOT MODIFY */ - -/* - * deallocation functions for schema-defined QAPI types - * - * Copyright IBM, Corp. 2011 - * - * Authors: - * Anthony Liguori - * Michael Roth - * - * This work is licensed under the terms of the GNU LGPL, version 2.1 or later. - * See the COPYING.LIB file in the top-level directory. - * - */ - -#include "qapi/qapi-dealloc-visitor.h" -#include "%(prefix)sqapi-types.h" -#include "%(prefix)sqapi-visit.h" - -''', prefix=prefix)) - -fdecl.write(mcgen(''' -/* AUTOMATICALLY GENERATED, DO NOT MODIFY */ - -/* - * schema-defined QAPI types - * - * Copyright IBM, Corp. 2011 - * - * Authors: - * Anthony Liguori - * - * This work is licensed under the terms of the GNU LGPL, version 2.1 or later. - * See the COPYING.LIB file in the top-level directory. - * - */ - -#ifndef %(guard)s -#define %(guard)s - -#include "qapi/qapi-types-core.h" -''', - guard=guardname(h_file))) - -exprs = parse_schema(sys.stdin) - -for expr in exprs: - ret = "\n" - if expr.has_key('type'): - ret += generate_fwd_struct(expr['type'], expr['data']) - elif expr.has_key('enum'): - ret += generate_enum(expr['enum'], expr['data']) - fdef.write(generate_enum_lookup(expr['enum'], expr['data'])) - elif expr.has_key('union'): - ret += generate_fwd_struct(expr['union'], expr['data']) + "\n" - ret += generate_enum('%sKind' % expr['union'], expr['data'].keys()) - else: - continue - fdecl.write(ret) - -for expr in exprs: - ret = "\n" - if expr.has_key('type'): - ret += generate_struct(expr['type'], "", expr['data']) + "\n" - ret += generate_type_cleanup_decl(expr['type'] + "List") - fdef.write(generate_type_cleanup(expr['type'] + "List") + "\n") - ret += generate_type_cleanup_decl(expr['type']) - fdef.write(generate_type_cleanup(expr['type']) + "\n") - elif expr.has_key('union'): - ret += generate_union(expr['union'], expr['data']) - else: - continue - fdecl.write(ret) - -fdecl.write(''' -#endif -''') - -fdecl.flush() -fdecl.close() - -fdef.flush() -fdef.close() +if __name__ == '__main__': + try: + opts, args = getopt.gnu_getopt(sys.argv[1:], "p:o:", ["prefix=", "output-dir="]) + except getopt.GetoptError, err: + print str(err) + sys.exit(1) + + output_dir = "" + prefix = "" + c_file = 'qapi-types.c' + h_file = 'qapi-types.h' + + for o, a in opts: + if o in ("-p", "--prefix"): + prefix = a + elif o in ("-o", "--output-dir"): + output_dir = a + "/" + + c_file = output_dir + prefix + c_file + h_file = output_dir + prefix + h_file + + try: + os.makedirs(output_dir) + except os.error, e: + if e.errno != errno.EEXIST: + raise + + fdef = open(c_file, 'w') + fdecl = open(h_file, 'w') + + fdef.write(mcgen(''' + /* AUTOMATICALLY GENERATED, DO NOT MODIFY */ + + /* + * deallocation functions for schema-defined QAPI types + * + * Copyright IBM, Corp. 2011 + * + * Authors: + * Anthony Liguori + * Michael Roth + * + * This work is licensed under the terms of the GNU LGPL, version 2.1 or later. + * See the COPYING.LIB file in the top-level directory. + * + */ + + #include "qapi/qapi-dealloc-visitor.h" + #include "%(prefix)sqapi-types.h" + #include "%(prefix)sqapi-visit.h" + + ''', prefix=prefix)) + + fdecl.write(mcgen(''' + /* AUTOMATICALLY GENERATED, DO NOT MODIFY */ + + /* + * schema-defined QAPI types + * + * Copyright IBM, Corp. 2011 + * + * Authors: + * Anthony Liguori + * + * This work is licensed under the terms of the GNU LGPL, version 2.1 or later. + * See the COPYING.LIB file in the top-level directory. + * + */ + + #ifndef %(guard)s + #define %(guard)s + + #include "qapi/qapi-types-core.h" + ''', + guard=guardname(h_file))) + + exprs = parse_schema(sys.stdin) + + for expr in exprs: + ret = "\n" + if expr.has_key('type'): + ret += generate_fwd_struct(expr['type'], expr['data']) + elif expr.has_key('enum'): + ret += generate_enum(expr['enum'], expr['data']) + fdef.write(generate_enum_lookup(expr['enum'], expr['data'])) + elif expr.has_key('union'): + ret += generate_fwd_struct(expr['union'], expr['data']) + "\n" + ret += generate_enum('%sKind' % expr['union'], expr['data'].keys()) + else: + continue + fdecl.write(ret) + + for expr in exprs: + ret = "\n" + if expr.has_key('type'): + ret += generate_struct(expr['type'], "", expr['data']) + "\n" + ret += generate_type_cleanup_decl(expr['type'] + "List") + fdef.write(generate_type_cleanup(expr['type'] + "List") + "\n") + ret += generate_type_cleanup_decl(expr['type']) + fdef.write(generate_type_cleanup(expr['type']) + "\n") + elif expr.has_key('union'): + ret += generate_union(expr['union'], expr['data']) + else: + continue + fdecl.write(ret) + + fdecl.write(''' + #endif + ''') + + fdecl.flush() + fdecl.close() + + fdef.flush() + fdef.close()