def enable(self): log.debug('Stats plugin enabled') self.core = component.get('Core') self.stats = {} self.count = {} self.intervals = [1, 5, 30, 300] self.last_update = {} t = time.time() for i in self.intervals: self.stats[i] = {} self.last_update[i] = t self.count[i] = 0 self.config = configmanager.ConfigManager('stats.conf', DEFAULT_PREFS) self.saved_stats = configmanager.ConfigManager('stats.totals', DEFAULT_TOTALS) if self.totals == {}: self.totals.update(self.saved_stats.config) self.length = self.config['length'] # self.stats = get_key(self.saved_stats, 'stats') or {} self.stats_keys = ['peer.num_peers_half_open', 'dht.dht_node_cache'] self.add_stats('upload_rate', 'download_rate', 'dht_nodes', 'dht_cache_nodes', 'dht_torrents', 'num_peers', 'num_connections') self.update_stats() self.update_timer = LoopingCall(self.update_stats) self.update_timer.start(self.config['update_interval']) self.save_timer = LoopingCall(self.save_stats) self.save_timer.start(60)
def __init__(self, parent, initial_tab=None): QtGui.QDialog.__init__( self, parent, QtCore.Qt.WindowTitleHint | QtCore.Qt.WindowSystemMenuHint) self.setAttribute(QtCore.Qt.WA_DeleteOnClose) self.setupUi(self) self.core__label_test_active_port.setFixedWidth(self._small_icon_size) self.ui_config = configmanager.ConfigManager("qtui.conf") self.core_config = None self.plugins = None self.enabled_plugins = None # load languages self.ui__language.addItem(_("Default"), None) for locale_name in pkg_resources.resource_listdir("deluge", "i18n"): locale_name = locale_name[:-3] locale = QtCore.QLocale(locale_name) if locale != QtCore.QLocale.c(): lang_name = locale.languageToString(locale.language()) if "_" in locale_name: lang_name = "%s (%s)" % ( lang_name, locale.countryToString(locale.country())) self.ui__language.addItem(lang_name, locale_name) # load styles # self.ui__style.addItem(_("Default"), None) # for style_name in QtGui.QStyleFactory.keys(): # self.ui__style.addItem(style_name, style_name) if initial_tab: self.list_categories.setCurrentRow( self.stack_categories.indexOf( getattr(self, "page_" + initial_tab)))
def __init__(self): super(DelugeWeb, self).__init__("DelugeWeb") self.config = configmanager.ConfigManager("web.conf", CONFIG_DEFAULTS) # Check to see if a configuration from the web interface prior to 1.2 # exists and convert it over. if os.path.exists(configmanager.get_config_dir("webui06.conf")): old_config = configmanager.ConfigManager("webui06.conf") if old_config.config: # we have an old config file here to handle so we should move # all the values across to the new config file, and then remove # it. for key in OLD_CONFIG_KEYS: if key in old_config: self.config[key] = old_config[key] # We need to base64 encode the passwords since json can't handle # them otherwise. from base64 import encodestring self.config["old_pwd_md5"] = encodestring( old_config["pwd_md5"]) self.config["old_pwd_salt"] = encodestring( old_config["pwd_salt"]) # Save our config and if it saved successfully then rename the # old configuration file. if self.config.save(): config_dir = os.path.dirname(old_config.config_file) backup_path = os.path.join(config_dir, 'web.conf.old') os.rename(old_config.config_file, backup_path) del old_config self.socket = None self.top_level = TopLevel() self.site = server.Site(self.top_level) self.interface = self.config["interface"] self.port = self.config["port"] self.https = self.config["https"] self.pkey = self.config["pkey"] self.cert = self.config["cert"] self.base = self.config["base"] self.web_api = WebApi() self.auth = Auth() # Initalize the plugins self.plugins = PluginManager()
def __init__(self, parent=None): QtGui.QDialog.__init__( self, parent, QtCore.Qt.WindowTitleHint | QtCore.Qt.WindowSystemMenuHint) self.setAttribute(QtCore.Qt.WA_DeleteOnClose) self.setupUi(self) self.ui_config = configmanager.ConfigManager("qtui.conf") self.host_config = configmanager.ConfigManager("hostlist.conf.1.2") self.button_connect = QtGui.QPushButton( _("&Connect"), self, default=True, clicked=self.on_button_connect_clicked) self.button_disconnect = QtGui.QPushButton( _("&Disconnect"), self, clicked=self.on_button_disconnect_clicked) self.button_box.addButton(self.button_connect, QtGui.QDialogButtonBox.ActionRole) self.button_box.addButton(self.button_disconnect, QtGui.QDialogButtonBox.ActionRole) self.check_autoconnect.setChecked(bool(self.ui_config["autoconnect"])) self.check_autostart.setChecked(self.ui_config["autostart_localhost"]) self.check_do_not_show.setChecked( not self.ui_config["show_connection_manager_on_start"]) HeightFixItemDelegate.install(self.tree_hosts) self.tree_hosts.setHeaderLabels([_("Host"), _("Version")]) self.tree_hosts.addTopLevelItems( [HostItem(*args) for args in self.host_config["hosts"]]) self.tree_hosts.itemSelectionChanged.connect(self._update_buttons) self.tree_hosts.model().dataChanged.connect(self._update_buttons) header = self.tree_hosts.header() header.setMinimumSectionSize(header.fontMetrics().width('M') * 8) header.setResizeMode(0, QtGui.QHeaderView.Stretch) header.setResizeMode(1, QtGui.QHeaderView.ResizeToContents) header.setMovable(False) try: self.tree_hosts.setCurrentItem( (host for host in self.hosts() if host.is_connected()).next()) except StopIteration: if self.tree_hosts.topLevelItemCount(): self.tree_hosts.setCurrentItem(self.tree_hosts.topLevelItem(0)) WindowStateMixin.__init__(self, "connection_dialog")
def __init__(self, parent, new_version): QtGui.QDialog.__init__(self, parent) self.setAttribute(QtCore.Qt.WA_DeleteOnClose) self.setupUi(self) self.ui_config = configmanager.ConfigManager("qtui.conf") self.buttonBox.addButton(_("&Goto Website"), QtGui.QDialogButtonBox.AcceptRole) self.labelCurrentVersion.setText(deluge.common.get_version()) self.labelAvailableVersion.setText(new_version)
def _start_thin(self): host_config = configmanager.ConfigManager("hostlist.conf.1.2", self.default_host_config) if self.ui_config["autoconnect"]: for host in host_config["hosts"]: if host[0] == self.ui_config["autoconnect_host_id"]: self.connect(host, autostart=self.ui_config["autostart_localhost"]) if self.ui_config["show_connection_manager_on_start"]: from .connection_dialog import ConnectionDialog ConnectionDialog(component.get("MainWindow")).show()
def enable(self): log.debug("Stats plugin enabled") self.core = component.get("Core") self.stats ={} self.count = {} self.intervals = [1, 5, 30, 300] self.last_update = {} t = time.time() for i in self.intervals: self.stats[i] = {} self.last_update[i] = t self.count[i] = 0 self.config = configmanager.ConfigManager("stats.conf", DEFAULT_PREFS) self.saved_stats = configmanager.ConfigManager("stats.totals", DEFAULT_TOTALS) if self.totals == {}: self.totals.update(self.saved_stats.config) self.length = self.config["length"] #self.stats = get_key(self.saved_stats, "stats") or {} self.stats_keys = [] self.add_stats( 'upload_rate', 'download_rate', 'num_connections', 'dht_nodes', 'dht_cache_nodes', 'dht_torrents', 'num_peers', ) self.update_stats() self.update_timer = LoopingCall(self.update_stats) self.update_timer.start(self.config["update_interval"]) self.save_timer = LoopingCall(self.save_stats) self.save_timer.start(60)
def __init__(self, parent=None): QtGui.QTreeWidget.__init__(self, parent) component.Component.__init__(self, "FilterView", interval=2) HeightFixItemDelegate.install(self) self.items_by_cat = {} self.filters = {} self.ui_config = configmanager.ConfigManager("qtui.conf") self.itemSelectionChanged.connect(self.on_itemSelectionChanged)
def __init__(self, options=None, daemon=True): """ Setup the DelugeWeb server. Args: options (argparse.Namespace): The web server options. daemon (bool): If True run web server as a separate daemon process (starts a twisted reactor). If False shares the process and twisted reactor from WebUI plugin or tests. """ component.Component.__init__(self, 'DelugeWeb', depend=['Web']) self.config = configmanager.ConfigManager( 'web.conf', defaults=CONFIG_DEFAULTS, file_version=2 ) self.config.run_converter((0, 1), 2, self._migrate_config_1_to_2) self.config.register_set_function('language', self._on_language_changed) self.socket = None self.top_level = TopLevel() self.interface = self.config['interface'] self.port = self.config['port'] self.https = self.config['https'] self.pkey = self.config['pkey'] self.cert = self.config['cert'] self.base = self.config['base'] if options: self.interface = ( options.interface if options.interface is not None else self.interface ) self.port = options.port if options.port else self.port self.base = options.base if options.base else self.base if options.ssl: self.https = True elif options.no_ssl: self.https = False if self.base != '/': # Strip away slashes and serve on the base path as well as root path self.top_level.putChild(self.base.strip('/'), self.top_level) setup_translation() # Remove twisted version number from 'server' http-header for security reasons server.version = 'TwistedWeb' self.site = server.Site(self.top_level) self.web_api = WebApi() self.web_utils = WebUtils() self.auth = Auth(self.config) self.daemon = daemon # Initialize the plugins self.plugins = PluginManager()
def start_webapi(self, arg): self.webserver_listen_port = 8999 config_defaults = deluge.ui.web.server.CONFIG_DEFAULTS.copy() config_defaults['port'] = self.webserver_listen_port self.config = configmanager.ConfigManager('web.conf', config_defaults) self.deluge_web = DelugeWeb(daemon=False) host = list(self.deluge_web.web_api.hostlist.config['hosts'][0]) host[2] = self.listen_port self.deluge_web.web_api.hostlist.config['hosts'][0] = tuple(host) self.host_id = host[0] self.deluge_web.start()
def __init__(self, window_state_variable=None): self.__ui_config = configmanager.ConfigManager("qtui.conf") self.window_state_variable = window_state_variable or self.objectName() try: state = self.__ui_config[self.window_state_variable] except KeyError: pass else: if "geometry" in state: self.restoreGeometry( QtCore.QByteArray.fromBase64(state["geometry"])) for key, widget in self._widgetsWithState(): if key in state: widget.restoreState( QtCore.QByteArray.fromBase64(state[key]))
def __init__(self, args): from deluge import configmanager self.ui_config = configmanager.ConfigManager("qtui.conf", self.default_ui_config) # if self.ui_config["style"] and '-style' not in args: # QtGui.QApplication.setStyle(self.ui_config["style"]) app = QtGui.QApplication(args, applicationName="Deluge", quitOnLastWindowClosed=False) import qt4reactor qt4reactor.install() from twisted.internet import reactor self.locale_dir = pkg_resources.resource_filename("deluge", "i18n") from ui_tools import IconLoader app.setWindowIcon(IconLoader.themeIcon("deluge")) self.ui_config.register_set_function("language", self.on_language_change, apply_now=True) from .tracker_icons import TrackerIcons from deluge.ui.sessionproxy import SessionProxy from .connection_manager import ConnectionManager from .main_window import MainWindow from .plugin_manager import PluginManager TrackerIcons() SessionProxy() PluginManager() connection_manager = ConnectionManager() main_window = MainWindow() main_window.show() app.aboutToQuit.connect(self.on_quit) reactor.callLater(0, connection_manager.first_time) reactor.run() # calls app.exec_()
def enable(self): self.config = deluge.configmanager.ConfigManager("streaming.conf", DEFAULT_PREFS) try: session = component.get("Core").session settings = session.get_settings() settings['prioritize_partial_pieces'] = True session.set_settings(settings) except AttributeError: logger.warning('Unable to exclude partial pieces') self.fsr = FileServeResource() resource = Resource() resource.putChild('file', self.fsr) if self.config['allow_remote']: resource.putChild('stream', StreamResource(username=self.config['remote_username'], password=self.config['remote_password'], client=self)) base_resource = Resource() base_resource.putChild('streaming', resource) self.site = server.Site(base_resource) self.torrent_handler = TorrentHandler(self.config) plugin_manager = component.get("CorePluginManager") logger.warning('plugins %s' % (plugin_manager.get_enabled_plugins(), )) self.base_url = 'http' if self.config['serve_method'] == 'standalone': if self.config['use_ssl'] and self.check_ssl(): # use default deluge (or webui), input custom if self.config['ssl_source'] == 'daemon': web_config = configmanager.ConfigManager("web.conf", {"pkey": "ssl/daemon.pkey", "cert": "ssl/daemon.cert"}) context = ServerContextFactory(configmanager.get_config_dir(web_config['cert']), configmanager.get_config_dir(web_config['pkey'])) elif self.config['ssl_source'] == 'custom': context = ServerContextFactory(self.config['ssl_cert_path'], self.config['ssl_priv_key_path']) try: self.listening = reactor.listenSSL(self.config['port'], self.site, context, interface=self.config['ip']) except: self.listening = reactor.listenSSL(self.config['port'], self.site, context, interface='0.0.0.0') self.base_url += 's' else: try: self.listening = reactor.listenTCP(self.config['port'], self.site, interface=self.config['ip']) except: self.listening = reactor.listenTCP(self.config['port'], self.site, interface='0.0.0.0') port = self.config['port'] ip = self.config['ip'] elif self.config['serve_method'] == 'webui' and self.check_webui(): # this webserver is fubar plugin_manager = component.get("CorePluginManager") webui_plugin = plugin_manager['WebUi'].plugin webui_plugin.server.top_level.putChild('streaming', resource) port = webui_plugin.server.port ip = getattr(webui_plugin.server, 'interface', None) or self.config['ip'] if webui_plugin.server.https: self.base_url += 's' else: raise NotImplementedError() self.base_url += '://' if ':' in ip: self.base_url += ip else: self.base_url += '%s:%s' % (ip, port)
def __init__(self): QtGui.QMainWindow.__init__(self) component.Component.__init__(self, "MainWindow", interval=3) self.ui_config = configmanager.ConfigManager("qtui.conf") self.core_config = {} self.setupUi(self) WindowStateMixin.__init__(self, "main_window") self.tree_filters.filter_changed.connect(self.tree_torrents.set_filter) self.tree_torrents.selection_changed.connect(self.set_torrent_ids) self.tree_torrents.selection_changed.connect( self.tabs_details.set_torrent_ids) self.tree_torrents.selection_changed.connect( self.tabs_details.tree_peers.set_torrent_ids) self.tree_torrents.selection_changed.connect( self.tabs_details.tree_files.set_torrent_ids) self.tree_torrents.selection_changed.connect( self.tabs_details.tab_options.set_torrent_ids) # action groups and states self.torrent_actions = QtGui.QActionGroup(self, exclusive=False, enabled=False) for name, widget in self.__dict__.iteritems(): if name.startswith("action_torrent_"): self.torrent_actions.addAction(widget) elif name.startswith("menu_torrent_"): self.torrent_actions.addAction(widget.menuAction()) self.global_actions = QtGui.QActionGroup(self, exclusive=False, enabled=False) for action in (self.action_add_torrent, self.action_quit_daemon): self.global_actions.addAction(action) self.menu_torrent.menuAction().setVisible(False) # notification area icon self.popup_menu_tray_mini = QtGui.QMenu() self.popup_menu_tray_mini.addActions( [self.action_show, self.action_quit]) self.tray_icon = QtGui.QSystemTrayIcon( QtGui.qApp.windowIcon(), toolTip=QtGui.qApp.applicationName(), activated=self.on_tray_icon_activated) self.tray_icon.setContextMenu(self.popup_menu_tray_mini) self.tray_icon.show() # dynamic menus self.menu_columns.addActions(self.tree_torrents.header().actions()) self.menu_tabs.addActions(self.tabs_details.tabBar().actions()) # action setup (note: some connections are already done in designer) self.action_show_toolbar.setChecked(not self.toolbar.isHidden()) self.action_show_sidebar.setChecked(not self.tree_filters.isHidden()) self.action_show_statusbar.setChecked(not self.statusbar.isHidden()) self.upload_speed_actions = ConfigActionList( "max_upload_speed", self.ui_config["tray_upload_speed_list"], self, _("KiB/s"), _("Set Maximum Upload Speed"), 60000) self.download_speed_actions = ConfigActionList( "max_download_speed", self.ui_config["tray_download_speed_list"], self, _("KiB/s"), _("Set Maximum Download Speed"), 60000) self.max_connections_actions = ConfigActionList( "max_connections_global", self.ui_config["connection_limit_list"], self, "", _("Set Maximum Connections"), 9999) self.menu_download_speed.addActions( self.download_speed_actions.actions()) self.menu_upload_speed.addActions(self.upload_speed_actions.actions()) self.menu_max_connections.addActions( self.max_connections_actions.actions()) self.torrent_upload_speed_actions = None self.torrent_download_speed_actions = None self.torrent_max_connections_actions = None # deluge events self.ui_config.register_set_function("show_rate_in_title", self.on_showRateInTitle_change, apply_now=False) self.ui_config.register_set_function("classic_mode", self.on_classicMode_change, apply_now=True) client.register_event_handler( "NewVersionAvailableEvent", lambda: QtCore.QMetaObject.invokeMethod( self, "on_client_newVersionAvailable", QtCore.Qt.AutoConnection )) client.register_event_handler("TorrentFinishedEvent", self.on_client_torrentFinished)
def enable(self): self.config = configmanager.ConfigManager('web_plugin.conf', DEFAULT_PREFS) if self.config['enabled']: self.start_server()
def __init__(self): component.Component.__init__(self, "ConnectionManager") self._started_classic = False self.ui_config = configmanager.ConfigManager("qtui.conf")
def enable(self): self.config = configmanager.ConfigManager("web_plugin.conf", DEFAULT_PREFS) self.server = None if self.config['enabled']: self.start()
def enable(self): log.debug('Stats plugin enabled') self.core = component.get('Core') self.stats = {} self.count = {} self.intervals = [1, 5, 30, 300] self.last_update = {} t = time.time() for i in self.intervals: self.stats[i] = {} self.last_update[i] = t self.count[i] = 0 self.config = configmanager.ConfigManager('stats.conf', DEFAULT_PREFS) self.saved_stats = configmanager.ConfigManager('stats.totals', DEFAULT_TOTALS) if self.totals == {}: self.totals.update(self.saved_stats.config) self.length = self.config['length'] # self.stats = get_key(self.saved_stats, 'stats') or {} # keys needed from core.get_session_status self.stat_keys = [ 'upload_rate', 'download_rate', 'dht.dht_nodes', 'dht.dht_node_cache', 'dht.dht_torrents', 'peer.num_peers_connected', 'peer.num_peers_half_open', ] # collected statistics and functions to get them self.stat_getters = { 'upload_rate': lambda s: s['upload_rate'], 'download_rate': lambda s: s['download_rate'], 'dht_nodes': lambda s: s['dht.dht_nodes'], 'dht_cache_nodes': lambda s: s['dht.dht_node_cache'], 'dht_torrents': lambda s: s['dht.dht_torrents'], 'num_peers': lambda s: s['peer.num_peers_connected'], 'num_connections': lambda s: s['peer.num_peers_connected'] + s[ 'peer.num_peers_half_open'], } # initialize stats object for key in self.stat_getters.keys(): for i in self.intervals: if key not in self.stats[i]: self.stats[i][key] = [] self.update_stats() self.update_timer = LoopingCall(self.update_stats) self.update_timer.start(self.config['update_interval']) self.save_timer = LoopingCall(self.save_stats) self.save_timer.start(60)