From 5e493f2d3f1adac34c3a1d7e98528f759f3f4987 Mon Sep 17 00:00:00 2001 From: bendikro Date: Mon, 9 May 2016 19:38:21 +0200 Subject: [PATCH] [UI] Use a shared DEFAULT_HOSTS dict in ui/common Instead of defining a DEFAULT_HOSTS dict for each UI use a shared dict. --- deluge/ui/common.py | 8 ++++++++ deluge/ui/console/modes/connectionmanager.py | 10 ++-------- deluge/ui/web/json_api.py | 8 +------- 3 files changed, 11 insertions(+), 15 deletions(-) diff --git a/deluge/ui/common.py b/deluge/ui/common.py index 72e68b5ce..202785525 100644 --- a/deluge/ui/common.py +++ b/deluge/ui/common.py @@ -14,6 +14,7 @@ The ui common module contains methods and classes that are deemed useful for all import logging import os +import time from hashlib import sha1 as sha import deluge.configmanager @@ -30,6 +31,7 @@ log = logging.getLogger(__name__) # No need to import these, just simply use the `_()` function around a status variable. def _(message): return message + STATE_TRANSLATION = { "All": _("All"), "Active": _("Active"), @@ -50,6 +52,12 @@ TRACKER_STATUS_TRANSLATION = { } del _ +DEFAULT_HOST = "127.0.0.1" +DEFAULT_PORT = 58846 +DEFAULT_HOSTS = { + "hosts": [(sha(str(time.time())).hexdigest(), DEFAULT_HOST, DEFAULT_PORT, "", "")] +} + class TorrentInfo(object): """ diff --git a/deluge/ui/console/modes/connectionmanager.py b/deluge/ui/console/modes/connectionmanager.py index f3c5ab8f0..6c1a064b1 100644 --- a/deluge/ui/console/modes/connectionmanager.py +++ b/deluge/ui/console/modes/connectionmanager.py @@ -16,6 +16,7 @@ from collections import deque import deluge.component as component from deluge.configmanager import ConfigManager +from deluge.ui import common as uicommon from deluge.ui.client import Client, client from deluge.ui.console.modes.alltorrents import AllTorrents from deluge.ui.console.modes.basemode import BaseMode @@ -29,13 +30,6 @@ except ImportError: log = logging.getLogger(__name__) -DEFAULT_HOST = "127.0.0.1" -DEFAULT_PORT = 58846 - -DEFAULT_CONFIG = { - "hosts": [(hashlib.sha1(str(time.time())).hexdigest(), DEFAULT_HOST, DEFAULT_PORT, "", "")] -} - class ConnectionManager(BaseMode): @@ -43,7 +37,7 @@ class ConnectionManager(BaseMode): self.popup = None self.statuses = {} self.messages = deque() - self.config = ConfigManager("hostlist.conf.1.2", DEFAULT_CONFIG) + self.config = ConfigManager("hostlist.conf.1.2", uicommon.DEFAULT_HOSTS) BaseMode.__init__(self, stdscr, encoding) self.__update_statuses() self.__update_popup() diff --git a/deluge/ui/web/json_api.py b/deluge/ui/web/json_api.py index 54b07a042..205f03fd3 100644 --- a/deluge/ui/web/json_api.py +++ b/deluge/ui/web/json_api.py @@ -253,13 +253,7 @@ class JSON(resource.Resource, component.Component): log.debug("Registering method: %s", name + "." + d) self._local_methods[name + "." + d] = getattr(obj, d) -DEFAULT_HOST = "127.0.0.1" -DEFAULT_PORT = 58846 -DEFAULT_HOSTS = { - "hosts": [(hashlib.sha1(str(time.time())).hexdigest(), - DEFAULT_HOST, DEFAULT_PORT, "", "")] -} HOSTLIST_ID = 0 HOSTLIST_NAME = 1 HOSTLIST_PORT = 2 @@ -368,7 +362,7 @@ class WebApi(JSONComponent): def __init__(self): super(WebApi, self).__init__("Web", depend=["SessionProxy"]) - self.host_list = ConfigManager("hostlist.conf.1.2", DEFAULT_HOSTS) + self.host_list = ConfigManager("hostlist.conf.1.2", uicommon.DEFAULT_HOSTS) if not os.path.isfile(self.host_list.config_file): self.host_list.save() self.core_config = CoreConfig()