From 74ed2ed68ec59736f0ec6c8a9e47098d92f66c49 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Fri, 26 May 2023 01:24:01 +0200 Subject: [PATCH] Continued: - old Friendica installations (I found one with 2019.03) may have version number in software's name info and in format YYYY.MM (and maybe later others) --- fba.py | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/fba.py b/fba.py index 1bc4684..334da1a 100644 --- a/fba.py +++ b/fba.py @@ -90,7 +90,10 @@ connection = sqlite3.connect("blocks.db") cursor = connection.cursor() # Pattern instance for version numbers -pattern = re.compile("^(?Pv|V{0,1})(\.{0,1})(?P0|[1-9]\d*)\.(?P0|[1-9]\d*)(\.(?P0|[1-9]\d*)(?:-(?P(?: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[0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?)?$") +patterns = [ + re.compile("^(?Pv|V{0,1})(\.{0,1})(?P0|[1-9]\d*)\.(?P0|[1-9]\d*)(\.(?P0|[1-9]\d*)(?:-(?P(?: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[0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?)?$"), + re.compile("^(?P[1-9]{1}[0-9]{3})\.(?P[0-9]{2})$") +] def remove_version(software: str) -> str: # NOISY-DEBUG: print(f"DEBUG: software='{software}' - CALLED!") @@ -109,11 +112,17 @@ def remove_version(software: str) -> str: # NOISY-DEBUG: print(f"DEBUG: Was not able to find common seperator, returning untouched software='{software}'") return software - # Run match() - matches = pattern.match(version) + matches = None + # NOISY-DEBUG: print(f"DEBUG: Checking {len(patterns)} patterns ...") + for pattern in patterns: + # Run match() + match = pattern.match(version) + # NOISY-DEBUG: print(f"DEBUG: match[]={type(match)}") + if type(match) is re.Match: + break - # NOISY-DEBUG: print(f"DEBUG: version[{type(version)}]='{version}',matches='{matches}'") - if type(matches) is not re.Match: + # NOISY-DEBUG: print(f"DEBUG: version[{type(version)}]='{version}',match='{match}'") + if type(match) is not re.Match: print(f"WARNING: version='{version}' does not match regex, leaving software='{software}' untouched.") return software -- 2.39.5