From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35726) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZJrzX-00024X-CM for qemu-devel@nongnu.org; Mon, 27 Jul 2015 19:39:32 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZJrzT-0003rC-9m for qemu-devel@nongnu.org; Mon, 27 Jul 2015 19:39:31 -0400 Received: from mx3-phx2.redhat.com ([209.132.183.24]:59045) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZJrzT-0003qx-1w for qemu-devel@nongnu.org; Mon, 27 Jul 2015 19:39:27 -0400 Date: Mon, 27 Jul 2015 19:39:20 -0400 (EDT) From: =?utf-8?Q?Marc-Andr=C3=A9?= Lureau Message-ID: <1907049170.980383.1438040360564.JavaMail.zimbra@redhat.com> In-Reply-To: <55B6B15D.2080709@redhat.com> References: <1435917064-17827-1-git-send-email-marcandre.lureau@redhat.com> <1435917064-17827-4-git-send-email-marcandre.lureau@redhat.com> <55B6B15D.2080709@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [PATCH 3/5] qapi: add qapi2texi script List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Eric Blake Cc: mdroth@linux.vnet.ibm.com, =?utf-8?Q?Marc-Andr=C3=A9?= Lureau , =?utf-8?Q?Marc-Andr=C3=A9?= Lureau , qemu-devel@nongnu.org, armbru@redhat.com Hi ----- Original Message ----- > On 07/03/2015 03:51 AM, Marc-Andr=C3=A9 Lureau wrote: > > From: Marc-Andr=C3=A9 Lureau > >=20 > > As the name suggests, the qapi2texi script converts JSON QAPI > > description into a standalone texi file suitable for different target > > formats. > >=20 > > As the documentation format doesn't seem to be specified, it parses the > > following blocks before each declaration with some variations: >=20 > docs/qapi-code-gen.txt tried to give a sample documentation. Feel free > to formalize that, and to fix non-conforming uses, if you desire. It'll > be a big one-time audit of the .json files, but getting things > consistent, _and keeping them that way by automatic conformance checks > in your conversion tool_, is fine by me. Thanks, the patch series evolved quite a bit since this first series. The current branch is: https://github.com/elmarco/qemu/commits/qapi And I found about that doc, so I removed that comment in commit message. =20 > >=20 > > ## > > # @symbol > > # > > # body > > # > > # @arg: foo > > # @arg: #optional foo > > # > > # Returns: returns > > # Since: version > > # Notes: notes > > ## > >=20 > > Using the json declaration, it's able to give extra information about > > the type of arguments and return value expected. > >=20 > > Signed-off-by: Marc-Andr=C3=A9 Lureau > > --- > > scripts/qapi.py | 78 ++++++++++++++++++- > > scripts/qapi2texi.py | 212 > > +++++++++++++++++++++++++++++++++++++++++++++++++++ > > 2 files changed, 286 insertions(+), 4 deletions(-) > > create mode 100644 scripts/qapi2texi.py >=20 > Are you intending to apply this after Markus' big work on QMP Introspecti= on? Yes, I am in contact with Markus, I propose we revisit this series after hi= s patches are merged. Thanks for your comments so far,=20 > >=20 > > diff --git a/scripts/qapi.py b/scripts/qapi.py > > index 06d7fc2..70208e8 100644 > > --- a/scripts/qapi.py > > +++ b/scripts/qapi.py > > @@ -103,6 +103,53 @@ class QAPIExprError(Exception): > > return error_path(self.info['parent']) + \ > > "%s:%d: %s" % (self.info['file'], self.info['line'], self.= msg) > > =20 > > +class QAPIDoc: >=20 > In particular, this should probably be QAPIDoc(object) (new style class > declaration). I just run pep8 fine on my file, I don't know about that new syntax. >=20 > > @@ -762,6 +823,15 @@ def parse_schema(fname): > > print >>sys.stderr, e > > exit(1) > > =20 > > +def parse_schema_full(fname): > > + try: > > + schema =3D QAPISchema(open(fname, "r")) > > + check_exprs(schema.exprs) > > + return schema.exprs > > + except (QAPISchemaError, QAPIExprError), e: > > + print >>sys.stderr, e > > + exit(1) >=20 > and this may need to be reworked on top of Markus' new parser class. >=20 > > +++ b/scripts/qapi2texi.py > > @@ -0,0 +1,212 @@ > > +# QAPI texi generator > > +# > > +# This work is licensed under the terms of the GNU GPL, version 2. > > +# See the COPYING file in the top-level directory. >=20 > Although I'm not a lawyer, my understanding is that for GPL to apply, > there has to be an explicit mention of Copyright. >=20 ah ok, I'll add it then > > +exprs =3D parse_schema_full(sys.argv[4]) >=20 > And you'll probably want to rewrite this in terms of the visitor interfac= e. >=20 > > +for cmd in exprs: > > + expr =3D cmd['expr'] > > + docs =3D cmd['info']['doc'] > > + (kind, name) =3D expr.items()[0] > > + > > + for d in docs[0:-1]: > > + print d.comment > > + > > + texi =3D {"command": texi_command, > > + "struct": texi_struct, > > + "enum": texi_enum, > > + "union": texi_union, > > + "alternate": texi_alternate, > > + "event": texi_event} > > + try: > > + texi[kind](expr, docs[-1]) > > + except KeyError: > > + raise ValueError("Unknown expression kind '%s'" % kind) >=20 > although this is a rather cute way to polymorphically invoke the correct > helper function. >=20 > -- > Eric Blake eblake redhat com +1-919-301-3266 > Libvirt virtualization library http://libvirt.org >=20 >=20