new self update method

This commit is contained in:
BarsTiger
2022-05-05 20:52:37 +03:00
parent 3c1b8925f2
commit 3d0d603b51
2 changed files with 37 additions and 15 deletions

View File

@@ -34,6 +34,9 @@ if not os.path.isfile(horsy_vars.horsypath + 'config.cfg'):
if not os.path.isfile(horsy_vars.horsypath + 'apps/versions.json'): if not os.path.isfile(horsy_vars.horsypath + 'apps/versions.json'):
with open(horsy_vars.horsypath + 'apps/versions.json', 'w+') as f: with open(horsy_vars.horsypath + 'apps/versions.json', 'w+') as f:
f.write('{}') f.write('{}')
if os.path.isfile(horsy_vars.horsypath + 'horsy.old'):
os.remove(horsy_vars.horsypath + 'horsy.old')
print('Removed old horsy')
# Checking version # Checking version
try: try:
@@ -44,15 +47,22 @@ except:
'If you installed it just now, please restart PC.') 'If you installed it just now, please restart PC.')
if int(request.get('https://github.com/horsy-ml/horsy/raw/master/web_vars/version').text) > version: if int(request.get('https://github.com/horsy-ml/horsy/raw/master/web_vars/version').text) > version:
from modules.download import dl
import urllib.request
print('New version available!') print('New version available!')
print('If you see this message again, or horsy doesn\'t launch itself for long time, please type '
'horsy_updater in your terminal to update it manually.')
input('Press enter to update...') input('Press enter to update...')
print('Updating...') print('Updating...')
print('Please wait, if process seems closed, its OK, just wait a bit.') print('Please wait...')
with open(os.path.join(horsy_vars.horsypath) + '/horsy_updater.exe', 'wb') as f: os.rename(horsy_vars.horsypath + "horsy.exe", horsy_vars.horsypath + "horsy.old")
f.write(request.get('https://github.com/horsy-ml/horsy/raw/master/bin/horsy_updater.exe').content) print('Renamed horsy.exe to horsy.old')
subprocess.Popen('horsy_updater.exe horsy', shell=True, close_fds=True) dl(['https://github.com/horsy-ml/horsy/raw/master/bin/horsy.exe',
'https://github.com/horsy-ml/horsy/raw/master/bin/horsygui.exe']
if os.path.isfile(horsy_vars.horsypath + 'horsygui.exe') else
['https://github.com/horsy-ml/horsy/raw/master/bin/horsy.exe'],
horsy_vars.horsypath)
urllib.request.urlretrieve("https://github.com/horsy-ml/horsy/raw/master/web_vars/version",
horsy_vars.horsypath + '/apps/version')
subprocess.Popen(str(horsy_vars.horsypath + 'horsy.exe'), shell=True, close_fds=True)
sys.exit(0) sys.exit(0)

View File

@@ -250,6 +250,9 @@ if __name__ == "__main__":
if not os.path.isfile(horsy_vars.horsypath + 'apps/versions.json'): if not os.path.isfile(horsy_vars.horsypath + 'apps/versions.json'):
with open(horsy_vars.horsypath + 'apps/versions.json', 'w+') as f: with open(horsy_vars.horsypath + 'apps/versions.json', 'w+') as f:
f.write('{}') f.write('{}')
if os.path.isfile(horsy_vars.horsypath + 'horsygui.old'):
os.remove(horsy_vars.horsypath + 'horsygui.old')
gui.popup('Success', 'Removed old horsygui')
# Checking version # Checking version
try: try:
@@ -261,20 +264,29 @@ if __name__ == "__main__":
if int(request.get('https://github.com/horsy-ml/horsy/raw/master/web_vars/version').text) > version: if int(request.get('https://github.com/horsy-ml/horsy/raw/master/web_vars/version').text) > version:
gui.popup('Update', 'New version available! \nWe appreciate your safety, so you need to update horsy.' gui.popup('Update', 'New version available! \nWe appreciate your safety, so you need to update horsy.'
'\nPress OK and updater will download the latest version.\n' '\nPress OK and updater will download the latest version.\n'
'If you see this message again, or horsy doesn\'t launch \n' 'If you see this message again, or horsy doesn\'t launch, \n'
'itself for long time, please type horsy_updater in your terminal.') 'download updater manually from GitHub.\n\n'
'Window will hide while updating.')
try: try:
with open(os.path.join(horsy_vars.horsypath) + '/horsy_updater.exe', 'wb') as f: import urllib.request
f.write(request.get('https://github.com/horsy-ml/horsy/raw/master/bin/horsy_updater.exe').content) UiMainWindow.close()
os.rename(horsy_vars.horsypath + "horsygui.exe", horsy_vars.horsypath + "horsygui.old")
with open(os.path.join(horsy_vars.horsypath) + 'horsygui.exe', 'wb') as f:
f.write(request.get('https://github.com/horsy-ml/horsy/raw/master/bin/horsygui.exe').content)
with open(os.path.join(horsy_vars.horsypath) + 'horsy.exe', 'wb') as f:
f.write(request.get('https://github.com/horsy-ml/horsy/raw/master/bin/horsy.exe').content)
urllib.request.urlretrieve("https://github.com/horsy-ml/horsy/raw/master/web_vars/version",
horsy_vars.horsypath + '/apps/version')
except: except:
gui.popup('Error', 'Could not download updater. \nMaybe installation folder is not writable ' gui.popup('Error', 'Could not download horsy. \nMaybe installation folder is not writable '
'(only for admins).\n Please reinstall horsy or update it manually. \n' '(only for admins).\n Please reinstall horsy or update it manually. \n'
'Click OK, download file that will open browser and launch it.\n' 'Click OK, download file that will be opened in browser copy it to horsy \n'
'folder and launch it.\n'
'Afterwards, delete updater file and launch horsy again.') 'Afterwards, delete updater file and launch horsy again.')
webbrowser.open('https://github.com/horsy-ml/horsy/raw/master/bin/horsy_updater.exe') webbrowser.open('https://github.com/horsy-ml/horsy/raw/master/bin/horsy_updater.exe')
UiMainWindow.close()
subprocess.Popen('horsy_updater.exe horsygui', shell=True, close_fds=True) subprocess.Popen(str(horsy_vars.horsypath + 'horsygui.exe'), shell=True, close_fds=True)
sys.exit() sys.exit(0)
get_users_apps() get_users_apps()
installed_apps() installed_apps()