-
Notifications
You must be signed in to change notification settings - Fork 41
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support latest distro args in pxemenu #241
base: python-3
Are you sure you want to change the base?
Conversation
For latest distros, the variables 'method' and 'repos' are not supported in beaker pxemenu. Replace with 'inst.repos' instead. The latest distros are RHEL9, CentOSStream9, FedoraRawhide, FedoraELN, and Fedora34 and up.
@@ -31,6 +31,43 @@ def _get_url(available): | |||
[url for lc, url in available]) | |||
|
|||
|
|||
def _is_newer_distro(osmajor): | |||
if ((osmajor == 'FedoraELN') or (osmajor == 'Fedorarawhide') or |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about:
if osmajor.lower() in ('fedoraeln', 'fedorarawhide'):
return True
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just a side-note. I usually use list as a right hand side of such expression. Quick search shows that for small number of values, (), [] have similar performance (even assemble into same code) except using {} which is a little bit faster as it uses frozenset:
$ python3 -m timeit -s 'x = "test"' 'x in ("one", "two")'
10000000 loops, best of 5: 24.2 nsec per loop
$ python3 -m timeit -s 'x = "test"' 'x in ["one", "two"]'
10000000 loops, best of 5: 24.6 nsec per loop
$ python3 -m timeit -s 'x = "test"' 'x in {"one", "two"}'
20000000 loops, best of 5: 15.3 nsec per loop
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hehe. Interesting. I'll keep that in mind for large amounts of iterations and try to remember to just use it by default. It doesn't make a meaningful difference here. But in some situations it could be a valuable optimization!
if ((osmajor == 'FedoraELN') or (osmajor == 'Fedorarawhide') or | ||
(osmajor == 'FedoraRawhide')): | ||
return True | ||
split_str = re.split("(RedHatEnterpriseLinux|Fedora|CentOSStream)(\d+)", osmajor) # noqa: W605 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If mark it as a regular-expression string using r"
Then should not need the noqa
portion
split_str = re.split(r"(RedHatEnterpriseLinux|Fedora|CentOSStream)(\d+)", osmajor)
But how about this instead?
result = re.search(r"([a-zA-Z]+)(\d+)", osmajor)
if result is None:
return False
distro = result.groups()[0]
version = int(result.groups()[1])
if distro in ('RedHatEnterpriseLinux', 'CentOSStream') and version > 8:
return True
if distro == 'Fedora' and version > 33:
return True
return False
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
agree with above suggestion, the conditional logic can be made more readable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also named groups can be used r"(?P<distro>RedHatEnterpriseLinux|Fedora|CentOSStream)(?P<version>\d+)"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also named groups can be used
r"(?P<distro>RedHatEnterpriseLinux|Fedora|CentOSStream)(?P<version>\d+)"
I considered that. But when I tried it, the code seemed more complicated if using either result.groupdict()
or result.group("distro")
. But could add the named groups as like a comment about what each portion of the regex is. Though I don't think it is necessary.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, just one comment from John that should be addressed.
if ((osmajor == 'FedoraELN') or (osmajor == 'Fedorarawhide') or | ||
(osmajor == 'FedoraRawhide')): | ||
return True | ||
split_str = re.split("(RedHatEnterpriseLinux|Fedora|CentOSStream)(\d+)", osmajor) # noqa: W605 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
agree with above suggestion, the conditional logic can be made more readable.
Yes I'm working on it but need to change downstream first where I know full Unit Test suite runs which takes hours. |
For latest distros, the variables 'method' and 'repos' are not supported in beaker pxemenu. Replace with 'inst.repos' instead. The latest distros are
RHEL9, CentOSStream9, FedoraRawhide, FedoraELN, and Fedora34 and up.