mirror of
https://github.com/CMiksche/gitea-auto-update
synced 2025-12-10 16:07:23 +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:
20
functions.py
20
functions.py
@@ -49,3 +49,23 @@ def is_tool(name):
|
|||||||
from shutil import which
|
from shutil import which
|
||||||
|
|
||||||
return which(name) is not None
|
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
|
||||||
@@ -7,6 +7,7 @@ All rights reserved.
|
|||||||
License: GNU General Public License
|
License: GNU General Public License
|
||||||
'''
|
'''
|
||||||
# Gitea Site
|
# Gitea Site
|
||||||
|
# Optional - the script will get the version from the gitea file if you change the url to a empty string
|
||||||
gtsite = 'https://your-gitea-instance.com/api/v1/version'
|
gtsite = 'https://your-gitea-instance.com/api/v1/version'
|
||||||
# Gitea GitHub API URL for latest Relase
|
# Gitea GitHub API URL for latest Relase
|
||||||
gtgithubapiurl = 'https://api.github.com/repos/go-gitea/gitea/releases/latest'
|
gtgithubapiurl = 'https://api.github.com/repos/go-gitea/gitea/releases/latest'
|
||||||
|
|||||||
3
tests.py
3
tests.py
@@ -29,5 +29,8 @@ class Tests(unittest.TestCase):
|
|||||||
def testSuffix(self):
|
def testSuffix(self):
|
||||||
self.assertTrue(functions.checkVersion('1.9.0+dev-264-g8de76b6e6', '1.8.0'))
|
self.assertTrue(functions.checkVersion('1.9.0+dev-264-g8de76b6e6', '1.8.0'))
|
||||||
|
|
||||||
|
def testParseFileVersion(self):
|
||||||
|
self.assertEqual(functions.parseFileVersion('Gitea version 1.8.1 built with go1.12.2 : bindata, sqlite, sqlite_unlock_notify'), '1.8.1')
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
@@ -16,7 +16,7 @@ if not functions.is_tool("xz"):
|
|||||||
quit()
|
quit()
|
||||||
|
|
||||||
# Version from gitea site
|
# Version from gitea site
|
||||||
current_version = requests.get(settings.gtsite).json()['version']
|
current_version = functions.getCurrentVersion()
|
||||||
print ("current_version =", current_version)
|
print ("current_version =", current_version)
|
||||||
# Get version tag from github and remove first char (v)
|
# Get version tag from github and remove first char (v)
|
||||||
github_version_tag = requests.get(settings.gtgithubapiurl).json()['tag_name']
|
github_version_tag = requests.get(settings.gtgithubapiurl).json()['tag_name']
|
||||||
|
|||||||
Reference in New Issue
Block a user