Reputation: 774
I need to compare software versions for Cisco devices in Python, but unfortunately packaging.version doesn't support this format when 3rd and 4th indexes are joined by letters. Maybe someone knows a package that can compare the following versioning format "15.2.7E7"
from packaging.version import Version
# working
if Version("15.2.7") > Version("15.2.1"):
print("packaging.version is working")
# not working
try:
if Version("15.2.7E7") > Version("15.2.7E1"):
print("Cisco version is working")
except Exception:
print("Cisco version is not working")
# result
# packaging.version is working
# Cisco version is not working
Upvotes: 0
Views: 215
Reputation: 774
netports.SwVersion can parse and compare Cisco software versions, as in the following example
import re
from netports import SwVersion
text = "Cisco IOS Software, C2960X Software (C2960X-UNIVERSALK9-M), Version 15.2(4)E10, ..."
text = re.search(r"Version (\S+),", text)[1]
version1 = SwVersion(text) # 15.2(4)E10
version2 = SwVersion("15.2(4)E11")
assert version1 < version2
assert version1 <= version2
assert not version1 > version2
assert not version1 >= version2
print(version1)
print(version2)
# 15.2(4)e10
# 15.2(4)e11
Upvotes: 0