[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [PATCH RFC 07/21] qapi: Move parse_command_line() next
From: |
Marc-Andre Lureau |
Subject: |
Re: [Qemu-devel] [PATCH RFC 07/21] qapi: Move parse_command_line() next to its only use |
Date: |
Mon, 5 Feb 2018 14:45:01 +0100 |
On Fri, Feb 2, 2018 at 2:03 PM, Markus Armbruster <address@hidden> wrote:
> Signed-off-by: Markus Armbruster <address@hidden>
Reviewed-by: Marc-André Lureau <address@hidden>
> ---
> scripts/qapi-gen.py | 52 +++++++++++++++++++++++++++++++++++++++++++++++-
> scripts/qapi/common.py | 54
> --------------------------------------------------
> 2 files changed, 51 insertions(+), 55 deletions(-)
>
> diff --git a/scripts/qapi-gen.py b/scripts/qapi-gen.py
> index 575c938a1b..6302fd0d55 100755
> --- a/scripts/qapi-gen.py
> +++ b/scripts/qapi-gen.py
> @@ -4,8 +4,10 @@
> # This work is licensed under the terms of the GNU GPL, version 2 or later.
> # See the COPYING file in the top-level directory.
>
> +import getopt
> +import re
> import sys
> -from qapi.common import parse_command_line, QAPISchema
> +from qapi.common import QAPISchema
> from qapi.types import gen_types
> from qapi.visit import gen_visit
> from qapi.commands import gen_commands
> @@ -14,6 +16,54 @@ from qapi.introspect import gen_introspect
> from qapi.doc import gen_doc
>
>
> +def parse_command_line(extra_options='', extra_long_options=[]):
> +
> + try:
> + opts, args = getopt.gnu_getopt(sys.argv[1:],
> + 'chp:o:' + extra_options,
> + ['source', 'header', 'prefix=',
> + 'output-dir='] + extra_long_options)
> + except getopt.GetoptError as err:
> + print >>sys.stderr, "%s: %s" % (sys.argv[0], str(err))
> + sys.exit(1)
> +
> + output_dir = ''
> + prefix = ''
> + do_c = False
> + do_h = False
> + extra_opts = []
> +
> + for oa in opts:
> + o, a = oa
> + if o in ('-p', '--prefix'):
> + match = re.match(r'([A-Za-z_.-][A-Za-z0-9_.-]*)?', a)
> + if match.end() != len(a):
> + print >>sys.stderr, \
> + "%s: 'funny character '%s' in argument of --prefix" \
> + % (sys.argv[0], a[match.end()])
> + sys.exit(1)
> + prefix = a
> + elif o in ('-o', '--output-dir'):
> + output_dir = a + '/'
> + elif o in ('-c', '--source'):
> + do_c = True
> + elif o in ('-h', '--header'):
> + do_h = True
> + else:
> + extra_opts.append(oa)
> +
> + if not do_c and not do_h:
> + do_c = True
> + do_h = True
> +
> + if len(args) != 1:
> + print >>sys.stderr, "%s: need exactly one argument" % sys.argv[0]
> + sys.exit(1)
> + fname = args[0]
> +
> + return (fname, output_dir, do_c, do_h, prefix, extra_opts)
> +
> +
> def main(argv):
> (input_file, output_dir, do_c, do_h, prefix, opts) = \
> parse_command_line('bu', ['builtins', 'unmask-non-abi-names'])
> diff --git a/scripts/qapi/common.py b/scripts/qapi/common.py
> index d73ef618e2..cfa2671ca3 100644
> --- a/scripts/qapi/common.py
> +++ b/scripts/qapi/common.py
> @@ -12,7 +12,6 @@
> # See the COPYING file in the top-level directory.
>
> import errno
> -import getopt
> import os
> import re
> import string
> @@ -1917,59 +1916,6 @@ def build_params(arg_type, boxed, extra):
>
>
> #
> -# Common command line parsing
> -#
> -
> -
> -def parse_command_line(extra_options='', extra_long_options=[]):
> -
> - try:
> - opts, args = getopt.gnu_getopt(sys.argv[1:],
> - 'chp:o:' + extra_options,
> - ['source', 'header', 'prefix=',
> - 'output-dir='] + extra_long_options)
> - except getopt.GetoptError as err:
> - print >>sys.stderr, "%s: %s" % (sys.argv[0], str(err))
> - sys.exit(1)
> -
> - output_dir = ''
> - prefix = ''
> - do_c = False
> - do_h = False
> - extra_opts = []
> -
> - for oa in opts:
> - o, a = oa
> - if o in ('-p', '--prefix'):
> - match = re.match(r'([A-Za-z_.-][A-Za-z0-9_.-]*)?', a)
> - if match.end() != len(a):
> - print >>sys.stderr, \
> - "%s: 'funny character '%s' in argument of --prefix" \
> - % (sys.argv[0], a[match.end()])
> - sys.exit(1)
> - prefix = a
> - elif o in ('-o', '--output-dir'):
> - output_dir = a + '/'
> - elif o in ('-c', '--source'):
> - do_c = True
> - elif o in ('-h', '--header'):
> - do_h = True
> - else:
> - extra_opts.append(oa)
> -
> - if not do_c and not do_h:
> - do_c = True
> - do_h = True
> -
> - if len(args) != 1:
> - print >>sys.stderr, "%s: need exactly one argument" % sys.argv[0]
> - sys.exit(1)
> - fname = args[0]
> -
> - return (fname, output_dir, do_c, do_h, prefix, extra_opts)
> -
> -
> -#
> # Accumulate and write output
> #
>
> --
> 2.13.6
>
- [Qemu-devel] [PATCH RFC 13/21] qapi: Record 'include' directives in parse tree, (continued)
- [Qemu-devel] [PATCH RFC 13/21] qapi: Record 'include' directives in parse tree, Markus Armbruster, 2018/02/02
- [Qemu-devel] [PATCH RFC 02/21] qapi: Generate up-to-date copyright notice, Markus Armbruster, 2018/02/02
- [Qemu-devel] [PATCH RFC 07/21] qapi: Move parse_command_line() next to its only use, Markus Armbruster, 2018/02/02
- [Qemu-devel] [PATCH RFC 19/21] qapi/types: Generate separate .h, .c for each module, Markus Armbruster, 2018/02/02
- [Qemu-devel] [PATCH RFC 01/21] qapi: Streamline boilerplate comment generation, Markus Armbruster, 2018/02/02
- [Qemu-devel] [PATCH RFC 11/21] qapi: Lift error reporting from QAPISchema.__init__() to callers, Markus Armbruster, 2018/02/02
- [Qemu-devel] [PATCH RFC 21/21] qapi: Empty out qapi-schema.json, Markus Armbruster, 2018/02/02