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

Feature Request: PyEz official version compare function #1225

Open
shigechika opened this issue Dec 16, 2022 · 0 comments
Open

Feature Request: PyEz official version compare function #1225

shigechika opened this issue Dec 16, 2022 · 0 comments

Comments

@shigechika
Copy link
Contributor

I need a official version compare function.

I am using distutils LooseVersion() in my PyEz based tools ( https://github.com/shigechika/junos-update )
But LooseVersion() has problems.

  • distutils Version classes are deprecated.
  • LooseVersion() can't compare JUNOS -S train. ex 20.4R3.8 vs 20.4R3-S4.8

So, I use the following function. but It's not portable in the future.

def compare_version(left, right):
    """compare version left and right

    :param left: version left string, ex 18.4R3-S9.2, 
    :param right: version right string, ex 18.4R3-S10

    :return:  1 if left  > right
              0 if left == right
             -1 if left  < right
    """
    if left is None or right is None:
        return None
    if LooseVersion(left.replace("-S", "00")) > LooseVersion(right.replace("-S", "00")):
	return 1
    if LooseVersion(left.replace("-S", "00")) < LooseVersion(right.replace("-S", "00")):
        return -1
    return 0

Could you create official version compare function?
Thank you.

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

No branches or pull requests

2 participants