class StopLocalServerWorker(QtCore.QObject): """ Worker for displaying a progress dialog when closing the server """ # signals to update the progress dialog. error = QtCore.pyqtSignal(str, bool) finished = QtCore.pyqtSignal() updated = QtCore.pyqtSignal(int) def __init__(self, local_server_process): super().__init__() self._local_server_process = local_server_process self._precision = 100 # In MS self._remaining_trial = int(10 * (1000 / self._precision)) @qslot def _callbackSlot(self, *params): self._local_server_process.poll() if self._local_server_process.returncode is None and self._remaining_trial > 0: self._remaining_trial -= 1 QtCore.QTimer.singleShot(self._precision, self._callbackSlot) else: self.finished.emit() def run(self): QtCore.QTimer.singleShot(1000, self._callbackSlot) def cancel(self): return
class StopLocalServerWorker(QtCore.QObject): """ Worker for displaying a progress dialog when closing the server """ # signals to update the progress dialog. error = QtCore.pyqtSignal(str, bool) finished = QtCore.pyqtSignal() updated = QtCore.pyqtSignal(int) def __init__(self, local_server_process): super().__init__() self._local_server_process = local_server_process def run(self): precision = 1 remaining_trial = 4 / precision # 4 Seconds while remaining_trial > 0: if self._local_server_process.returncode is None: remaining_trial -= 1 self.thread().sleep(precision) else: break self.finished.emit() def cancel(self): return
class DecompressIOSWorker(QtCore.QObject): """ Thread to decompress an IOS image. :param ios_image: IOS image path :param destination_file: destination path for the decompressed IOS image """ # signals to update the progress dialog. error = QtCore.pyqtSignal(str, bool) finished = QtCore.pyqtSignal() updated = QtCore.pyqtSignal(int) def __init__(self, ios_image, destination_file): super().__init__() self._is_running = False self._ios_image = ios_image self._destination_file = destination_file def run(self): """ Thread starting point. """ self._is_running = True try: decompressIOS(self._ios_image, self._destination_file) except (zipfile.BadZipFile, zlib.error) as e: self.error.emit( "File {} is corrupted {}".format(self._ios_image, e), True) return except (OSError, MemoryError) as e: self.error.emit( "Could not decompress {}: {}".format(self._ios_image, e), True) return # IOS image has successfully been decompressed self.finished.emit() def cancel(self): """ Cancel this worker. """ if not self: return self._is_running = False
class DecompressIOSThread(QtCore.QThread): """ Thread to decompress an IOS image. :param ios_image: IOS image path :param destination_file: destination path for the decompressed IOS image """ # signals to update the progress dialog. error = QtCore.pyqtSignal(str, bool) completed = QtCore.pyqtSignal() update = QtCore.pyqtSignal(int) def __init__(self, ios_image, destination_file): QtCore.QThread.__init__(self) self._ios_image = ios_image self._destination_file = destination_file self._is_running = False def run(self): """ Thread starting point. """ self._is_running = True try: decompressIOS(self._ios_image, self._destination_file) except zipfile.BadZipFile as e: self.error.emit( "File {} is corrupted {}".format(self._ios_image, e), True) return except OSError as e: self.error.emit( "Could not decompress {}: {}".format(self._ios_image, e), True) return # IOS image has successfully been decompressed self.completed.emit() def stop(self): """ Stops this thread as soon as possible. """ self._is_running = False
class SSHConnectionThread(QtCore.QThread): error_signal = QtCore.pyqtSignal(str) connected_signal = QtCore.pyqtSignal() def __init__(self, ssh_client, parent=None): self._ssh_client = ssh_client super().__init__(parent) def run(self): port = Endpoint.find_unused_port(1000, 10000) if port is None: self.error_signal.emit( "No port available in order to create SSH tunnel") return try: self._ssh_client.transport = paramiko.Transport(( self._ssh_client.host(), self._ssh_client.ssh_port(), )) self._ssh_client.transport.set_keepalive(30) with open(self._ssh_client.ssh_key()) as f: self._ssh_client.transport.connect( username=self._ssh_client.user(), pkey=paramiko.RSAKey.from_private_key(f)) endpoint = Endpoint(("127.0.0.1", port), ("127.0.0.1", self._ssh_client._http_port), self._ssh_client.transport) endpoint.enable() self._ssh_client._endpoints[port] = endpoint except (paramiko.ssh_exception.SSHException, OSError) as e: self.error_signal.emit(str(e)) return self._ssh_client._http_port = port self.connected_signal.emit()