: QAPI: Small fixes for qapi-types.py
PATCH 3/4 qapi-types.py: Fail gracefully if out dir is not specified
In reply to Luiz CapitulinoOtherwise we get:
Traceback (most recent call last):
File "./scripts/qapi-types.py", line 183, in <module>
os.makedirs(output_dir)
File "/usr/lib64/python2.7/os.py", line 157, in makedirs
mkdir(name, mode)
OSError: [Errno 2] No such file or directory: ''--- scripts/qapi-types.py | 6 +++++- 1 files changed, 5 insertions(+), 1 deletions(-)
scripts/qapi-types.py +5 -1
@@ -178,7 +178,11 @@ if __name__ == '__main__': prefix = a elif o in ("-o", "--output-dir"): output_dir = a - + + if not output_dir: + sys.stdout.write("ouput directory was not specified\n") + sys.exit(1) + c_file = os.path.join(output_dir, prefix + c_file) h_file = os.path.join(output_dir, prefix + h_file)
Signature · 1 line
1.7.7.rc3
PATCH 2/4 qapi-types.py: Don't build paths by hand
In reply to Luiz CapitulinoUse os.path.join() instead.
--- scripts/qapi-types.py | 6 +++--- 1 files changed, 3 insertions(+), 3 deletions(-)
scripts/qapi-types.py +3 -3
@@ -177,10 +177,10 @@ if __name__ == '__main__': if o in ("-p", "--prefix"): prefix = a elif o in ("-o", "--output-dir"): - output_dir = a + "/" + output_dir = a - c_file = output_dir + prefix + c_file - h_file = output_dir + prefix + h_file + c_file = os.path.join(output_dir, prefix + c_file) + h_file = os.path.join(output_dir, prefix + h_file) try: os.makedirs(output_dir)
Signature · 1 line
1.7.7.rc3
PATCH 1/4 qapi-types.py: Add a main() like function
In reply to Luiz CapitulinoMakes it easier to read the code.
--- scripts/qapi-types.py | 230 ++++++++++++++++++++++++------------------------ 1 files changed, 115 insertions(+), 115 deletions(-)
scripts/qapi-types.py +115 -115
@@ -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 <[email protected]> - * Michael Roth <[email protected]> - * - * 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 <[email protected]> - * - * 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 <[email protected]> + * Michael Roth <[email protected]> + * + * 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 <[email protected]> + * + * 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()
Signature · 1 line
1.7.7.rc3
cover : QAPI: Small fixes for qapi-types.py
Details in the patches.
scripts/qapi-types.py | 233 +++++++++++++++++++++++++------------------------ 1 files changed, 118 insertions(+), 115 deletions(-)
PATCH 4/4 qapi-types.py: Drop unused variable
--- scripts/qapi-types.py | 1 - 1 files changed, 0 insertions(+), 1 deletions(-)
scripts/qapi-types.py +0 -1
@@ -65,7 +65,6 @@ def generate_enum_lookup(name, values): const char *%(name)s_lookup[] = { ''', name=name) - i = 0 for value in values: ret += mcgen(''' "%(value)s",
Signature · 1 line
1.7.7.rc3
Re: [Qemu-devel] [PATCH 1/4] qapi-types.py: Add a main() like function
In reply to Luiz CapitulinoQuoted 248 lines · Luiz Capitulino
Makes it easier to read the code.
Signed-off-by Luiz Capitulino <[email protected]>--- scripts/qapi-types.py | 230 ++++++++++++++++++++++++------------------------ 1 files changed, 115 insertions(+), 115 deletions(-)scripts/qapi-types.py +115
-115@@ -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 <[email protected]> - * Michael Roth <[email protected]> - * - * 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 <[email protected]> - * - * 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 <[email protected]> + * Michael Roth <[email protected]> + * + * 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 <[email protected]> + * + * 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()Signature · 1 line
1.7.7.rc3
Signature · 3 lines
Sincerely, Mike Roth IBM Linux Technology Center
Re: [Qemu-devel] [PATCH 2/4] qapi-types.py: Don't build paths by hand
In reply to Luiz CapitulinoQuoted 28 lines · Luiz Capitulino
Use
os.path.join()instead.Signed-off-by Luiz Capitulino <[email protected]>--- scripts/qapi-types.py | 6 +++--- 1 files changed, 3 insertions(+), 3 deletions(-)scripts/qapi-types.py +3
-3@@ -177,10 +177,10 @@ if __name__ == '__main__': if o in ("-p", "--prefix"): prefix = a elif o in ("-o", "--output-dir"): - output_dir = a + "/" + output_dir = a - c_file = output_dir + prefix + c_file - h_file = output_dir + prefix + h_file + c_file = os.path.join(output_dir, prefix + c_file) + h_file = os.path.join(output_dir, prefix + h_file) try: os.makedirs(output_dir)Signature · 1 line
1.7.7.rc3
Signature · 3 lines
Sincerely, Mike Roth IBM Linux Technology Center
Re: [Qemu-devel] [PATCH 3/4] qapi-types.py: Fail gracefully if out dir is not specified
In reply to Luiz CapitulinoQuoted 19 lines · Luiz Capitulino
Otherwise we get:
Traceback (most recent call last):
File "./scripts/qapi-types.py", line 183, in <module> os.makedirs(output_dir) File "/usr/lib64/python2.7/os.py", line 157, in makedirs mkdir(name, mode) OSError: [Errno 2] No such file or directory: ''Signed-off-by Luiz Capitulino <[email protected]>--- scripts/qapi-types.py | 6 +++++- 1 files changed, 5 insertions(+), 1 deletions(-)scripts/qapi-types.py +0
-0
scripts/qapi-types.py if __name__ == '__main__': · line 185
Quoted 9 lines
scripts/qapi-types.py +5
-1@@ -178,7 +178,11 @@ if __name__ == '__main__': prefix = a elif o in ("-o", "--output-dir"): output_dir = a - + + if not output_dir: + sys.stdout.write("ouput directory was not specified\n") + sys.exit(1) +
We should probably just set output_dir to os.getcwd() here.
Quoted 6 lines
scripts/qapi-types.py +0
-0c_file = os.path.join(output_dir, prefix + c_file) h_file = os.path.join(output_dir, prefix + h_file)Signature · 1 line
1.7.7.rc3
Signature · 3 lines
Sincerely, Mike Roth IBM Linux Technology Center
Re: [Qemu-devel] [PATCH 4/4] qapi-types.py: Drop unused variable
In reply to Luiz CapitulinoQuoted 20 lines · Luiz Capitulino
Signed-off-by Luiz Capitulino <[email protected]>--- scripts/qapi-types.py | 1 - 1 files changed, 0 insertions(+), 1 deletions(-)scripts/qapi-types.py +0
-1@@ -65,7 +65,6 @@ def generate_enum_lookup(name, values): const char *%(name)s_lookup[] = { ''', name=name) - i = 0 for value in values: ret += mcgen(''' "%(value)s",Signature · 1 line
1.7.7.rc3
Signature · 3 lines
Sincerely, Mike Roth IBM Linux Technology Center
Re: [Qemu-devel] [PATCH 3/4] qapi-types.py: Fail gracefully if out dir is not specified
In reply to Michael RothQuoted 15 lines · On Mon, 17 Oct 2011 16:27:34 -0500 Michael Roth <[email protected]>…
Quoted 14 lines · Luiz Capitulino
Otherwise we get:
Traceback (most recent call last):
File "./scripts/qapi-types.py", line 183, in <module> os.makedirs(output_dir) File "/usr/lib64/python2.7/os.py", line 157, in makedirs mkdir(name, mode) OSError: [Errno 2] No such file or directory: ''Signed-off-by Luiz Capitulino <[email protected]>--- scripts/qapi-types.py | 6 +++++- 1 files changed, 5 insertions(+), 1 deletions(-)
Quoted 16 lines
Quoted 5 lines
scripts/qapi-types.py +0
-0scripts/qapi-types.py if __name__ == '__main__': · line 185
Quoted 9 lines
scripts/qapi-types.py +5
-1@@ -178,7 +178,11 @@ if __name__ == '__main__': prefix = a elif o in ("-o", "--output-dir"): output_dir = a - + + if not output_dir: + sys.stdout.write("ouput directory was not specified\n") + sys.exit(1) +We should probably just set
output_dirtoos.getcwd()here.
Fair enough.
Quoted 8 lines
Quoted 7 lines
scripts/qapi-types.py +0
-0c_file = os.path.join(output_dir, prefix + c_file) h_file = os.path.join(output_dir, prefix + h_file)Signature · 1 line
1.7.7.rc3