download-drivers: compare BIOS versions numerically, not as strings
parse_bios_catalog kept the 'latest' BIOS per model with a string compare, so e.g. '1.20.1' > '1.9.0' was False and it wrongly retained the older 1.9.0. Added _ver_tuple() and compare tuples of ints so the genuinely newest firmware wins.
This commit is contained in:
@@ -155,6 +155,14 @@ def parse_driver_catalog(xml_path, os_filter=None):
|
|||||||
return packs
|
return packs
|
||||||
|
|
||||||
|
|
||||||
|
def _ver_tuple(v):
|
||||||
|
"""Version string -> tuple of ints for numeric compare ('1.20.1' -> (1,20,1))."""
|
||||||
|
try:
|
||||||
|
return tuple(int(x) for x in str(v).split("."))
|
||||||
|
except (ValueError, AttributeError):
|
||||||
|
return (0,)
|
||||||
|
|
||||||
|
|
||||||
def parse_bios_catalog(xml_path, model_names):
|
def parse_bios_catalog(xml_path, model_names):
|
||||||
"""Parse DellSDPCatalogPC.xml → list of latest BIOS update dicts for given models."""
|
"""Parse DellSDPCatalogPC.xml → list of latest BIOS update dicts for given models."""
|
||||||
tree = ET.parse(xml_path)
|
tree = ET.parse(xml_path)
|
||||||
@@ -199,9 +207,11 @@ def parse_bios_catalog(xml_path, model_names):
|
|||||||
"model": matched_model,
|
"model": matched_model,
|
||||||
}
|
}
|
||||||
|
|
||||||
# Keep latest version per model
|
# Keep latest version per model. Compare numerically (tuple of ints),
|
||||||
|
# not as strings - "1.20.1" > "1.9.0" is False as a string compare,
|
||||||
|
# which would wrongly keep the older 1.9.0 BIOS.
|
||||||
key = matched_model
|
key = matched_model
|
||||||
if key not in bios or version > bios[key]["version"]:
|
if key not in bios or _ver_tuple(version) > _ver_tuple(bios[key]["version"]):
|
||||||
bios[key] = entry
|
bios[key] = entry
|
||||||
|
|
||||||
return list(bios.values())
|
return list(bios.values())
|
||||||
|
|||||||
Reference in New Issue
Block a user