diff options
author | MCApollo <34170230+MCApollo@users.noreply.github.com> | 2019-04-20 20:49:46 -0500 |
---|---|---|
committer | MCApollo <34170230+MCApollo@users.noreply.github.com> | 2019-04-23 20:18:47 -0500 |
commit | 12335518ab39608d58370c85ff9f5384ad2aa5f7 (patch) | |
tree | 352d81f2a2de3f1252af732080ec0fde38c13b4d /util/.marauder/marauder/version.py | |
parent | a2b26ad12d4fa12f0273645caf4be6d0b8b71e7c (diff) |
Ported in the homebrew-marauder for a hacky update/import system.
TODO: Maybe add a license & fix up messy code.
Diffstat (limited to 'util/.marauder/marauder/version.py')
-rw-r--r-- | util/.marauder/marauder/version.py | 40 |
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] |