All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] oeqa.utils.metadata: cope with invalid lines in os-release file
@ 2017-04-26 14:39 Markus Lehtonen
  2017-04-26 14:47 ` Joshua Lock
  0 siblings, 1 reply; 3+ messages in thread
From: Markus Lehtonen @ 2017-04-26 14:39 UTC (permalink / raw)
  To: openembedded-core

Don't crash if every line in /etc/os-release does not adhere to the
expected "key=val" format. E.g. CentOS 7 has empty lines in the file.

Signed-off-by: Markus Lehtonen <markus.lehtonen@linux.intel.com>
---
 meta/lib/oeqa/utils/metadata.py | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/meta/lib/oeqa/utils/metadata.py b/meta/lib/oeqa/utils/metadata.py
index cb81155e54..d291ddb960 100644
--- a/meta/lib/oeqa/utils/metadata.py
+++ b/meta/lib/oeqa/utils/metadata.py
@@ -20,8 +20,10 @@ def get_os_release():
         return None
     with open(os_release_file) as fobj:
         for line in fobj:
-            key, value = line.split('=', 1)
-            data[key.strip().lower()] = value.strip().strip('"')
+            split = line.split('=', 1)
+            if len(split) == 2:
+                key, value = split
+                data[key.strip().lower()] = value.strip().strip('"')
     return data
 
 def metadata_from_bb():
-- 
2.12.0



^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] oeqa.utils.metadata: cope with invalid lines in os-release file
  2017-04-26 14:39 [PATCH] oeqa.utils.metadata: cope with invalid lines in os-release file Markus Lehtonen
@ 2017-04-26 14:47 ` Joshua Lock
  2017-04-27  7:57   ` Markus Lehtonen
  0 siblings, 1 reply; 3+ messages in thread
From: Joshua Lock @ 2017-04-26 14:47 UTC (permalink / raw)
  To: Markus Lehtonen, openembedded-core

On Wed, 2017-04-26 at 17:39 +0300, Markus Lehtonen wrote:
> Don't crash if every line in /etc/os-release does not adhere to the
> expected "key=val" format. E.g. CentOS 7 has empty lines in the file.
> 
> Signed-off-by: Markus Lehtonen <markus.lehtonen@linux.intel.com>
> ---
>  meta/lib/oeqa/utils/metadata.py | 6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)
> 
> diff --git a/meta/lib/oeqa/utils/metadata.py
> b/meta/lib/oeqa/utils/metadata.py
> index cb81155e54..d291ddb960 100644
> --- a/meta/lib/oeqa/utils/metadata.py
> +++ b/meta/lib/oeqa/utils/metadata.py
> @@ -20,8 +20,10 @@ def get_os_release():
>          return None
>      with open(os_release_file) as fobj:
>          for line in fobj:
> -            key, value = line.split('=', 1)
> -            data[key.strip().lower()] = value.strip().strip('"')
> +            split = line.split('=', 1)
> +            if len(split) == 2:
> +                key, value = split
> +                data[key.strip().lower()] = value.strip().strip('"')

We have a function to read os-release in oe.lsb, return_dict_osr().

It handles this situation slightly differently, but the real reason I'm
pointing this out is that it seems like we could factor out a shared
function to be used both here and in oe.lsb ?

Joshua


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] oeqa.utils.metadata: cope with invalid lines in os-release file
  2017-04-26 14:47 ` Joshua Lock
@ 2017-04-27  7:57   ` Markus Lehtonen
  0 siblings, 0 replies; 3+ messages in thread
From: Markus Lehtonen @ 2017-04-27  7:57 UTC (permalink / raw)
  To: Joshua Lock, openembedded-core

On 26/04/2017, 17.47, "Joshua Lock" <joshua.g.lock@linux.intel.com> wrote:

    On Wed, 2017-04-26 at 17:39 +0300, Markus Lehtonen wrote:
    > Don't crash if every line in /etc/os-release does not adhere to the
    > expected "key=val" format. E.g. CentOS 7 has empty lines in the file.
    > 
    > Signed-off-by: Markus Lehtonen <markus.lehtonen@linux.intel.com>
    > ---
    >  meta/lib/oeqa/utils/metadata.py | 6 ++++--
    >  1 file changed, 4 insertions(+), 2 deletions(-)
    > 
    > diff --git a/meta/lib/oeqa/utils/metadata.py
    > b/meta/lib/oeqa/utils/metadata.py
    > index cb81155e54..d291ddb960 100644
    > --- a/meta/lib/oeqa/utils/metadata.py
    > +++ b/meta/lib/oeqa/utils/metadata.py
    > @@ -20,8 +20,10 @@ def get_os_release():
    >          return None
    >      with open(os_release_file) as fobj:
    >          for line in fobj:
    > -            key, value = line.split('=', 1)
    > -            data[key.strip().lower()] = value.strip().strip('"')
    > +            split = line.split('=', 1)
    > +            if len(split) == 2:
    > +                key, value = split
    > +                data[key.strip().lower()] = value.strip().strip('"')
    
    We have a function to read os-release in oe.lsb, return_dict_osr().
    
    It handles this situation slightly differently, but the real reason I'm
    pointing this out is that it seems like we could factor out a shared
    function to be used both here and in oe.lsb ?


Thanks for spotting this. Makes sense to me. I'll send a new patch merging the two functions shortly.

Thanks,
   Markus




^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2017-04-27  7:57 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-04-26 14:39 [PATCH] oeqa.utils.metadata: cope with invalid lines in os-release file Markus Lehtonen
2017-04-26 14:47 ` Joshua Lock
2017-04-27  7:57   ` Markus Lehtonen

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.