Changeset e99dd0 for deluge/ui/web/server.py
- Timestamp:
- 02/16/2009 12:46:16 AM (16 years ago)
- Branches:
- 2.0.x, develop, extjs4-port, master
- Children:
- 990790
- Parents:
- 5bd5db
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
deluge/ui/web/server.py
r5bd5db re99dd0 25 25 import os 26 26 import sys 27 import time 27 28 import locale 28 29 import shutil … … 49 50 from deluge.log import setupLogger, LOG as _log 50 51 from deluge.ui import common as uicommon 51 from deluge.ui.client import client 52 from deluge.ui.client import client, Client 52 53 from deluge.ui.tracker_icons import TrackerIcons 53 54 log = logging.getLogger(__name__) … … 65 66 except Exception, e: 66 67 log.error("Unable to initialize gettext/locale: %s", e) 68 69 _ = gettext.gettext 67 70 68 71 current_dir = os.path.dirname(__file__) … … 89 92 "refresh_secs": 10 90 93 } 94 95 DEFAULT_HOST = "127.0.0.1" 96 DEFAULT_PORT = 58846 97 DEFAULT_HOSTS = { 98 "hosts": [(hashlib.sha1(str(time.time())).hexdigest(), DEFAULT_HOST, DEFAULT_PORT, "", "")] 99 } 100 101 HOSTLIST_COL_ID = 0 102 HOSTLIST_COL_HOST = 1 103 HOSTLIST_COL_PORT = 2 104 HOSTLIST_COL_STATUS = 3 105 HOSTLIST_COL_USER = 4 106 HOSTLIST_COL_PASS = 5 107 HOSTLIST_COL_VERSION = 6 108 91 109 config = ConfigManager("webui06.conf", CONFIG_DEFAULTS) 110 hostlist = ConfigManager("hostlist.conf.1.2", DEFAULT_HOSTS) 92 111 93 112 def rpath(path): … … 100 119 101 120 builtins = { 102 "_": gettext.gettext,121 "_": _, 103 122 "version": common.get_version() 104 123 } … … 127 146 "web.get_torrent_info": self.get_torrent_info, 128 147 "web.add_torrents": self.add_torrents, 129 "web.login": self.login 148 "web.login": self.login, 149 "web.get_hosts": self.get_hosts 130 150 } 131 151 for entry in open(common.get_default_config_dir("auth")): … … 140 160 self.local_username = username 141 161 self.local_password = password 142 self.connect() 143 144 def connect(self, host="localhost", username=None, password=None): 162 163 def connect(self, host="localhost", port=58846, username=None, password=None): 145 164 """ 146 165 Connects the client to a daemon … … 215 234 return self._exec_remote(method, params), request_id 216 235 except Exception, e: 236 log.exception(e) 217 237 raise JSONException(e) 218 238 … … 353 373 354 374 def login(self, password): 355 """ 375 """Method to allow the webui to authenticate 356 376 """ 357 377 m = hashlib.md5() … … 362 382 return d 363 383 384 def get_hosts(self): 385 """Return the hosts in the hostlist""" 386 hosts = dict((host[0], host[:]) for host in hostlist["hosts"]) 387 388 main_deferred = Deferred() 389 def run_check(): 390 if all(map(lambda x: x[5] is not None, hosts.values())): 391 main_deferred.callback(hosts.values()) 392 393 def on_connect(result, c, host_id): 394 def on_info(info, c): 395 hosts[host_id][5] = _("Online") 396 hosts[host_id][6] = info 397 c.disconnect() 398 run_check() 399 400 def on_info_fail(reason): 401 hosts[host_id][5] = _("Offline") 402 run_check() 403 404 d = c.daemon.info() 405 d.addCallback(on_info, c) 406 d.addErrback(on_info_fail, c) 407 408 def on_connect_failed(reason, host_id): 409 print reason 410 hosts[host_id][5] = _("Offline") 411 run_check() 412 413 for host in hosts.values(): 414 host_id, host, port, user, password = host[0:5] 415 hosts[host_id].append(None) 416 hosts[host_id].append(None) 417 418 if client.connected() and (host, port, user) == client.connection_info(): 419 def on_info(info): 420 hosts[host_id][6] = info 421 run_check() 422 host[5] = _("Connected") 423 client.daemon.info().addCallback(on_info) 424 hosts[host_id] = host 425 continue 426 427 c = Client() 428 d = c.connect(host, port, user, password) 429 d.addCallback(on_connect, c, host_id) 430 d.addErrback(on_connect_failed, host_id) 431 return main_deferred 364 432 365 433 class GetText(resource.Resource):
Note:
See TracChangeset
for help on using the changeset viewer.