diff --git a/functions.py b/functions.py new file mode 100644 index 0000000..770322e --- /dev/null +++ b/functions.py @@ -0,0 +1,42 @@ +import settings +import requests +import os + +# Function to download a file +def download(url, file_name): + # open in binary mode + with open(file_name, "wb") as file: + # get request + response = requests.get(url) + # write to file + file.write(response.content) + +# Function to build the new version from source +def buildFromSource(tag): + # Change to source dir + os.chdir(settings.source_dir) + # Checkout master + os.system("git checkout master") + # Update + os.system("git pull") + # Checkout relase branch + os.system("git checkout "+tag) + # Build from source + os.system('TAGS="bindata sqlite sqlite_unlock_notify" make generate build') + # Move binary + os.system("mv gitea "+settings.gtfile) + +# Function to create a list from a version string +def getVersionList(string): + return list(map(int, string.split('.'))) + +# Function to check if there is a new version +def checkVersion(new_version, old_version): + new_version_list = getVersionList(new_version) + old_version_list = getVersionList(old_version) + + for id, val in enumerate(new_version_list): + if val > old_version_list[id]: + return True + + return None diff --git a/tests.py b/tests.py new file mode 100644 index 0000000..8f92cb7 --- /dev/null +++ b/tests.py @@ -0,0 +1,19 @@ +import functions +import unittest + +class Tests(unittest.TestCase): + + def checkSimpleVersion(self): + self.assertTrue(functions.checkVersion('1.9.1', '1.9.0')) + + def checkTwoIntVersion(self): + self.assertTrue(functions.checkVersion('1.10.0', '1.9.0')) + + def checkFalseVersion(self): + self.assertFalse(functions.checkVersion('1.8.0', '1.9.0')) + + def checkSameVersion(self): + self.assertFalse(functions.checkVersion('1.9.7', '1.9.7')) + +if __name__ == '__main__': + unittest.main() \ No newline at end of file diff --git a/updater.py b/updater.py index 3508711..346eba6 100644 --- a/updater.py +++ b/updater.py @@ -9,6 +9,7 @@ License: GNU General Public License import settings import requests import os +<<<<<<< HEAD # Function to download a file @@ -35,6 +36,9 @@ def buildFromSource(tag): os.system('TAGS="bindata sqlite sqlite_unlock_notify" make generate build') # Move binary os.system("mv gitea "+settings.gtfile) +======= +import functions +>>>>>>> 38e9451f8a230c9110e7b43f34cd64f375858f71 def is_tool(name): ##Check whether `name` is on PATH and marked as executable. @@ -57,7 +61,7 @@ print ("github_version_tag =", github_version_tag) # Get version from version tag github_version = github_version_tag[1:] # Check if there is a new version -if github_version > current_version: +if functions.checkVersion(github_version, current_version): # Stop systemd service @@ -67,7 +71,7 @@ if github_version > current_version: # Should the new version be build from source? if settings.build_from_source: - buildFromSource(github_version_tag) + functions.buildFromSource(github_version_tag) else: # Set download url @@ -79,6 +83,7 @@ if github_version > current_version: print (shadownload) # Download file +<<<<<<< HEAD ## downloading sha print ("downloading sha256 hashsum") @@ -105,6 +110,9 @@ if github_version > current_version: else: print ("error") quit() +======= + functions.download(gtdownload, settings.gtfile) +>>>>>>> 38e9451f8a230c9110e7b43f34cd64f375858f71 # Start systemd service print ("starting gitea.service")