-def remove_version(software: str) -> str:
- # DEBUG: print(f"DEBUG: software='{software}' - CALLED!")
- if not "." in software and " " not in software:
- print(f"WARNING: software='{software}' does not contain a version number.")
- return software
-
- temp = software
- if ";" in software:
- temp = software.split(";")[0]
- elif "," in software:
- temp = software.split(",")[0]
- elif " - " in software:
- temp = software.split(" - ")[0]
-
- # DEBUG: print(f"DEBUG: software='{software}'")
- version = None
- if " " in software:
- version = temp.split(" ")[-1]
- elif "/" in software:
- version = temp.split("/")[-1]
- elif "-" in software:
- version = temp.split("-")[-1]
- else:
- # DEBUG: print(f"DEBUG: Was not able to find common seperator, returning untouched software='{software}'")
- return software
-
- match = None
- # DEBUG: print(f"DEBUG: Checking {len(patterns)} patterns ...")
- for pattern in patterns:
- # Run match()
- match = pattern.match(version)
-
- # DEBUG: print(f"DEBUG: match[]={type(match)}")
- if isinstance(match, re.Match):
- # DEBUG: print(f"DEBUG: version='{version}' is matching pattern='{pattern}'")
- break
-
- # DEBUG: print(f"DEBUG: version[{type(version)}]='{version}',match='{match}'")
- if not isinstance(match, re.Match):
- print(f"WARNING: version='{version}' does not match regex, leaving software='{software}' untouched.")
- return software
-
- # DEBUG: print(f"DEBUG: Found valid version number: '{version}', removing it ...")
- end = len(temp) - len(version) - 1
-
- # DEBUG: print(f"DEBUG: end[{type(end)}]={end}")
- software = temp[0:end].strip()
- if " version" in software:
- # DEBUG: print(f"DEBUG: software='{software}' contains word ' version'")
- software = strip_until(software, " version")
-
- # DEBUG: print(f"DEBUG: software='{software}' - EXIT!")
- return software
-
-def strip_powered_by(software: str) -> str:
- # DEBUG: print(f"DEBUG: software='{software}' - CALLED!")
- if not isinstance(software, str):
- raise ValueError(f"Parameter software[]='{type(software)}' is not 'str'")
- elif software == "":
- raise ValueError("Parameter 'software' is empty")
- elif "powered by" not in software:
- print(f"WARNING: Cannot find 'powered by' in software='{software}'!")
- return software
-
- start = software.find("powered by ")
- # DEBUG: print(f"DEBUG: start[{type(start)}]='{start}'")
-
- software = software[start + 11:].strip()
- # DEBUG: print(f"DEBUG: software='{software}'")
-
- software = strip_until(software, " - ")
-
- # DEBUG: print(f"DEBUG: software='{software}' - EXIT!")
- return software
-
-def strip_hosted_on(software: str) -> str:
- # DEBUG: print(f"DEBUG: software='{software}' - CALLED!")
- if not isinstance(software, str):
- raise ValueError(f"Parameter software[]='{type(software)}' is not 'str'")
- elif software == "":
- raise ValueError("Parameter 'software' is empty")
- elif "hosted on" not in software:
- print(f"WARNING: Cannot find 'hosted on' in '{software}'!")
- return software
-
- end = software.find("hosted on ")
- # DEBUG: print(f"DEBUG: end[{type(end)}]='{end}'")
-
- software = software[0, end].strip()
- # DEBUG: print(f"DEBUG: software='{software}'")
-
- software = strip_until(software, " - ")
-
- # DEBUG: print(f"DEBUG: software='{software}' - EXIT!")
- return software
-
-def strip_until(software: str, until: str) -> str:
- # DEBUG: print(f"DEBUG: software='{software}',until='{until}' - CALLED!")
- if not isinstance(software, str):
- raise ValueError(f"Parameter software[]='{type(software)}' is not 'str'")
- elif software == "":
- raise ValueError("Parameter 'software' is empty")
- elif not isinstance(until, str):
- raise ValueError(f"Parameter until[]='{type(until)}' is not 'str'")
- elif until == "":
- raise ValueError("Parameter 'until' is empty")
- elif not until in software:
- print(f"WARNING: Cannot find '{until}' in '{software}'!")
- return software
-
- # Next, strip until part
- end = software.find(until)
-
- # DEBUG: print(f"DEBUG: end[{type(end)}]='{end}'")
- if end > 0:
- software = software[0:end].strip()
-
- # DEBUG: print(f"DEBUG: software='{software}' - EXIT!")
- return software
-
-def remove_pending_error(domain: str):
- if not isinstance(domain, str):
- raise ValueError(f"Parameter domain[]={type(domain)} is not 'str'")
- elif domain == "":
- raise ValueError("Parameter 'domain' is empty")
-
- try:
- # Prevent updating any pending errors, nodeinfo was found
- del pending_errors[domain]
-
- except:
- pass
-
- # DEBUG: print("DEBUG: EXIT!")
-