Moved logic to own function

Allows importing from another file
This commit is contained in:
Marcel Kapfer 2021-05-26 21:13:28 +02:00
parent 8659de71cd
commit c3e3b0800a
Signed by: mmk2410
GPG key ID: CADE6F0C09F21B09

View file

@ -20,13 +20,7 @@
import subprocess import subprocess
def sorted_tags():
def main():
# # TODO: Add user defined keywords to the list.
# ignored_keywords = ["pre", "rc", "beta", "alpha", "dev"]
# # TODO: Add a ability for the user to customize this.
# default_branch = "main"
# Retrieve all tags in the repo (that are fetched...) # Retrieve all tags in the repo (that are fetched...)
tags = subprocess.run(["git", "tag"], stdout=subprocess.PIPE) tags = subprocess.run(["git", "tag"], stdout=subprocess.PIPE)
allowedTags = {} allowedTags = {}
@ -39,12 +33,20 @@ def main():
# Strip away the encloding quotes as well as some whitespace # Strip away the encloding quotes as well as some whitespace
allowedTags[tag] = date.stdout.decode('utf-8').strip(" \n'") allowedTags[tag] = date.stdout.decode('utf-8').strip(" \n'")
# Sort by keys, which are the retrieved timestampes # Sort by keys, which are the retrieved timestampes
allowedTags = sorted(allowedTags.items(), key=lambda item: item[1]) return sorted(allowedTags.items(), key=lambda item: item[1])
def main():
# # TODO: Add user defined keywords to the list.
# ignored_keywords = ["pre", "rc", "beta", "alpha", "dev"]
# # TODO: Add a ability for the user to customize this.
# default_branch = "main"
tags = sorted_tags()
# Printing out # Printing out
for k,v in allowedTags: for k,_ in tags:
print(k) print(k)
print("Latest tag: {}\nSecond latest tag: {}".format(allowedTags[-1][0],allowedTags[-2][0])) print("Latest tag: {}\nSecond latest tag: {}".format(tags[-1][0],tags[-2][0]))
if __name__ == "__main__": if __name__ == "__main__":