1
0
mirror of https://github.com/CMiksche/gitea-auto-update synced 2025-12-12 17:07:22 +01:00

feat: get version from file

Add function to get the version from the gitea file if the web api does fail.

Should implement the idea from GH-8
This commit is contained in:
Christoph Miksche
2019-05-31 22:16:11 +02:00
parent b38143effc
commit 482df30496
4 changed files with 25 additions and 1 deletions

View File

@@ -49,3 +49,23 @@ def is_tool(name):
from shutil import which
return which(name) is not None
def parseFileVersion(string):
return string.split(" ")[2]
def getVersionFromFile():
version_string = os.popen(settings.gtfile+" -v").read()
return parseFileVersion(version_string)
# Function to get the current version
def getCurrentVersion():
try:
# Try to get the version from the file
current_version = getVersionFromFile()
except:
# Get the version via the web api if the file does fail
current_version = requests.get(settings.gtsite).json()['version']
if current_version.status_code != 200:
current_version = getVersionFromFile()
finally:
return current_version