# Pattern instance for version numbers
patterns = [
# semantic version number (with v|V) prefix)
- re.compile("^(?P<version>v|V{0,1})(\.{0,1})(?P<major>0|[1-9]\d*)\.(?P<minor>0|[1-9]\d*)(\.(?P<patch>0|[1-9]\d*)(?:-(?P<prerelease>(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+(?P<buildmetadata>[0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?)?$"),
+ re.compile("^(?P<version>v|V{0,1})(\.{0,1})(?P<major>0|[1-9]\d*)\.(?P<minor>0+|[1-9]\d*)(\.(?P<patch>0+|[1-9]\d*)(?:-(?P<prerelease>(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+(?P<buildmetadata>[0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?)?$"),
# non-sematic, e.g. 1.2.3.4
- re.compile("^(?P<version>v|V{0,1})(\.{0,1})(?P<major>0|[1-9]\d*)\.(?P<minor>0|[1-9]\d*)(\.(?P<patch>0|[1-9]\d*)(\.(?P<subpatch>0|[1-9]\d*))?)$"),
+ re.compile("^(?P<version>v|V{0,1})(\.{0,1})(?P<major>0|[1-9]\d*)\.(?P<minor>0+|[1-9]\d*)(\.(?P<patch>0+|[1-9]\d*)(\.(?P<subpatch>0|[1-9]\d*))?)$"),
# non-sematic, e.g. 2023-05
re.compile("^(?P<year>[1-9]{1}[0-9]{3})\.(?P<month>[0-9]{2})$")
]
# NOISY-DEBUG: print(f"DEBUG: end[{type(end)}]={end}")
software = software[0:end].strip()
+ if " version" in software:
+ # NOISY-DEBUG: print(f"DEBUG: software='{software}' contains word ' version'")
+ software = strip_until(software, " version")
# NOISY-DEBUG: print(f"DEBUG: software='{software}' - EXIT!")
return software
def strip_powered_by(software: str) -> str:
# NOISY-DEBUG: print(f"DEBUG: software='{software}' - CALLED!")
- if not "powered by" in software:
+ if software == "":
+ print(f"ERROR: Bad method call, 'software' is empty")
+ raise Exception("Parameter 'software' is empty")
+ elif not "powered by" in software:
print(f"WARNING: Cannot find 'powered by' in '{software}'!")
return software
software = software[start + 11:].strip()
# NOISY-DEBUG: print(f"DEBUG: software='{software}'")
- # Next, strip of ' - ' part
- end = software.find(" - ")
+ software = strip_until(software, " - ")
+
+ # NOISY-DEBUG: print(f"DEBUG: software='{software}' - EXIT!")
+ return software
+
+def strip_until(software: str, until: str) -> str:
+ # NOISY-DEBUG: print(f"DEBUG: software='{software}',until='{until}' - CALLED!")
+ if software == "":
+ print(f"ERROR: Bad method call, 'software' is empty")
+ raise Exception("Parameter 'software' is empty")
+ elif until == "":
+ print(f"ERROR: Bad method call, 'until' is empty")
+ raise Exception("Parameter 'until' is empty")
+ elif not until in software:
+ print(f"WARNING: Cannot find 'powered by' in '{software}'!")
+ return software
+
+ # Next, strip until part
+ end = software.find(until)
+
# NOISY-DEBUG: print(f"DEBUG: end[{type(end)}]='{end}'")
if end > 0:
software = software[0:end].strip()
if type(software) is str and "powered by" in software:
# NOISY-DEBUG: print(f"DEBUG: software='{software}' has 'powered by' in it")
software = remove_version(strip_powered_by(software))
+ elif type(software) is str and " by " in software:
+ # NOISY-DEBUG: print(f"DEBUG: software='{software}' has ' by ' in it")
+ software = strip_until(software, " by ")
+ elif type(software) is str and " see " in software:
+ # NOISY-DEBUG: print(f"DEBUG: software='{software}' has ' see ' in it")
+ software = strip_until(software, " see ")
# NOISY-DEBUG: print(f"DEBUG: software='{software}' - EXIT!")
return software
print("WARNING: Spliting of pipe:", software)
software = tidyup(software.split("|")[0]);
elif "powered by" in software:
- print(f"DEBUG: software='{software}' has 'powered by' in it")
+ # NOISY-DEBUG: print(f"DEBUG: software='{software}' has 'powered by' in it")
software = strip_powered_by(software)
+ elif type(software) is str and " by " in software:
+ # NOISY-DEBUG: print(f"DEBUG: software='{software}' has ' by ' in it")
+ software = strip_until(software, " by ")
+ elif type(software) is str and " see " in software:
+ # NOISY-DEBUG: print(f"DEBUG: software='{software}' has ' see ' in it")
+ software = strip_until(software, " see ")
# NOISY-DEBUG: print(f"DEBUG: software[]={type(software)}")
if software == "":