[{"id":3173,"web_url":"https://patchwork.libcamera.org/comment/3173/","msgid":"<20191204150126.GA7811@pendragon.ideasonboard.com>","date":"2019-12-04T15:01:26","subject":"Re: [libcamera-devel] [PATCH 02/10] libcamera: controls: Parse\n\t'values' in gen-controls.py","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"Hi Jacopo,\n\nThank you for the patch.\n\nOn Wed, Dec 04, 2019 at 02:20:58PM +0100, Jacopo Mondi wrote:\n> In preparation to add libcamera Camera definition by re-using the\n> control generation framework, augment the gen_controls.py script to\n> support parsing the 'values' yaml tag and generate documentation and\n> definition of possible values associated with a Control or a Property.\n> \n> Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>\n> ---\n>  src/libcamera/gen-controls.py | 35 +++++++++++++++++++++++++++++++++++\n>  1 file changed, 35 insertions(+)\n> \n> diff --git a/src/libcamera/gen-controls.py b/src/libcamera/gen-controls.py\n> index 940386cc68c8..ca843cb9b538 100755\n> --- a/src/libcamera/gen-controls.py\n> +++ b/src/libcamera/gen-controls.py\n> @@ -11,6 +11,24 @@ import string\n>  import sys\n>  import yaml\n>  \n> +class ValueGenerator:\n> +    doc_template = string.Template('''/**\n> + * \\\\def ${name}\n> + * \\\\brief ${description} */''')\n> +    def_template = string.Template('''#define ${name} ${value}''')\n> +\n> +    def __init__(self, value):\n> +        self.info = {\n> +            'name': value['name'],\n> +            'value': value['value'],\n> +            'description': value['description']\n> +        }\n> +\n> +    def generate_doc(self):\n> +        return self.doc_template.substitute(self.info)\n> +\n> +    def generate_def(self):\n> +        return self.def_template.substitute(self.info)\n\nI think it makes sense to introduce classes in this python script, but\nthis one seems a bit strange to me as it's really about calling the\nabove two methods. I would just move the related code to the single\ncallers below.\n\nI have more comments regarding the yaml format, but I'll reply to the\npatch that introduces property_ids.yaml for that, which I think will\ninfluence the code below.\n\n>  \n>  def snake_case(s):\n>      return ''.join([c.isupper() and ('_' + c) or c for c in s]).strip('_')\n> @@ -35,14 +53,23 @@ ${description}\n>          description[0] = '\\\\brief ' + description[0]\n>          description = '\\n'.join([(line and ' * ' or ' *') + line for line in description])\n>  \n> +        try:\n> +            values = ctrl['values']\n> +        except KeyError:\n> +            values = \"\"\n> +\n>          info = {\n>              'name': name,\n>              'type': ctrl['type'],\n>              'description': description,\n>              'id_name': id_name,\n> +            'values' : values,\n>          }\n>  \n> +        for v in values:\n> +            ctrls_doc.append(ValueGenerator(v).generate_doc())\n>          ctrls_doc.append(doc_template.substitute(info))\n> +\n>          ctrls_def.append(def_template.substitute(info))\n>          ctrls_map.append('\\t{ ' + id_name + ', &' + name + ' },')\n>  \n> @@ -66,11 +93,19 @@ def generate_h(controls):\n>  \n>          ids.append('\\t' + id_name + ' = ' + str(id_value) + ',')\n>  \n> +        try:\n> +            values = ctrl['values']\n> +        except KeyError:\n> +            values = \"\"\n> +\n>          info = {\n>              'name': name,\n>              'type': ctrl['type'],\n> +            'values' : values,\n>          }\n>  \n> +        for v in values:\n> +            ctrls.append(ValueGenerator(v).generate_def())\n>          ctrls.append(template.substitute(info))\n>          id_value += 1\n>","headers":{"Return-Path":"<laurent.pinchart@ideasonboard.com>","Received":["from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id BF60660BFF\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed,  4 Dec 2019 16:01:33 +0100 (CET)","from pendragon.ideasonboard.com (81-175-216-236.bb.dnainternet.fi\n\t[81.175.216.236])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 3BA912E5;\n\tWed,  4 Dec 2019 16:01:33 +0100 (CET)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1575471693;\n\tbh=S5LVNmB2B/raMhvqVnCFzH0Va0KVZ9g/JvjVf6lu6lk=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=TOxcyRGY5sT2yRZfYTQ4J4eLvTu4lqcyPSsS5hc4vGqvJP8O3UQkUTiKOBvId7xKs\n\tSk7M9b35pPqDvR6sTDxv6e4ftkAKfr99pvpooFpI9OX2bbnl8DUFghqwdvbslPiXjh\n\tYrf4jfTvmoF73Ac8h3+911CtKTlcIVfesAJ97/lE=","Date":"Wed, 4 Dec 2019 17:01:26 +0200","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"Jacopo Mondi <jacopo@jmondi.org>","Cc":"libcamera-devel@lists.libcamera.org","Message-ID":"<20191204150126.GA7811@pendragon.ideasonboard.com>","References":"<20191204132106.21582-1-jacopo@jmondi.org>\n\t<20191204132106.21582-3-jacopo@jmondi.org>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<20191204132106.21582-3-jacopo@jmondi.org>","User-Agent":"Mutt/1.10.1 (2018-07-13)","Subject":"Re: [libcamera-devel] [PATCH 02/10] libcamera: controls: Parse\n\t'values' in gen-controls.py","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","X-List-Received-Date":"Wed, 04 Dec 2019 15:01:33 -0000"}}]