Fix the way the client auth file is found and processed to match the defaults in the deluge clients.
This commit is contained in:
@@ -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,47 @@ 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
|
continue
|
||||||
|
|
||||||
auth = line.split(":")
|
if len(lsplit) == 2:
|
||||||
if len(auth) >= 2 and auth[0] == "localclient":
|
username, password = lsplit
|
||||||
username, password = auth[0], auth[1]
|
elif len(lsplit) == 3:
|
||||||
break
|
username, password, level = lsplit
|
||||||
|
else:
|
||||||
|
continue
|
||||||
|
|
||||||
return username, password
|
if username == "localclient":
|
||||||
|
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)
|
||||||
|
|||||||
Reference in New Issue
Block a user