public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Stefan Herbrechtsmeier <stefan.herbrechtsmeier-oss@weidmueller.com>
To: Quentin Schulz <foss+uboot@0leil.net>
Cc: sjg@chromium.org, alpernebiyasak@gmail.com,
	stefan.herbrechtsmeier@weidmueller.com, u-boot@lists.denx.de,
	Quentin Schulz <quentin.schulz@theobroma-systems.com>
Subject: Re: [PATCH v2 1/7] binman: bintool: move version check implementation into bintool class
Date: Thu, 1 Sep 2022 08:17:17 +0200	[thread overview]
Message-ID: <119a2cfc-834f-8e4a-bf29-e6208cd2e33f@weidmueller.com> (raw)
In-Reply-To: <20220831173936.150114-1-foss+uboot@0leil.net>

Hi Quentin,

Am 31.08.2022 um 19:39 schrieb Quentin Schulz:
> From: Quentin Schulz <quentin.schulz@theobroma-systems.com>
> 
> Version checking has nothing specific to compression/decompression tools
> so let's move it to the Bintool class.
> 
> Signed-off-by: Quentin Schulz <quentin.schulz@theobroma-systems.com>
> ---
> 
> added in v2
> 
>   tools/binman/bintool.py | 46 ++++++++++++++++++-----------------------
>   1 file changed, 20 insertions(+), 26 deletions(-)
> 
> diff --git a/tools/binman/bintool.py b/tools/binman/bintool.py
> index ec30ceff74..a156ffb550 100644
> --- a/tools/binman/bintool.py
> +++ b/tools/binman/bintool.py
> @@ -53,9 +53,10 @@ class Bintool:
>       # List of bintools to regard as missing
>       missing_list = []
>   
> -    def __init__(self, name, desc):
> +    def __init__(self, name, desc, version_regex=None):
>           self.name = name
>           self.desc = desc
> +        self.version_regex = version_regex
>   
>       @staticmethod
>       def find_bintool_class(btype):
> @@ -464,16 +465,27 @@ binaries. It is fairly easy to create new bintools. Just add a new file to the
>           print(f"No method to fetch bintool '{self.name}'")
>           return False
>   
> -    # pylint: disable=R0201
>       def version(self):
> -        """Version handler for a bintool
> -
> -        This should be implemented by the base class
> +        """Version handler
>   
>           Returns:
> -            str: Version string for this bintool
> +            str: Version number
>           """
> -        return 'unknown'
> +        if self.version_regex is None:
> +            return 'unknown'
> +
> +        import re
> +
> +        result = self.run_cmd_result('-V')
> +        out = result.stdout.strip()
> +        if not out:
> +            out = result.stderr.strip()
> +        if not out:
> +            return 'unknown'
> +
> +        m_version = re.search(self.version_regex, out)
> +        return m_version.group(1) if m_version else out
> +
>   
>   class BintoolPacker(Bintool):
>       """Tool which compression / decompression entry contents
> @@ -497,7 +509,7 @@ class BintoolPacker(Bintool):
>                    decompress_args=None, fetch_package=None,
>                    version_regex=r'(v[0-9.]+)'):
>           desc = '%s compression' % (compression if compression else name)
> -        super().__init__(name, desc)
> +        super().__init__(name, desc, version_regex)
>           if compress_args is None:
>               compress_args = ['--compress']
>           self.compress_args = compress_args

Please remove the redundant self.version_regex assignment at the bottom 
of this function.

> @@ -557,21 +569,3 @@ class BintoolPacker(Bintool):
>           if method != FETCH_BIN:
>               return None
>           return self.apt_install(self.fetch_package)
> -
> -    def version(self):
> -        """Version handler
> -
> -        Returns:
> -            str: Version number
> -        """
> -        import re
> -
> -        result = self.run_cmd_result('-V')
> -        out = result.stdout.strip()
> -        if not out:
> -            out = result.stderr.strip()
> -        if not out:
> -            return super().version()
> -
> -        m_version = re.search(self.version_regex, out)
> -        return m_version.group(1) if m_version else out

Regards
   Stefan

      parent reply	other threads:[~2022-09-01  6:17 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-31 17:39 [PATCH v2 1/7] binman: bintool: move version check implementation into bintool class Quentin Schulz
2022-08-31 17:39 ` [PATCH v2 2/7] binman: btool: lz4: use Bintool.version Quentin Schulz
2022-09-01  2:27   ` Simon Glass
2022-08-31 17:39 ` [PATCH v2 3/7] binman: btool: mkimage: " Quentin Schulz
2022-09-01  2:27   ` Simon Glass
2022-08-31 17:39 ` [PATCH v2 4/7] binman: bintool: parametrize parameter to pass to binary for returning version Quentin Schulz
2022-09-01  2:27   ` Simon Glass
2022-09-01  6:20     ` Stefan Herbrechtsmeier
2022-08-31 17:39 ` [PATCH v2 5/7] binman: btool: fiptool: use Bintool.version Quentin Schulz
2022-09-01  2:27   ` Simon Glass
2022-08-31 17:39 ` [PATCH v2 6/7] binman: btool: futility: " Quentin Schulz
2022-09-01  2:27   ` Simon Glass
2022-08-31 17:39 ` [PATCH v2 7/7] binman: bintool: bzip2: fix version function on non-Debian-based systems Quentin Schulz
2022-09-01  2:27   ` Simon Glass
2022-09-01  2:27 ` [PATCH v2 1/7] binman: bintool: move version check implementation into bintool class Simon Glass
2022-09-01  6:17 ` Stefan Herbrechtsmeier [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=119a2cfc-834f-8e4a-bf29-e6208cd2e33f@weidmueller.com \
    --to=stefan.herbrechtsmeier-oss@weidmueller.com \
    --cc=alpernebiyasak@gmail.com \
    --cc=foss+uboot@0leil.net \
    --cc=quentin.schulz@theobroma-systems.com \
    --cc=sjg@chromium.org \
    --cc=stefan.herbrechtsmeier@weidmueller.com \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox