[{"id":30313,"web_url":"https://patchwork.libcamera.org/comment/30313/","msgid":"<20240704102419.GC6230@pendragon.ideasonboard.com>","date":"2024-07-04T10:24:19","subject":"Re: [PATCH v3 09/23] libtuning: Improve filename parsing","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"Hi Stefan,\n\nThank you for the patch.\n\nOn Wed, Jul 03, 2024 at 04:16:58PM +0200, Stefan Klug wrote:\n> In the tuning datasets, the files had names like\n> 'imx335_1600l_3000k_1.dng'. That failed on the old filename parsing\n> function. As there is no need to dictate the order of the tags, split\n> the big regex into chunks and parse them one by one. This also makes\n> the code easier to digest.\n> \n> Signed-off-by: Stefan Klug <stefan.klug@ideasonboard.com>\n> Reviewed-by: Paul Elder <paul.elder@ideasonboard.com>\n\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\n> ---\n>  utils/tuning/libtuning/utils.py | 30 ++++++++++++++++++++++--------\n>  1 file changed, 22 insertions(+), 8 deletions(-)\n> \n> diff --git a/utils/tuning/libtuning/utils.py b/utils/tuning/libtuning/utils.py\n> index 90fd7072a0fd..c70dfae049bc 100644\n> --- a/utils/tuning/libtuning/utils.py\n> +++ b/utils/tuning/libtuning/utils.py\n> @@ -43,16 +43,30 @@ def _list_image_files(directory):\n>  \n>  \n>  def _parse_image_filename(fn: Path):\n> -    result = re.search(r'^(alsc_)?(\\d+)[kK]_(\\d+)?[lLuU]?.\\w{3,4}$', fn.name)\n> -    if result is None:\n> -        logger.error(f'The file name of {fn.name} is incorrectly formatted')\n> -        return None, None, None\n> +    lsc_only = False\n> +    color_temperature = None\n> +    lux = None\n> +\n> +    parts = fn.stem.split('_')\n> +    for part in parts:\n> +        if part == 'alsc':\n> +            lsc_only = True\n> +            continue\n> +        r = re.match(r'(\\d+)[kK]', part)\n> +        if r:\n> +            color_temperature = int(r.group(1))\n> +            continue\n> +        r = re.match(r'(\\d+)[lLuU]', part)\n> +        if r:\n> +            lux = int(r.group(1))\n> +\n> +    if color_temperature is None:\n> +        logger.error(f'The file name of \"{fn.name}\" does not contain a color temperature')\n>  \n> -    color = int(result.group(2))\n> -    lsc_only = result.group(1) is not None\n> -    lux = None if lsc_only else int(result.group(3))\n> +    if lux is None and lsc_only is False:\n> +        logger.error(f'The file name of \"{fn.name}\" must either contain alsc or a lux level')\n>  \n> -    return color, lux, lsc_only\n> +    return color_temperature, lux, lsc_only\n>  \n>  \n>  # \\todo Implement this from check_imgs() in ctt.py","headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id 7B1E3BD87C\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu,  4 Jul 2024 10:24:42 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 3468362E24;\n\tThu,  4 Jul 2024 12:24:42 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id CCE31619C8\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu,  4 Jul 2024 12:24:40 +0200 (CEST)","from pendragon.ideasonboard.com\n\t(117.145-247-81.adsl-dyn.isp.belgacom.be [81.247.145.117])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 11EB8502;\n\tThu,  4 Jul 2024 12:24:12 +0200 (CEST)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"lFYTRYnM\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1720088652;\n\tbh=61b7VkbXV3uMST95H4CfypEgBU/Sqolu9ySrXDGV8ls=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=lFYTRYnMGwCzq+hrWGCrPjqulv/497rHOI/AneVfguuGNc/Crl9Dno9lrs1kKkp6h\n\tCCmm+H186woaiDYAVcXZMzP1JflVbpTDwsRZjVZuY0nQiIRUh8lkLXFYb9i1JFDd0o\n\tJI1H3SpKnrvDdaBLbiSdtKHShH3tzVXqpiEukhRU=","Date":"Thu, 4 Jul 2024 13:24:19 +0300","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"Stefan Klug <stefan.klug@ideasonboard.com>","Cc":"libcamera-devel@lists.libcamera.org,\n\tPaul Elder <paul.elder@ideasonboard.com>","Subject":"Re: [PATCH v3 09/23] libtuning: Improve filename parsing","Message-ID":"<20240704102419.GC6230@pendragon.ideasonboard.com>","References":"<20240703141726.252368-1-stefan.klug@ideasonboard.com>\n\t<20240703141726.252368-10-stefan.klug@ideasonboard.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<20240703141726.252368-10-stefan.klug@ideasonboard.com>","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>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}}]