From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50209) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZJqwJ-0003fd-GJ for qemu-devel@nongnu.org; Mon, 27 Jul 2015 18:32:08 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZJqwF-0002GE-Iy for qemu-devel@nongnu.org; Mon, 27 Jul 2015 18:32:07 -0400 Received: from mx1.redhat.com ([209.132.183.28]:41523) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZJqwF-0002Fo-Bd for qemu-devel@nongnu.org; Mon, 27 Jul 2015 18:32:03 -0400 References: <1435917064-17827-1-git-send-email-marcandre.lureau@redhat.com> <1435917064-17827-4-git-send-email-marcandre.lureau@redhat.com> From: Eric Blake Message-ID: <55B6B15D.2080709@redhat.com> Date: Mon, 27 Jul 2015 16:31:57 -0600 MIME-Version: 1.0 In-Reply-To: <1435917064-17827-4-git-send-email-marcandre.lureau@redhat.com> Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="4FJkJT9D4AF9DPPu5FjTim9NvmwEMcUsg" Subject: Re: [Qemu-devel] [PATCH 3/5] qapi: add qapi2texi script List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: =?UTF-8?Q?Marc-Andr=c3=a9_Lureau?= , qemu-devel@nongnu.org Cc: =?UTF-8?Q?Marc-Andr=c3=a9_Lureau?= , armbru@redhat.com, mdroth@linux.vnet.ibm.com This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --4FJkJT9D4AF9DPPu5FjTim9NvmwEMcUsg Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable 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: 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. >=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 Are you intending to apply this after Markus' big work on QMP Introspecti= on? >=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: In particular, this should probably be QAPIDoc(object) (new style class declaration). > @@ -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) and this may need to be reworked on top of Markus' new parser class. > +++ 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. Although I'm not a lawyer, my understanding is that for GPL to apply, there has to be an explicit mention of Copyright. > +exprs =3D parse_schema_full(sys.argv[4]) And you'll probably want to rewrite this in terms of the visitor interfac= e. > +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) 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 --4FJkJT9D4AF9DPPu5FjTim9NvmwEMcUsg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 Comment: Public key at http://people.redhat.com/eblake/eblake.gpg Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/ iQEcBAEBCAAGBQJVtrFdAAoJEKeha0olJ0Nqj2QIAIlvSOT+lxTXos432cDAtM2t rh+1VmjhHxn4FlXWcVUwBRsrpjAQZcBvRY+zpoqWpV5CBp4MUBjcWVd5J5N9bgsk kE6kxsU04DfPK1DHPX8Xe8TzJgEk00Z+ERhshlVrDG7QfJ3Hw1Q0IJFtWLaHTV8w XSKKF356Uq5ue1RZIqQtBU8Rn2VwcOaYfc/WEL340O2EgRs+ZFiTDw1ac47/oGQx GR4W4VmmI6VENDYYdXoWlB3p+0i2M/3YY2IX16XS+5RNW2UptuxYdA0mEzGxRcoi DZZImWNl4M8PXO8oxx5zfhiolbVg7uQJqt5/dTSZC6w8MVxLJGejH2DP4pM+9DQ= =hkwU -----END PGP SIGNATURE----- --4FJkJT9D4AF9DPPu5FjTim9NvmwEMcUsg--