def __init__( self, wait_shutdown, logger = None ): self.logger = logger or logging.getLogger( __name__ ) self._wait_shutdown = wait_shutdown self._control = Control() self._control.start()
class FrontendI(PyUpManager.Frontend): def __init__( self, wait_shutdown, logger = None ): self.logger = logger or logging.getLogger( __name__ ) self._wait_shutdown = wait_shutdown self._control = Control() self._control.start() def upload(self, hostName, fileToUploadPath, remoteFilePath, accountsIdList, priority, current=None ): self.logger.debug( "Recibida peticion de subida del fichero '%s' mediante Ice", fileToUploadPath ) result = self._control.upload( hostName, fileToUploadPath, remoteFilePath, accounts_id_list = accountsIdList, priority = priority ) return result def info(self, current=None ): self.logger.debug( "Recibida peticion de enviar el estado de las subidas mediante Ice" ) control_state_to_ice_state = { JobStateEnum.completed: PyUpManager.UploadState.completed, JobStateEnum.error: PyUpManager.UploadState.error, JobStateEnum.canceled: PyUpManager.UploadState.canceled, JobStateEnum.active: PyUpManager.UploadState.active, JobStateEnum.wait: PyUpManager.UploadState.wait } info_list = [] for x in self._control.info(): s = PyUpManager.Info() s.id = x[ InfoEnum.id ] s.service = x[ InfoEnum.servicio ] s.filePath = x[ InfoEnum.fichero ] s.state = control_state_to_ice_state[ x[ InfoEnum.estado ] ] s.progress = x[ InfoEnum.progreso ] s.priority = ':'.join( map( str, x[ InfoEnum.prioridad ] ) ) s.accounts = x[ InfoEnum.cuentas ] info_list.append( s ) return info_list def modify(self, current=None ): pass def shutdown(self, whenFinish, current=None ): self.logger.debug( "Recibida peticion de apagar el demonio mediante Ice" ) self._control.shutdown( al_terminar = whenFinish ) self._wait_shutdown.release() def addAccount( self, host_name, user, password, current=None ): self.logger.debug( "Recibida peticion de insertar una nueva cuenta '%s' mediante Ice", '{}:{}'.format( host_name, user ) ) return self._control.addAccount( host_name, user, password ) def delAccount( self, host_name, user, current=None ): self.logger.debug( "Recibida peticion de eliminar la cuenta '%s' mediante Ice", '{}:{}'.format( host_name, user ) ) return self._control.delAccount( host_name, user ) def listAccounts( self, current=None ): self.logger.debug( "Recibida peticion de listar las cuentas actuales mediante Ice" ) accounts_ice_list = [] for x in self._control.listAccounts(): s = PyUpManager.AccountInfo() s.host = x[ AccountEnum.host ] s.user = x[ AccountEnum.user ] accounts_ice_list.append( s ) return accounts_ice_list