]> git.mxchange.org Git - fba.git/commitdiff
Continued:
authorRoland Häder <roland@mxchange.org>
Thu, 25 May 2023 23:24:01 +0000 (01:24 +0200)
committerRoland Häder <roland@mxchange.org>
Thu, 25 May 2023 23:27:29 +0000 (01:27 +0200)
- 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

diff --git a/fba.py b/fba.py
index 1bc468458b08d7e36781cd527888ff808d1ae2a9..334da1acf03c1c38fdaba7dc39383657a611ab5b 100644 (file)
--- 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("^(?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-]+)*))?)?$")
+patterns = [
+    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<year>[1-9]{1}[0-9]{3})\.(?P<month>[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