def update_statusbars(self): # Update the topbar string self.screen.topbar = "{!status!}Deluge %s Console - " % deluge.common.get_version( ) if client.connected(): info = client.connection_info() self.screen.topbar += "%s@%s:%s" % (info[2], info[0], info[1]) else: self.screen.topbar += "Not Connected" # Update the bottombar string self.screen.bottombar = "{!status!}C: %s" % self.connections if self.config["max_connections_global"] > -1: self.screen.bottombar += " (%s)" % self.config[ "max_connections_global"] self.screen.bottombar += " D: %s" % self.download if self.config["max_download_speed"] > -1: self.screen.bottombar += " (%s " % self.config[ "max_download_speed"] + _("KiB/s") + ")" self.screen.bottombar += " U: %s" % self.upload if self.config["max_upload_speed"] > -1: self.screen.bottombar += " (%s " % self.config[ "max_upload_speed"] + _("KiB/s") + ")" if self.config["dht"]: self.screen.bottombar += " " + _("DHT") + ": %s" % self.dht self.screen.refresh()
def update_statusbars(self): # Update the topbar string self.screen.topbar = "{!status!}Deluge %s Console - " % deluge.common.get_version() if client.connected(): info = client.connection_info() self.screen.topbar += "%s@%s:%s" % (info[2], info[0], info[1]) else: self.screen.topbar += "Not Connected" # Update the bottombar string self.screen.bottombar = "{!status!}C: %s" % self.connections if self.config["max_connections_global"] > -1: self.screen.bottombar += " (%s)" % self.config["max_connections_global"] self.screen.bottombar += " D: %s" % self.download if self.config["max_download_speed"] > -1: self.screen.bottombar += " (%s " % self.config["max_download_speed"] + _("KiB/s") + ")" self.screen.bottombar += " U: %s" % self.upload if self.config["max_upload_speed"] > -1: self.screen.bottombar += " (%s " % self.config["max_upload_speed"] + _("KiB/s") + ")" if self.config["dht"]: self.screen.bottombar += " " + _("DHT") + ": %s" % self.dht self.screen.refresh()
def update_statusbars(self): # Update the topbar string self.topbar = '{!status!}Deluge %s Console - ' % deluge.common.get_version() if client.connected(): info = client.connection_info() connection_info = '' # Client name if info[2] == 'localclient': connection_info += '{!white,blue!}%s' else: connection_info += '{!green,blue,bold!}%s' # Hostname if info[0] == '127.0.0.1': connection_info += '{!white,blue,bold!}@{!white,blue!}%s' else: connection_info += '{!white,blue,bold!}@{!red,blue,bold!}%s' # Port if info[1] == DEFAULT_PREFS['daemon_port']: connection_info += '{!white,blue!}:%s' else: connection_info += '{!status!}:%s' # Change color back to normal, just in case connection_info += '{!status!}' self.topbar += connection_info % (info[2], info[0], info[1]) else: self.topbar += 'Not Connected' # Update the bottombar string self.bottombar = '{!status!}C: {!white,blue!}%s{!status!}' % self.connections if self.config['max_connections_global'] > -1: self.bottombar += ' (%s)' % self.config['max_connections_global'] if self.download != '0.0 KiB': self.bottombar += ' D: {!magenta,blue,bold!}%s{!status!}' % self.download else: self.bottombar += ' D: {!white,blue!}%s{!status!}' % self.download if self.config['max_download_speed'] > -1: self.bottombar += ' (%s ' % self.config['max_download_speed'] + _('KiB/s') + ')' if self.upload != '0.0 KiB': self.bottombar += ' U: {!green,blue,bold!}%s{!status!}' % self.upload else: self.bottombar += ' U: {!white,blue!}%s{!status!}' % self.upload if self.config['max_upload_speed'] > -1: self.bottombar += ' (%s ' % self.config['max_upload_speed'] + _('KiB/s') + ')' if self.config['dht']: self.bottombar += ' ' + _('DHT') + ': {!white,blue!}%s{!status!}' % self.dht self.bottombar += ' ' + _('IP {!white,blue!}%s{!status!}') % ( self.external_ip if self.external_ip else _('n/a'))
def update_statusbars(self): # Update the topbar string self.topbar = "{!status!}Deluge %s Console - " % deluge.common.get_version() if client.connected(): info = client.connection_info() connection_info = "" #Client name if info[2] == "localclient": connection_info += "{!white,blue!}%s" else: connection_info += "{!green,blue,bold!}%s" #Hostname if info[0] == "127.0.0.1": connection_info += "{!white,blue,bold!}@{!white,blue!}%s" else: connection_info += "{!white,blue,bold!}@{!red,blue,bold!}%s" #Port if info[1] == DEFAULT_PREFS["daemon_port"]: connection_info += "{!white,blue!}:%s" else: connection_info += "{!status!}:%s" #Change color back to normal, just in case connection_info += "{!status!}" self.topbar += connection_info % (info[2], info[0], info[1]) else: self.topbar += "Not Connected" # Update the bottombar string self.bottombar = "{!status!}C: {!white,blue!}%s{!status!}" % self.connections if self.config["max_connections_global"] > -1: self.bottombar += " (%s)" % self.config["max_connections_global"] if self.download != "0.0 KiB": self.bottombar += " D: {!magenta,blue,bold!}%s{!status!}" % self.download else: self.bottombar += " D: {!white,blue!}%s{!status!}" % self.download if self.config["max_download_speed"] > -1: self.bottombar += " (%s " % self.config["max_download_speed"] + _("KiB/s") + ")" if self.upload != "0.0 KiB": self.bottombar += " U: {!green,blue,bold!}%s{!status!}" % self.upload else: self.bottombar += " U: {!white,blue!}%s{!status!}" % self.upload if self.config["max_upload_speed"] > -1: self.bottombar += " (%s " % self.config["max_upload_speed"] + _("KiB/s") + ")" if self.config["dht"]: self.bottombar += " " + _("DHT") + ": {!white,blue!}%s{!status!}" % self.dht
def get_host_status(self, host_id): """Gets the current status (online/offline) of the host Args: host_id (str): The host id to check status of. Returns: tuple: A tuple of strings (host_id, status, version). """ status_offline = (host_id, 'Offline', '') def on_connect(result, c, host_id): """Successfully connected to a daemon""" def on_info(info, c): c.disconnect() return host_id, 'Online', info def on_info_fail(reason, c): c.disconnect() return status_offline return c.daemon.info().addCallback(on_info, c).addErrback(on_info_fail, c) def on_connect_failed(reason, host_id): """Connection to daemon failed""" log.debug('Host status failed for %s: %s', host_id, reason) return status_offline try: host_id, host, port, user = self.get_host_info(host_id) except ValueError: log.warning('Problem getting host_id info from hostlist') return status_offline try: ip = gethostbyname(host) except gaierror as ex: log.error('Error resolving host %s to ip: %s', host, ex.args[1]) return status_offline host_conn_info = (ip, port, 'localclient' if not user and host in LOCALHOST else user) if client.connected() and host_conn_info == client.connection_info(): # Currently connected to host_id daemon. def on_info(info, host_id): log.debug('Client connected, query info: %s', info) return host_id, 'Connected', info return client.daemon.info().addCallback(on_info, host_id) else: # Attempt to connect to daemon with host_id details. c = Client() d = c.connect(host, port, skip_authentication=True) d.addCallback(on_connect, c, host_id) d.addErrback(on_connect_failed, host_id) return d
def cb_data_init(self, data): self.dialog = None self._config = None info = client.connection_info() self._daemon = "%s@%s:%s" % (info[2], info[0], info[1]) self.timestamp = data[0] self.label_data = data[1] self.label_data[ID_ALL]["name"] = _(ID_ALL) self.label_data[ID_NONE]["name"] = _(ID_NONE) self._do_load()
def on_button_startdaemon_clicked(self, widget): log.debug("on_button_startdaemon_clicked") if self.liststore.iter_n_children(None) < 1: # There is nothing in the list, so lets create a localhost entry self.add_host(DEFAULT_HOST, DEFAULT_PORT, *get_localhost_auth()) # ..and start the daemon. self.start_daemon(DEFAULT_PORT, deluge.configmanager.get_config_dir()) return paths = self.hostlist.get_selection().get_selected_rows()[1] if len(paths) < 1: return status = self.liststore[paths[0]][HOSTLIST_COL_STATUS] host = self.liststore[paths[0]][HOSTLIST_COL_HOST] port = self.liststore[paths[0]][HOSTLIST_COL_PORT] user = self.liststore[paths[0]][HOSTLIST_COL_USER] password = self.liststore[paths[0]][HOSTLIST_COL_PASS] if host not in ("127.0.0.1", "localhost"): return if status in ("Online", "Connected"): # We need to stop this daemon # Call the shutdown method on the daemon def on_daemon_shutdown(d): # Update display to show change self.__update_list() if client.connected() and client.connection_info() == (host, port, user): client.daemon.shutdown().addCallback(on_daemon_shutdown) elif user and password: # Create a new client instance c = deluge.ui.client.Client() def on_connect(d, c): log.debug("on_connect") c.daemon.shutdown().addCallback(on_daemon_shutdown) c.connect(host, port, user, password).addCallback(on_connect, c) elif status == "Offline": self.start_daemon(port, deluge.configmanager.get_config_dir()) reactor.callLater(2.0, self.__update_list)
def on_button_startdaemon_clicked(self, widget): log.debug("on_button_startdaemon_clicked") if self.liststore.iter_n_children(None) < 1: # There is nothing in the list, so lets create a localhost entry self.add_host(DEFAULT_HOST, DEFAULT_PORT, *get_localhost_auth()) # ..and start the daemon. self.start_daemon( DEFAULT_PORT, deluge.configmanager.get_config_dir() ) return paths = self.hostlist.get_selection().get_selected_rows()[1] if len(paths) < 1: return status = self.liststore[paths[0]][HOSTLIST_COL_STATUS] host = self.liststore[paths[0]][HOSTLIST_COL_HOST] port = self.liststore[paths[0]][HOSTLIST_COL_PORT] user = self.liststore[paths[0]][HOSTLIST_COL_USER] password = self.liststore[paths[0]][HOSTLIST_COL_PASS] if host not in ("127.0.0.1", "localhost"): return if status in (_("Online"), _("Connected")): # We need to stop this daemon # Call the shutdown method on the daemon def on_daemon_shutdown(d): # Update display to show change self.__update_list() if client.connected() and client.connection_info() == (host, port, user): client.daemon.shutdown().addCallback(on_daemon_shutdown) elif user and password: # Create a new client instance c = deluge.ui.client.Client() def on_connect(d, c): log.debug("on_connect") c.daemon.shutdown().addCallback(on_daemon_shutdown) c.connect(host, port, user, password).addCallback(on_connect, c) elif status == _("Offline"): self.start_daemon(port, deluge.configmanager.get_config_dir()) reactor.callLater(2.0, self.__update_list)
def on_button_startdaemon_clicked(self, widget): log.debug('on_button_startdaemon_clicked') if not self.liststore.iter_n_children(None): # There is nothing in the list, so lets create a localhost entry try: self.hostlist.add_default_host() except ValueError as ex: log.error('Error adding default host: %s', ex) else: self.start_daemon(DEFAULT_PORT, get_config_dir()) finally: return paths = self.treeview.get_selection().get_selected_rows()[1] if len(paths): __, host, port, user, password, status, __ = self.liststore[ paths[0]] else: return if host not in LOCALHOST: return def on_daemon_status_change(result): """Daemon start/stop callback""" reactor.callLater(0.7, self._update_host_status) if status in ('Online', 'Connected'): # Button will stop the daemon if status is online or connected. def on_connect(d, c): """Client callback to call daemon shutdown""" c.daemon.shutdown().addCallback(on_daemon_status_change) if client.connected() and (host, port, user) == client.connection_info(): client.daemon.shutdown().addCallback(on_daemon_status_change) elif user and password: c = Client() c.connect(host, port, user, password).addCallback(on_connect, c) else: # Otherwise button will start the daemon. self.start_daemon(port, get_config_dir())
def _finish_init(self, result): log.debug("Resuming initialization...") try: info = client.connection_info() self.daemon = "%s@%s:%s" % (info[2], info[0], info[1]) self._load_config() self._update_store(result) self.initialized = True self._load_extensions() log.info("%s initialized", self.__class__.__name__) except: log.error("Error initializing %s", self.__class__.__name__) raise twisted.internet.reactor.callLater(0, self._update_loop)
def on_button_startdaemon_clicked(self, widget): log.debug('on_button_startdaemon_clicked') if not self.liststore.iter_n_children(None): # There is nothing in the list, so lets create a localhost entry try: self.hostlist.add_default_host() except ValueError as ex: log.error('Error adding default host: %s', ex) else: self.start_daemon(DEFAULT_PORT, get_config_dir()) finally: return paths = self.treeview.get_selection().get_selected_rows()[1] if len(paths): __, host, port, user, password, status, __ = self.liststore[paths[0]] else: return if host not in LOCALHOST: return def on_daemon_status_change(result): """Daemon start/stop callback""" reactor.callLater(0.7, self._update_host_status) if status in ('Online', 'Connected'): # Button will stop the daemon if status is online or connected. def on_connect(d, c): """Client callback to call daemon shutdown""" c.daemon.shutdown().addCallback(on_daemon_status_change) if client.connected() and (host, port, user) == client.connection_info(): client.daemon.shutdown().addCallback(on_daemon_status_change) elif user and password: c = Client() c.connect(host, port, user, password).addCallback(on_connect, c) else: # Otherwise button will start the daemon. self.start_daemon(port, get_config_dir())
def __update_list(self): """Updates the host status""" if not hasattr(self, "liststore"): # This callback was probably fired after the window closed return def on_connect(result, c, host_id): # Return if the deferred callback was done after the dialog was closed if not self.running: return row = self.__get_host_row(host_id) def on_info(info, c): if not self.running: return if row: row[HOSTLIST_COL_STATUS] = "Online" row[HOSTLIST_COL_VERSION] = info self.__update_buttons() c.disconnect() def on_info_fail(reason, c): if not self.running: return if row: row[HOSTLIST_COL_STATUS] = "Offline" self.__update_buttons() c.disconnect() d = c.daemon.info() d.addCallback(on_info, c) d.addErrback(on_info_fail, c) def on_connect_failed(reason, host_id): if not self.running: return row = self.__get_host_row(host_id) if row: row[HOSTLIST_COL_STATUS] = "Offline" self.__update_buttons() for row in self.liststore: host_id = row[HOSTLIST_COL_ID] host = row[HOSTLIST_COL_HOST] port = row[HOSTLIST_COL_PORT] user = row[HOSTLIST_COL_USER] password = row[HOSTLIST_COL_PASS] if client.connected() and \ (host, port, "localclient" if not user and host in ("127.0.0.1", "localhost") else user) == client.connection_info(): def on_info(info): if not self.running: return row[HOSTLIST_COL_VERSION] = info self.__update_buttons() row[HOSTLIST_COL_STATUS] = "Connected" client.daemon.info().addCallback(on_info) continue # Create a new Client instance c = deluge.ui.client.Client() d = c.connect(host, port, user, password) d.addCallback(on_connect, c, host_id) d.addErrback(on_connect_failed, host_id)
def update_statusbars(self): # Update the topbar string self.topbar = "{!status!}Deluge %s Console - " % deluge.common.get_version( ) if client.connected(): info = client.connection_info() connection_info = "" #Client name if info[2] == "localclient": connection_info += "{!white,blue!}%s" else: connection_info += "{!green,blue,bold!}%s" #Hostname if info[0] == "127.0.0.1": connection_info += "{!white,blue,bold!}@{!white,blue!}%s" else: connection_info += "{!white,blue,bold!}@{!red,blue,bold!}%s" #Port if info[1] == DEFAULT_PREFS["daemon_port"]: connection_info += "{!white,blue!}:%s" else: connection_info += "{!status!}:%s" #Change color back to normal, just in case connection_info += "{!status!}" self.topbar += connection_info % (info[2], info[0], info[1]) else: self.topbar += "Not Connected" # Update the bottombar string self.bottombar = "{!status!}C: {!white,blue!}%s{!status!}" % self.connections if self.config["max_connections_global"] > -1: self.bottombar += " (%s)" % self.config["max_connections_global"] if self.download != "0.0 KiB": self.bottombar += " D: {!magenta,blue,bold!}%s{!status!}" % self.download else: self.bottombar += " D: {!white,blue!}%s{!status!}" % self.download if self.config["max_download_speed"] > -1: self.bottombar += " (%s " % self.config["max_download_speed"] + _( "KiB/s") + ")" if self.upload != "0.0 KiB": self.bottombar += " U: {!green,blue,bold!}%s{!status!}" % self.upload else: self.bottombar += " U: {!white,blue!}%s{!status!}" % self.upload if self.config["max_upload_speed"] > -1: self.bottombar += " (%s " % self.config["max_upload_speed"] + _( "KiB/s") + ")" if self.config["dht"]: self.bottombar += " " + _( "DHT") + ": {!white,blue!}%s{!status!}" % self.dht
def __update_buttons(self): """ Updates the buttons states. """ if len(self.liststore) == 0: # There is nothing in the list self.builder.get_object("button_startdaemon").set_sensitive(True) self.builder.get_object("button_connect").set_sensitive(False) self.builder.get_object("button_removehost").set_sensitive(False) self.builder.get_object("image_startdaemon").set_from_stock( gtk.STOCK_EXECUTE, gtk.ICON_SIZE_MENU) self.builder.get_object("label_startdaemon").set_text("_Start Daemon") model, row = self.hostlist.get_selection().get_selected() if not row: self.builder.get_object("button_edithost").set_sensitive(False) return self.builder.get_object("button_edithost").set_sensitive(True) # Get some values about the selected host status = model[row][HOSTLIST_COL_STATUS] host = model[row][HOSTLIST_COL_HOST] port = model[row][HOSTLIST_COL_PORT] user = model[row][HOSTLIST_COL_USER] passwd = model[row][HOSTLIST_COL_PASS] log.debug("Status: %s", status) # Check to see if we have a localhost entry selected localhost = False if host in ("127.0.0.1", "localhost"): localhost = True # Make sure buttons are sensitive at start self.builder.get_object("button_startdaemon").set_sensitive(True) self.builder.get_object("button_connect").set_sensitive(True) self.builder.get_object("button_removehost").set_sensitive(True) # See if this is the currently connected host if status == _("Connected"): # Display a disconnect button if we're connected to this host self.builder.get_object("button_connect").set_label("gtk-disconnect") self.builder.get_object("button_removehost").set_sensitive(False) else: self.builder.get_object("button_connect").set_label("gtk-connect") if status == _("Offline") and not localhost: self.builder.get_object("button_connect").set_sensitive(False) # Check to see if the host is online if status == _("Connected") or status == _("Online"): self.builder.get_object("image_startdaemon").set_from_stock( gtk.STOCK_STOP, gtk.ICON_SIZE_MENU) self.builder.get_object("label_startdaemon").set_text( _("_Stop Daemon")) # Update the start daemon button if the selected host is localhost if localhost and status == _("Offline"): # The localhost is not online self.builder.get_object("image_startdaemon").set_from_stock( gtk.STOCK_EXECUTE, gtk.ICON_SIZE_MENU) self.builder.get_object("label_startdaemon").set_text( _("_Start Daemon")) if client.connected() and (host, port, user) == client.connection_info(): # If we're connected, we can stop the dameon self.builder.get_object("button_startdaemon").set_sensitive(True) elif user and passwd: # In this case we also have all the info to shutdown the dameon self.builder.get_object("button_startdaemon").set_sensitive(True) else: # Can't stop non localhost daemons, specially without the necessary info self.builder.get_object("button_startdaemon").set_sensitive(False) # Make sure label is displayed correctly using mnemonics self.builder.get_object("label_startdaemon").set_use_underline(True)
def is_connected(self): actual_username = "******" if ( not self.username and self.is_local()) else self.username return client.connected() and client.connection_info() == ( self.host, self.port, actual_username)
def is_connected(self): actual_username = "******" if (not self.username and self.is_local()) else self.username return client.connected() and client.connection_info() == (self.host, self.port, actual_username)
def update_statusbars(self): # Update the topbar string self.topbar = '{!status!}Deluge %s Console - ' % deluge.common.get_version( ) if client.connected(): info = client.connection_info() connection_info = '' # Client name if info[2] == 'localclient': connection_info += '{!white,blue!}%s' else: connection_info += '{!green,blue,bold!}%s' # Hostname if info[0] == '127.0.0.1': connection_info += '{!white,blue,bold!}@{!white,blue!}%s' else: connection_info += '{!white,blue,bold!}@{!red,blue,bold!}%s' # Port if info[1] == DEFAULT_PREFS['daemon_port']: connection_info += '{!white,blue!}:%s' else: connection_info += '{!status!}:%s' # Change color back to normal, just in case connection_info += '{!status!}' self.topbar += connection_info % (info[2], info[0], info[1]) else: self.topbar += 'Not Connected' # Update the bottombar string self.bottombar = '{!status!}C: {!white,blue!}%s{!status!}' % self.connections if self.config['max_connections_global'] > -1: self.bottombar += ' (%s)' % self.config['max_connections_global'] if self.download != '0.0 KiB': self.bottombar += ' D: {!magenta,blue,bold!}%s{!status!}' % self.download else: self.bottombar += ' D: {!white,blue!}%s{!status!}' % self.download if self.config['max_download_speed'] > -1: self.bottombar += ' (%s ' % self.config['max_download_speed'] + _( 'KiB/s') + ')' if self.upload != '0.0 KiB': self.bottombar += ' U: {!green,blue,bold!}%s{!status!}' % self.upload else: self.bottombar += ' U: {!white,blue!}%s{!status!}' % self.upload if self.config['max_upload_speed'] > -1: self.bottombar += ' (%s ' % self.config['max_upload_speed'] + _( 'KiB/s') + ')' if self.config['dht']: self.bottombar += ' ' + _( 'DHT') + ': {!white,blue!}%s{!status!}' % self.dht self.bottombar += ' ' + _('IP {!white,blue!}%s{!status!}') % ( self.external_ip if self.external_ip else _('n/a'))