mirror of
https://github.com/dkmstr/openuds.git
synced 2025-01-05 09:17:54 +03:00
Some minor inprovements to plugin
This commit is contained in:
parent
93c6c1c20e
commit
512feaed81
@ -45,6 +45,8 @@ import webbrowser
|
|||||||
|
|
||||||
from UDSWindow import Ui_MainWindow
|
from UDSWindow import Ui_MainWindow
|
||||||
|
|
||||||
|
class RetryException(Exception):
|
||||||
|
pass
|
||||||
|
|
||||||
class UDSClient(QtGui.QMainWindow):
|
class UDSClient(QtGui.QMainWindow):
|
||||||
|
|
||||||
@ -77,6 +79,10 @@ class UDSClient(QtGui.QMainWindow):
|
|||||||
|
|
||||||
def processError(self, data):
|
def processError(self, data):
|
||||||
if 'error' in data:
|
if 'error' in data:
|
||||||
|
# QtGui.QMessageBox.critical(self, 'Request error {}'.format(data.get('retryable', '0')), data['error'], QtGui.QMessageBox.Ok)
|
||||||
|
if data.get('retryable', '0') == '1':
|
||||||
|
raise RetryException(data['error'])
|
||||||
|
|
||||||
raise Exception(data['error'])
|
raise Exception(data['error'])
|
||||||
# QtGui.QMessageBox.critical(self, 'Request error', rest.data['error'], QtGui.QMessageBox.Ok)
|
# QtGui.QMessageBox.critical(self, 'Request error', rest.data['error'], QtGui.QMessageBox.Ok)
|
||||||
# self.closeWindow()
|
# self.closeWindow()
|
||||||
@ -92,6 +98,13 @@ class UDSClient(QtGui.QMainWindow):
|
|||||||
def cancelPushed(self):
|
def cancelPushed(self):
|
||||||
self.close()
|
self.close()
|
||||||
|
|
||||||
|
def _updateProgressBar(self, increment, maximum=100):
|
||||||
|
val = self.ui.progressBar.value()
|
||||||
|
val += increment
|
||||||
|
if val > maximum:
|
||||||
|
val = maximum
|
||||||
|
self.ui.progressBar.setValue(val)
|
||||||
|
|
||||||
@QtCore.pyqtSlot()
|
@QtCore.pyqtSlot()
|
||||||
def getVersion(self):
|
def getVersion(self):
|
||||||
self.req = RestRequest('', self, self.version)
|
self.req = RestRequest('', self, self.version)
|
||||||
@ -100,7 +113,7 @@ class UDSClient(QtGui.QMainWindow):
|
|||||||
@QtCore.pyqtSlot(dict)
|
@QtCore.pyqtSlot(dict)
|
||||||
def version(self, data):
|
def version(self, data):
|
||||||
try:
|
try:
|
||||||
self.ui.progressBar.setValue(50)
|
self.ui.progressBar.setValue(20)
|
||||||
|
|
||||||
self.processError(data)
|
self.processError(data)
|
||||||
|
|
||||||
@ -111,19 +124,29 @@ class UDSClient(QtGui.QMainWindow):
|
|||||||
webbrowser.open(data['result']['downloadUrl'])
|
webbrowser.open(data['result']['downloadUrl'])
|
||||||
self.closeWindow()
|
self.closeWindow()
|
||||||
return
|
return
|
||||||
|
self.getTransportData()
|
||||||
|
|
||||||
self.req = RestRequest('/{}/{}'.format(self.ticket, self.scrambler), self, self.transportDataReceived, params={'hostname': tools.getHostName(), 'version': VERSION})
|
except RetryException as e:
|
||||||
self.req.get()
|
self._updateProgressBar(5, 80)
|
||||||
|
self.ui.info.setText(six.text_type(e))
|
||||||
|
QtCore.QTimer.singleShot(1000, self.getVersion)
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.showError(e)
|
self.showError(e)
|
||||||
|
|
||||||
|
@QtCore.pyqtSlot()
|
||||||
|
def getTransportData(self):
|
||||||
|
self.req = RestRequest('/{}/{}'.format(self.ticket, self.scrambler), self, self.transportDataReceived, params={'hostname': tools.getHostName(), 'version': VERSION})
|
||||||
|
self.req.get()
|
||||||
|
|
||||||
|
|
||||||
@QtCore.pyqtSlot(dict)
|
@QtCore.pyqtSlot(dict)
|
||||||
def transportDataReceived(self, data):
|
def transportDataReceived(self, data):
|
||||||
try:
|
try:
|
||||||
self.ui.progressBar.setValue(80)
|
|
||||||
self.processError(data)
|
self.processError(data)
|
||||||
|
|
||||||
|
self.ui.progressBar.setValue(80)
|
||||||
|
|
||||||
script = data['result'].decode('base64').decode('bz2')
|
script = data['result'].decode('base64').decode('bz2')
|
||||||
|
|
||||||
six.exec_(script, globals(), {'parent': self})
|
six.exec_(script, globals(), {'parent': self})
|
||||||
@ -133,6 +156,12 @@ class UDSClient(QtGui.QMainWindow):
|
|||||||
|
|
||||||
QtCore.QTimer.singleShot(3000, self.endScript)
|
QtCore.QTimer.singleShot(3000, self.endScript)
|
||||||
|
|
||||||
|
except RetryException as e:
|
||||||
|
self._updateProgressBar(5, 80)
|
||||||
|
self.ui.info.setText(six.text_type(e) + ', retrying access...')
|
||||||
|
# Retry operation in ten seconds
|
||||||
|
QtCore.QTimer.singleShot(10000, self.getTransportData)
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.showError(e)
|
self.showError(e)
|
||||||
|
|
||||||
|
@ -63,7 +63,7 @@ class Client(Handler):
|
|||||||
authenticated = False # Client requests are not authenticated
|
authenticated = False # Client requests are not authenticated
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def result(result=None, error=None, errorCode=0):
|
def result(result=None, error=None, errorCode=0, retryable=False):
|
||||||
'''
|
'''
|
||||||
Helper method to create a "result" set for actor response
|
Helper method to create a "result" set for actor response
|
||||||
:param result: Result value to return (can be None, in which case it is converted to empty string '')
|
:param result: Result value to return (can be None, in which case it is converted to empty string '')
|
||||||
@ -79,6 +79,10 @@ class Client(Handler):
|
|||||||
error += ' (code {0:04X})'.format(errorCode)
|
error += ' (code {0:04X})'.format(errorCode)
|
||||||
|
|
||||||
res['error'] = error
|
res['error'] = error
|
||||||
|
res['retryable'] = retryable and '1' or '0'
|
||||||
|
|
||||||
|
logger.debug('Client Result: {}'.format(res))
|
||||||
|
|
||||||
return res
|
return res
|
||||||
|
|
||||||
def test(self):
|
def test(self):
|
||||||
@ -140,7 +144,9 @@ class Client(Handler):
|
|||||||
|
|
||||||
return Client.result(result=transportScript.encode('bz2').encode('base64'))
|
return Client.result(result=transportScript.encode('bz2').encode('base64'))
|
||||||
except ServiceNotReadyError as e:
|
except ServiceNotReadyError as e:
|
||||||
return Client.result(error=errors.SERVICE_NOT_READY, errorCode=e.code)
|
# Refresh ticket and make this retrayable
|
||||||
|
TicketStore.revalidate(ticket, 20) # Retry will be in at most 5 seconds
|
||||||
|
return Client.result(error=errors.SERVICE_IN_PREPARATION, errorCode=e.code, retryable=True)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.exception("Exception")
|
logger.exception("Exception")
|
||||||
return Client.result(error=six.text_type(e))
|
return Client.result(error=six.text_type(e))
|
||||||
|
@ -64,6 +64,7 @@ INVALID_REQUEST = 10
|
|||||||
BROWSER_NOT_SUPPORTED = 11,
|
BROWSER_NOT_SUPPORTED = 11,
|
||||||
SERVICE_IN_MAINTENANCE = 12
|
SERVICE_IN_MAINTENANCE = 12
|
||||||
SERVICE_NOT_READY = 13
|
SERVICE_NOT_READY = 13
|
||||||
|
SERVICE_IN_PREPARATION = 14
|
||||||
|
|
||||||
|
|
||||||
strings = [
|
strings = [
|
||||||
@ -80,7 +81,8 @@ strings = [
|
|||||||
_('Invalid request received'),
|
_('Invalid request received'),
|
||||||
_('Your browser is not supported. Please, upgrade it to a modern HTML5 browser like Firefox or Chrome'),
|
_('Your browser is not supported. Please, upgrade it to a modern HTML5 browser like Firefox or Chrome'),
|
||||||
_('The requested service is in maintenance mode'),
|
_('The requested service is in maintenance mode'),
|
||||||
_('The service is not ready.\nPlease, try again in a few moments.')
|
_('The service is not ready.\nPlease, try again in a few moments.'),
|
||||||
|
_('Preparing service')
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user