From 417729d66624feb48eb2ad44c565c4e0af435a9e Mon Sep 17 00:00:00 2001 From: ingvar1995 Date: Sun, 9 Oct 2016 15:35:29 +0300 Subject: [PATCH] updater.py fixes. updater code is moved to another repo --- toxygen/main.py | 10 +++++++++ toxygen/updater.py | 51 +++++++++++++++++++--------------------------- 2 files changed, 31 insertions(+), 30 deletions(-) diff --git a/toxygen/main.py b/toxygen/main.py index 0e39107..73ac63c 100644 --- a/toxygen/main.py +++ b/toxygen/main.py @@ -259,11 +259,13 @@ class Toxygen: self.tray.show() self.tray.activated.connect(tray_activated) + updating = False if settings['update']: # auto update version = updater.check_for_updates() if version is not None: if settings['update'] == 2: updater.download(version) + updating = True else: reply = QtGui.QMessageBox.question(None, '', @@ -275,6 +277,14 @@ class Toxygen: QtGui.QMessageBox.No) if reply == QtGui.QMessageBox.Yes: updater.download(version) + updating = True + + if updating: + data = self.tox.get_savedata() + ProfileHelper.get_instance().save_profile(data) + settings.close() + del self.tox + return self.ms.show() diff --git a/toxygen/updater.py b/toxygen/updater.py index fb33ec8..23a5c55 100644 --- a/toxygen/updater.py +++ b/toxygen/updater.py @@ -1,10 +1,12 @@ import util +import os import settings import platform try: from PySide import QtNetwork, QtCore except ImportError: from PyQt4 import QtNetwork, QtCore +import subprocess def check_for_updates(): @@ -21,46 +23,35 @@ def is_from_sources(): return __file__.endswith('.py') -def get_file_name(): - res = 'toxygen.zip' if platform.system() == 'Windows' else 'toxygen.tar.gz' - return util.curr_directory() + '/' + res - - def test_url(version): return 'https://github.com/toxygen-project/toxygen/releases/tag/v' + version def get_url(version): - if not is_from_sources(): - return 'https://github.com/toxygen-project/toxygen/releases/tag/v' + version + if is_from_sources(): + return 'https://github.com/toxygen-project/toxygen/archive/v' + version + '.zip' else: name = 'toxygen_windows.zip' if platform.system() == 'Windows' else 'toxygen_linux.tar.gz' - return 'https://github.com/toxygen-project/toxygen/archive/v{}.{}'.format(version, name) + return 'https://github.com/toxygen-project/toxygen/releases/tag/v{}/{}'.format(version, name) + + +def get_params(url): + if is_from_sources(): + return ['python3', 'toxygen_updater.py', url] + elif platform.system() == 'Windows': + return ['run', 'toxygen_updater.exe', url] + else: + return ['./toxygen_updater', url] def download(version): - s = settings.Settings.get_instance() - if s['update']: - netman = QtNetwork.QNetworkAccessManager() - proxy = QtNetwork.QNetworkProxy() - if s['proxy_type']: - proxy.setType( - QtNetwork.QNetworkProxy.Socks5Proxy if s['proxy_type'] == 2 else QtNetwork.QNetworkProxy.HttpProxy) - proxy.setHostName(s['proxy_host']) - proxy.setPort(s['proxy_port']) - netman.setProxy(proxy) - url = get_url(version) - try: - request = QtNetwork.QNetworkRequest(url) - reply = netman.get(request) - while not reply.isFinished(): - QtCore.QThread.msleep(1) - QtCore.QCoreApplication.processEvents() - data = bytes(reply.readAll().data()) # TODO: fix - with open(get_file_name(), 'wb') as fl: - fl.write(data) - except Exception as ex: - util.log('Downloading new version of Toxygen failed with exception: ' + str(ex)) + os.chdir(util.curr_directory()) + url = get_url(version) + params = get_params(url) + try: + subprocess.Popen(params) + except Exception as ex: + util.log('Exception: running updater failed with ' + str(ex)) def send_request(version):