From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56714) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZWlJT-0002Xa-GU for qemu-devel@nongnu.org; Tue, 01 Sep 2015 09:09:27 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZWlJO-0002Nl-Fb for qemu-devel@nongnu.org; Tue, 01 Sep 2015 09:09:23 -0400 Received: from mx1.redhat.com ([209.132.183.28]:45385) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZWlJO-0002N8-95 for qemu-devel@nongnu.org; Tue, 01 Sep 2015 09:09:18 -0400 From: Markus Armbruster References: <1438703896-12553-1-git-send-email-armbru@redhat.com> <1438703896-12553-31-git-send-email-armbru@redhat.com> <55C27001.1050307@redhat.com> <87pp31hr5i.fsf@blackfin.pond.sub.org> Date: Tue, 01 Sep 2015 15:09:13 +0200 In-Reply-To: <87pp31hr5i.fsf@blackfin.pond.sub.org> (Markus Armbruster's message of "Thu, 06 Aug 2015 08:23:05 +0200") Message-ID: <877foa9thi.fsf@blackfin.pond.sub.org> MIME-Version: 1.0 Content-Type: text/plain Subject: Re: [Qemu-devel] [PATCH RFC v3 30/32] qapi: New QMP command query-schema for QMP schema introspection List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Eric Blake Cc: kwolf@redhat.com, berto@igalia.com, qemu-devel@nongnu.org, mdroth@linux.vnet.ibm.com Markus Armbruster writes: > Eric Blake writes: > >> On 08/04/2015 09:58 AM, Markus Armbruster wrote: [...] >>> +++ b/qapi/introspect.json >> >>> +{ 'struct': 'SchemaInfoObject', >>> + 'data': { 'members': [ 'SchemaInfoObjectMember' ], >>> + '*tag': 'str', >>> + '*variants': [ 'SchemaInfoObjectVariant' ] } } >> >> I take it that either tag and variants will both be omitted, or both be >> present. No clean way to represent that in the schema, though. > > Needs a comment. Alternatively, wrap both tag and variants in an object, mandatory there, then make that object optional. Doesn't feel wortwhile to me, but if you like it better, I'll reconsider. [...] >>> +++ b/scripts/qapi-introspect.py >>> @@ -0,0 +1,172 @@ >>> +# >>> +# QAPI introspection generator >>> +# >>> +# Copyright (C) 2015 Red Hat, Inc. >>> +# >>> +# Authors: >>> +# Markus Armbruster >>> +# >>> +# This work is licensed under the terms of the GNU GPL, version 2. >>> +# See the COPYING file in the top-level directory. >>> + >>> +from qapi import * >>> + >>> +# Caveman's json.dumps() replacement (we're stuck at 2.4) >>> +# TODO try to use json.dumps() once we get unstuck >>> +def to_json(obj, level=0): >>> + if obj == None: >>> + ret = 'null' >>> + elif isinstance(obj, str): >>> + ret = '"' + obj.replace('"', r'\"') + '"' >>> + elif isinstance(obj, list): >>> + elts = [to_json(elt, level + 1) >>> + for elt in obj] >> >> No sorting here makes sense (the json-to-string converter can't know >> whether we are using arrays as sets, vs. in the usual JSON semantics of >> order-preserving). Thus, if we intend to sort things like enum values >> or object members by name, that sorting has to be done prior to feeding >> it to this pretty-printer. > > Correct. I didn't, because I ran out of time. > >>> + ret = '[' + ', '.join(elts) + ' ]' >> >> Here's where I was wondering if you want '[ '. > > Yes. I'll consistently drop the spaces, to match Python's conventions. [...] >>> + 'variants': [self._gen_variant(v) for v in variants] } >> >> Do you want to add a sort() on variant 'case's here? >> >>> + >>> + def visit_enum_type(self, name, info, values): >>> + self._gen_json(name, 'enum', { 'values': values }) >> >> Do you want to add a sort() on values here? > > I want to review the introspection schema systematically for sorting > opportunities. I'm going to leave this job for later, because I feel we should get the basics in as soon as possible. We then have the rest of the development cycle to refine stuff. [...]