updater.py fixes. updater code is moved to another repo

This commit is contained in:
ingvar1995 2016-10-09 15:35:29 +03:00
parent f782b99402
commit 417729d666
2 changed files with 31 additions and 30 deletions

View file

@ -259,11 +259,13 @@ class Toxygen:
self.tray.show() self.tray.show()
self.tray.activated.connect(tray_activated) self.tray.activated.connect(tray_activated)
updating = False
if settings['update']: # auto update if settings['update']: # auto update
version = updater.check_for_updates() version = updater.check_for_updates()
if version is not None: if version is not None:
if settings['update'] == 2: if settings['update'] == 2:
updater.download(version) updater.download(version)
updating = True
else: else:
reply = QtGui.QMessageBox.question(None, reply = QtGui.QMessageBox.question(None,
'', '',
@ -275,6 +277,14 @@ class Toxygen:
QtGui.QMessageBox.No) QtGui.QMessageBox.No)
if reply == QtGui.QMessageBox.Yes: if reply == QtGui.QMessageBox.Yes:
updater.download(version) 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() self.ms.show()

View file

@ -1,10 +1,12 @@
import util import util
import os
import settings import settings
import platform import platform
try: try:
from PySide import QtNetwork, QtCore from PySide import QtNetwork, QtCore
except ImportError: except ImportError:
from PyQt4 import QtNetwork, QtCore from PyQt4 import QtNetwork, QtCore
import subprocess
def check_for_updates(): def check_for_updates():
@ -21,46 +23,35 @@ def is_from_sources():
return __file__.endswith('.py') 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): def test_url(version):
return 'https://github.com/toxygen-project/toxygen/releases/tag/v' + version return 'https://github.com/toxygen-project/toxygen/releases/tag/v' + version
def get_url(version): def get_url(version):
if not is_from_sources(): if is_from_sources():
return 'https://github.com/toxygen-project/toxygen/releases/tag/v' + version return 'https://github.com/toxygen-project/toxygen/archive/v' + version + '.zip'
else: else:
name = 'toxygen_windows.zip' if platform.system() == 'Windows' else 'toxygen_linux.tar.gz' 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): def download(version):
s = settings.Settings.get_instance() os.chdir(util.curr_directory())
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) url = get_url(version)
params = get_params(url)
try: try:
request = QtNetwork.QNetworkRequest(url) subprocess.Popen(params)
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: except Exception as ex:
util.log('Downloading new version of Toxygen failed with exception: ' + str(ex)) util.log('Exception: running updater failed with ' + str(ex))
def send_request(version): def send_request(version):