summaryrefslogtreecommitdiff
path: root/util/.marauder/marauder/version.py
diff options
context:
space:
mode:
Diffstat (limited to 'util/.marauder/marauder/version.py')
-rw-r--r--util/.marauder/marauder/version.py40
1 files changed, 40 insertions, 0 deletions
diff --git a/util/.marauder/marauder/version.py b/util/.marauder/marauder/version.py
new file mode 100644
index 000000000..6ad09d9fe
--- /dev/null
+++ b/util/.marauder/marauder/version.py
@@ -0,0 +1,40 @@
+import os
+from io import BytesIO
+import re
+from urllib.request import urlopen
+import sys
+
+default = re.compile(r'(?:([0-9]+(?:[.-_][0-9]+)+))') # Version()
+
+""" Takes URL string and guesses version """
+def version(url):
+ filename = os.path.basename(url)
+ version = default.findall(filename)
+ if not version:
+ x = os.path.basename(os.path.dirname(url))
+ version = default.findall(x) # Go up one directory and try that.
+ if version:
+ return version[0]
+ version = re.findall(r'\S*?(:?[0-9-]+)', filename) # v40 or program-83 for example.
+ if version:
+ return version[0]
+ if url.endswith(".git"):
+ return None # FIXME: this is too slow.
+ # print(f"Finding version for {url}", file=sys.stderr)
+ latest_release = os.popen(
+ f"git ls-remote --tags {url} 2>/dev/null | sort -Vk2 | awk 'END{{ print $2 }}' | grep -oE '[0-9]+(\\.[0-9]+)+'"
+ ).read().strip()
+ latest_commit = os.popen(
+ f"git ls-remote --tags {url} 2>/dev/null | sort -Vk2 | awk 'END{{ print $1 }}'"
+ ).read().strip()
+ if latest_release and latest_commit:
+ version = f"{latest_release}-git-{latest_commit[:8]}"
+ elif latest_commit:
+ version = f"1.0-git-{latest_commit[:8]}"
+ else:
+ return None
+ return version
+
+ if not version: # If still no result.
+ return None
+ return version[0]