updater.py fixes. updater code is moved to another repo
This commit is contained in:
parent
f782b99402
commit
417729d666
2 changed files with 31 additions and 30 deletions
|
@ -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()
|
||||
|
||||
|
|
|
@ -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)
|
||||
os.chdir(util.curr_directory())
|
||||
url = get_url(version)
|
||||
params = get_params(url)
|
||||
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)
|
||||
subprocess.Popen(params)
|
||||
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):
|
||||
|
|
Loading…
Reference in a new issue