Browse Source

Merge branch 'refs/heads/techmunk-2235' into develop

pull/2092/merge
Ruud 12 years ago
parent
commit
99efcce4d0
  1. 49
      libs/synchronousdeluge/client.py

49
libs/synchronousdeluge/client.py

@ -1,4 +1,5 @@
import os import os
import platform
from collections import defaultdict from collections import defaultdict
from itertools import imap from itertools import imap
@ -23,22 +24,48 @@ class DelugeClient(object):
self._request_counter = 0 self._request_counter = 0
def _get_local_auth(self): def _get_local_auth(self):
xdg_config = os.path.expanduser(os.environ.get("XDG_CONFIG_HOME", "~/.config")) auth_file = ""
config_home = os.path.join(xdg_config, "deluge")
auth_file = os.path.join(config_home, "auth")
username = password = "" username = password = ""
with open(auth_file) as fd: if platform.system() in ('Windows', 'Microsoft'):
for line in fd: appDataPath = os.environ.get("APPDATA")
if not appDataPath:
import _winreg
hkey = _winreg.OpenKey(_winreg.HKEY_CURRENT_USER, "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders")
appDataReg = _winreg.QueryValueEx(hkey, "AppData")
appDataPath = appDataReg[0]
_winreg.CloseKey(hkey)
auth_file = os.path.join(appDataPath, "deluge", "auth")
else:
from xdg.BaseDirectory import save_config_path
try:
auth_file = os.path.join(save_config_path("deluge"), "auth")
except OSError, e:
return username, password
if os.path.exists(auth_file):
for line in open(auth_file):
if line.startswith("#"): if line.startswith("#"):
# This is a comment line
continue
line = line.strip()
try:
lsplit = line.split(":")
except Exception, e:
continue
if len(lsplit) == 2:
username, password = lsplit
elif len(lsplit) == 3:
username, password, level = lsplit
else:
continue continue
auth = line.split(":") if username == "localclient":
if len(auth) >= 2 and auth[0] == "localclient": return (username, password)
username, password = auth[0], auth[1]
break
return username, password return ("", "")
def _create_module_method(self, module, method): def _create_module_method(self, module, method):
fullname = "{0}.{1}".format(module, method) fullname = "{0}.{1}".format(module, method)

Loading…
Cancel
Save