From: Luiz Capitulino <lcapitulino@redhat.com>
To: mdroth@linux.vnet.ibm.com
Cc: aliguori@us.ibm.com, qemu-devel@nongnu.org
Subject: [Qemu-devel] [PATCH 1/4] qapi-types.py: Add a main() like function
Date: Mon, 17 Oct 2011 13:29:34 -0200 [thread overview]
Message-ID: <1318865377-3328-2-git-send-email-lcapitulino@redhat.com> (raw)
In-Reply-To: <1318865377-3328-1-git-send-email-lcapitulino@redhat.com>
Makes it easier to read the code.
Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
---
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 <aliguori@us.ibm.com>
- * Michael Roth <mdroth@linux.vnet.ibm.com>
- *
- * 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 <aliguori@us.ibm.com>
- *
- * 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 <aliguori@us.ibm.com>
+ * Michael Roth <mdroth@linux.vnet.ibm.com>
+ *
+ * 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 <aliguori@us.ibm.com>
+ *
+ * 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()
--
1.7.7.rc3
next prev parent reply other threads:[~2011-10-17 15:30 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-10-17 15:29 [Qemu-devel] [PATCH v1 0/4]: QAPI: Small fixes for qapi-types.py Luiz Capitulino
2011-10-17 15:29 ` Luiz Capitulino [this message]
2011-10-17 21:19 ` [Qemu-devel] [PATCH 1/4] qapi-types.py: Add a main() like function Michael Roth
2011-10-17 15:29 ` [Qemu-devel] [PATCH 2/4] qapi-types.py: Don't build paths by hand Luiz Capitulino
2011-10-17 21:20 ` Michael Roth
2011-10-17 15:29 ` [Qemu-devel] [PATCH 3/4] qapi-types.py: Fail gracefully if out dir is not specified Luiz Capitulino
2011-10-17 21:27 ` Michael Roth
2011-10-18 12:31 ` Luiz Capitulino
2011-10-17 15:29 ` [Qemu-devel] [PATCH 4/4] qapi-types.py: Drop unused variable Luiz Capitulino
2011-10-17 21:29 ` Michael Roth
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1318865377-3328-2-git-send-email-lcapitulino@redhat.com \
--to=lcapitulino@redhat.com \
--cc=aliguori@us.ibm.com \
--cc=mdroth@linux.vnet.ibm.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).