SELinux Security Module development
 help / color / mirror / Atom feed
From: Petr Lautrbach <lautrbach@redhat.com>
To: Jeffery To <jeffery.to@gmail.com>, selinux@vger.kernel.org
Subject: Re: [PATCH] python/sepolicy: Fix get_os_version except clause
Date: Fri, 30 Jun 2023 14:29:51 +0200	[thread overview]
Message-ID: <87sfa9yvy8.fsf@redhat.com> (raw)
In-Reply-To: <87fs6a1f3p.fsf@redhat.com>

Petr Lautrbach <lautrbach@redhat.com> writes:

> Jeffery To <jeffery.to@gmail.com> writes:
>
>> This adds more exceptions to be handled by the except clause in
>> `get_os_version()`:
>>
>> * If the `distro` package is not installed, then `import distro` raises
>>   a `ModuleNotFoundError` exception.
>>
>> * The distro documentation[1] lists `OSError` and `UnicodeError` as
>>   exceptions that can be raised.
>>
>> * Older versions of distro (<= 1.6.0) may also raise
>>   `subprocessCalledProcessError`[2].
>>
>> [1]: https://github.com/python-distro/distro/blob/v1.8.0/src/distro/distro.py#L749-L753
>> [2]: https://github.com/python-distro/distro/blob/v1.6.0/distro.py#L726-L728
>>
>> Signed-off-by: Jeffery To <jeffery.to@gmail.com>
>
> Acked-by: Petr Lautrbach <lautrbach@redhat.com>

merged, thanks!


>> ---
>>  python/sepolicy/sepolicy/__init__.py | 3 ++-
>>  1 file changed, 2 insertions(+), 1 deletion(-)
>>
>> diff --git a/python/sepolicy/sepolicy/__init__.py b/python/sepolicy/sepolicy/__init__.py
>> index c177cdfc529d..2d526c94a0c5 100644
>> --- a/python/sepolicy/sepolicy/__init__.py
>> +++ b/python/sepolicy/sepolicy/__init__.py
>> @@ -1240,11 +1240,12 @@ def boolean_desc(boolean):
>>  
>>  
>>  def get_os_version():
>> +    import subprocess
>>      system_release = ""
>>      try:
>>          import distro
>>          system_release = distro.name(pretty=True)
>> -    except IOError:
>> +    except (ModuleNotFoundError, OSError, IOError, UnicodeError, subprocess.CalledProcessError):
>>          system_release = "Misc"
>>  
>>      return system_release
>> -- 
>> 2.39.2


      reply	other threads:[~2023-06-30 12:30 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-19  6:32 [PATCH] python/sepolicy: Fix get_os_version except clause Jeffery To
2023-06-29 15:07 ` Petr Lautrbach
2023-06-30 12:29   ` Petr Lautrbach [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=87sfa9yvy8.fsf@redhat.com \
    --to=lautrbach@redhat.com \
    --cc=jeffery.to@gmail.com \
    --cc=selinux@vger.kernel.org \
    /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