diff --git a/functions.py b/functions.py index ff4af26..b06e06a 100644 --- a/functions.py +++ b/functions.py @@ -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 \ No newline at end of file diff --git a/settings.py b/settings.py index 8f56591..41704dc 100644 --- a/settings.py +++ b/settings.py @@ -7,6 +7,7 @@ All rights reserved. License: GNU General Public License ''' # 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' # Gitea GitHub API URL for latest Relase gtgithubapiurl = 'https://api.github.com/repos/go-gitea/gitea/releases/latest' diff --git a/tests.py b/tests.py index 4351263..11f01fc 100644 --- a/tests.py +++ b/tests.py @@ -29,5 +29,8 @@ class Tests(unittest.TestCase): def testSuffix(self): 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__': unittest.main() \ No newline at end of file diff --git a/updater.py b/updater.py index 43206c6..8670ba0 100644 --- a/updater.py +++ b/updater.py @@ -16,7 +16,7 @@ if not functions.is_tool("xz"): quit() # Version from gitea site -current_version = requests.get(settings.gtsite).json()['version'] +current_version = functions.getCurrentVersion() print ("current_version =", current_version) # Get version tag from github and remove first char (v) github_version_tag = requests.get(settings.gtgithubapiurl).json()['tag_name']