Skip to content
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

Open
wants to merge 1 commit into
base: python-3
Choose a base branch
from

Conversation

cbouchar
Copy link
Contributor

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.

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
Copy link
Collaborator

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

Copy link
Member

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

Copy link
Collaborator

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
Copy link
Collaborator

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

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.

Copy link
Member

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+)"

Copy link
Collaborator

@JohnVillalovos JohnVillalovos Nov 16, 2024

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.

Copy link

@jchristi jchristi left a 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

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.

@cbouchar
Copy link
Contributor Author

Yes I'm working on it but need to change downstream first where I know full Unit Test suite runs which takes hours.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants