summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Walter Purcaro <vuolter@users.noreply.github.com> 2015-04-17 00:50:31 +0200
committerGravatar Walter Purcaro <vuolter@users.noreply.github.com> 2015-04-17 00:50:31 +0200
commit3e87db92c439a4b8378a165f42a01ba142b56a5c (patch)
tree3d2a59c665b4656396b4927e603c0424723c8e95
parentMerge branch 'stable' into 0.4.10 (diff)
downloadpyload-3e87db92c439a4b8378a165f42a01ba142b56a5c.tar.xz
Spare code cosmetics (1)
-rwxr-xr-xpyload/Core.py60
-rw-r--r--pyload/api/__init__.py24
-rw-r--r--pyload/config/Parser.py38
-rw-r--r--pyload/config/default.conf14
-rw-r--r--pyload/manager/Thread.py6
-rw-r--r--pyload/manager/thread/Server.py2
-rw-r--r--pyload/plugin/account/ZeveraCom.py5
7 files changed, 86 insertions, 63 deletions
diff --git a/pyload/Core.py b/pyload/Core.py
index 4a919b689..47cd715d3 100755
--- a/pyload/Core.py
+++ b/pyload/Core.py
@@ -475,39 +475,69 @@ class Core(object):
if self.config.get("log", "color_console"):
import colorlog
- if self.config.get("log", "color_template") == "label":
- cfmt = "%(asctime)s %(log_color)s%(bold)s%(white)s %(levelname)-8s %(reset)s %(message)s"
- clr = {'DEBUG' : "bg_cyan" ,
+ color_template = self.config.get("log", "color_template")
+ extra_clr = {}
+
+ if color_template is "mixed":
+ c_fmt = "%(log_color)s%(asctime)s %(label_log_color)s%(bold)s%(white)s %(levelname)-8s%(reset)s %(log_color)s%(message)s"
+ clr = {
+ 'DEBUG' : "cyan" ,
+ 'WARNING' : "yellow",
+ 'ERROR' : "red" ,
+ 'CRITICAL': "purple",
+ }
+ extra_clr = {
+ 'label': {
+ 'DEBUG' : "bg_cyan" ,
'INFO' : "bg_green" ,
'WARNING' : "bg_yellow",
'ERROR' : "bg_red" ,
- 'CRITICAL': "bg_purple"}
- else:
- cfmt = "%(log_color)s%(asctime)s %(levelname)-8s %(message)s"
- clr = {'DEBUG' : "cyan" ,
- 'WARNING' : "yellow",
- 'ERROR' : "red" ,
- 'CRITICAL': "purple"}
+ 'CRITICAL': "bg_purple",
+ }
+ }
+
+ elif color_template is "label":
+ c_fmt = "%(asctime)s %(log_color)s%(bold)s%(white)s %(levelname)-8s%(reset)s %(message)s"
+ clr = {
+ 'DEBUG' : "bg_cyan" ,
+ 'INFO' : "bg_green" ,
+ 'WARNING' : "bg_yellow",
+ 'ERROR' : "bg_red" ,
+ 'CRITICAL': "bg_purple",
+ }
- console_frm = colorlog.ColoredFormatter(cfmt, date_fmt, clr)
+ else:
+ c_fmt = "%(log_color)s%(asctime)s %(levelname)-8s %(message)s"
+ clr = {
+ 'DEBUG' : "cyan" ,
+ 'WARNING' : "yellow",
+ 'ERROR' : "red" ,
+ 'CRITICAL': "purple"
+ }
+
+ console_frm = colorlog.ColoredFormatter(format=c_fmt,
+ datefmt=date_fmt,
+ log_colors=clr,
+ secondary_log_colors=extra_clr)
# Set console formatter
console = logging.StreamHandler(sys.stdout)
console.setFormatter(console_frm)
self.log.addHandler(console)
- if not exists(self.config.get("log", "log_folder")):
- makedirs(self.config.get("log", "log_folder"), 0700)
+ log_folder = self.config.get("log", "log_folder")
+ if not exists(log_folder):
+ makedirs(log_folder, 0700)
# Set file handler formatter
if self.config.get("log", "file_log"):
if self.config.get("log", "log_rotate"):
- file_handler = logging.handlers.RotatingFileHandler(join(self.config.get("log", "log_folder"), 'log.txt'),
+ file_handler = logging.handlers.RotatingFileHandler(join(log_folder, 'log.txt'),
maxBytes=self.config.get("log", "log_size") * 1024,
backupCount=int(self.config.get("log", "log_count")),
encoding="utf8")
else:
- file_handler = logging.FileHandler(join(self.config.get("log", "log_folder"), 'log.txt'), encoding="utf8")
+ file_handler = logging.FileHandler(join(log_folder, 'log.txt'), encoding="utf8")
file_handler.setFormatter(fh_frm)
self.log.addHandler(file_handler)
diff --git a/pyload/api/__init__.py b/pyload/api/__init__.py
index 461c77cac..9338b5337 100644
--- a/pyload/api/__init__.py
+++ b/pyload/api/__init__.py
@@ -109,8 +109,8 @@ class Api(Iface):
item = ConfigItem()
item.name = key
item.description = data["desc"]
- item.value = str(data["value"]) if not isinstance(data["value"], basestring) else data["value"]
- item.type = data["type"]
+ item.value = str(data['value']) if not isinstance(data['value'], basestring) else data['value']
+ item.type = data['type']
items.append(item)
section.items = items
sections[sectionName] = section
@@ -120,37 +120,37 @@ class Api(Iface):
@permission(PERMS.SETTINGS)
- def getConfigValue(self, category, option, section="core"):
+ def getConfigValue(self, section, option, section="core"):
"""Retrieve config value.
- :param category: name of category, or plugin
+ :param section: name of section, or plugin
:param option: config option
:param section: 'plugin' or 'core'
:return: config value as string
"""
if section == "core":
- value = self.core.config.get(category, option)
+ value = self.core.config.get(section, option)
else:
- value = self.core.config.getPlugin(category, option)
+ value = self.core.config.getPlugin(section, option)
return str(value)
@permission(PERMS.SETTINGS)
- def setConfigValue(self, category, option, value, section="core"):
+ def setConfigValue(self, section, option, value, section="core"):
"""Set new config value.
- :param category:
+ :param section:
:param option:
:param value: new config value
:param section: 'plugin' or 'core
"""
- self.core.addonManager.dispatchEvent("config-changed", category, option, value, section)
+ self.core.addonManager.dispatchEvent("config-changed", section, option, value, section)
if section == "core":
- self.core.config[category][option] = value
+ self.core.config.set(section, option, value)
if option in ("limit_speed", "max_speed"): # not so nice to update the limit
self.core.requestFactory.updateBucket()
elif section == "plugin":
- self.core.config.setPlugin(category, option, value)
+ self.core.config.setPlugin(section, option, value)
@permission(PERMS.SETTINGS)
@@ -895,7 +895,7 @@ class Api(Iface):
accs = self.core.accountManager.getAccountInfos(False, refresh)
for group in accs.values():
accounts = [AccountInfo(acc["validuntil"], acc["login"], acc["options"], acc["valid"],
- acc["trafficleft"], acc["maxtraffic"], acc["premium"], acc["type"])
+ acc["trafficleft"], acc["maxtraffic"], acc["premium"], acc['type'])
for acc in group]
return accounts or []
diff --git a/pyload/config/Parser.py b/pyload/config/Parser.py
index bad512a5f..ed81d041c 100644
--- a/pyload/config/Parser.py
+++ b/pyload/config/Parser.py
@@ -91,8 +91,8 @@ class ConfigParser(object):
homeconf = self.parseConfig("pyload.conf")
if "username" in homeconf["remote"]:
if "password" in homeconf["remote"]:
- self.oldRemoteData = {"username": homeconf["remote"]["username"]["value"],
- "password": homeconf["remote"]["username"]["value"]}
+ self.oldRemoteData = {"username": homeconf["remote"]["username"]['value'],
+ "password": homeconf["remote"]["username"]['value']}
del homeconf["remote"]["password"]
del homeconf["remote"]["username"]
self.updateValues(homeconf, self.config)
@@ -159,7 +159,7 @@ class ConfigParser(object):
typ, none, option = content.strip().rpartition(" ")
value = value.strip()
- typ = typ.strip()
+ typ = typ.strip()
if value.startswith("["):
if value.endswith("]"):
@@ -195,7 +195,7 @@ class ConfigParser(object):
continue
if option in dest[section]:
- dest[section][option]["value"] = config[section][option]["value"]
+ dest[section][option]['value'] = config[section][option]['value']
# else:
# dest[section][option] = config[section][option]
@@ -216,20 +216,20 @@ class ConfigParser(object):
for option, data in config[section].iteritems():
if option in ("desc", "outline"): continue
- if isinstance(data["value"], list):
+ if isinstance(data['value'], list):
value = "[ \n"
- for x in data["value"]:
+ for x in data['value']:
value += "\t\t" + str(x) + ",\n"
value += "\t\t]\n"
else:
- if isinstance(data["value"], basestring):
- value = data["value"] + "\n"
+ if isinstance(data['value'], basestring):
+ value = data['value'] + "\n"
else:
- value = str(data["value"]) + "\n"
+ value = str(data['value']) + "\n"
try:
- f.write('\t%s %s : "%s" = %s' % (data["type"], option, data["desc"], value))
+ f.write('\t%s %s : "%s" = %s' % (data['type'], option, data["desc"], value))
except UnicodeEncodeError:
- f.write('\t%s %s : "%s" = %s' % (data["type"], option, data["desc"], encode(value)))
+ f.write('\t%s %s : "%s" = %s' % (data['type'], option, data["desc"], encode(value)))
def cast(self, typ, value):
@@ -266,33 +266,31 @@ class ConfigParser(object):
def get(self, section, option):
"""get value"""
- value = self.config[section][option]["value"]
+ value = self.config[section][option]['value']
return decode(value)
def set(self, section, option, value):
"""set value"""
-
- value = self.cast(self.config[section][option]["type"], value)
-
- self.config[section][option]["value"] = value
+ value = self.cast(self.config[section][option]['type'], value)
+ self.config[section][option]['value'] = value
self.save()
def getPlugin(self, plugin, option):
"""gets a value for a plugin"""
- value = self.plugin[plugin][option]["value"]
+ value = self.plugin[plugin][option]['value']
return encode(value)
def setPlugin(self, plugin, option, value):
"""sets a value for a plugin"""
- value = self.cast(self.plugin[plugin][option]["type"], value)
+ value = self.cast(self.plugin[plugin][option]['type'], value)
if self.pluginCB: self.pluginCB(plugin, option, value)
- self.plugin[plugin][option]["value"] = value
+ self.plugin[plugin][option]['value'] = value
self.save()
@@ -319,7 +317,7 @@ class ConfigParser(object):
for item in config:
if item[0] in conf:
- conf[item[0]]["type"] = item[1]
+ conf[item[0]]['type'] = item[1]
conf[item[0]]["desc"] = item[2]
else:
conf[item[0]] = {
diff --git a/pyload/config/default.conf b/pyload/config/default.conf
index 453c40b4b..e07b92f68 100644
--- a/pyload/config/default.conf
+++ b/pyload/config/default.conf
@@ -21,13 +21,13 @@ webui - "Web User Interface":
str prefix : "Path Prefix" = None
log - "Log":
- bool file_log : "File Log" = True
- folder log_folder : "Folder" = Logs
- int log_count : "Count" = 5
- int log_size : "Size in kb" = 100
- bool log_rotate : "Log Rotate" = True
- bool color_console : "Colored console" = True
- label;full color_template : "Color template" = label
+ bool file_log : "File Log" = True
+ folder log_folder : "Folder" = Logs
+ int log_count : "Count" = 5
+ int log_size : "Size in kb" = 100
+ bool log_rotate : "Log Rotate" = True
+ bool color_console : "Colored console" = True
+ label;line;mixed color_template : "Color template" = mixed
general - "General":
en;de;fr;it;es;nl;sv;ru;pl;cs;sr;pt_BR language : "Language" = en
diff --git a/pyload/manager/Thread.py b/pyload/manager/Thread.py
index 015bc9ab1..e24b20d59 100644
--- a/pyload/manager/Thread.py
+++ b/pyload/manager/Thread.py
@@ -160,9 +160,9 @@ class ThreadManager(object):
if not exists(self.core.config.get("reconnect", "method")):
if exists(join(pypath, self.core.config.get("reconnect", "method"))):
- self.core.config['reconnect']['method'] = join(pypath, self.core.config.get("reconnect", "method"))
+ self.core.config.set("reconnect", "method", join(pypath, self.core.config.get("reconnect", "method")))
else:
- self.core.config['reconnect']['activated'] = False
+ self.core.config.set("reconnect", "activated", False)
self.core.log.warning(_("Reconnect script not found!"))
return
@@ -184,7 +184,7 @@ class ThreadManager(object):
reconn = Popen(self.core.config.get("reconnect", "method"), bufsize=-1, shell=True) # , stdout=subprocess.PIPE)
except Exception:
self.core.log.warning(_("Failed executing reconnect script!"))
- self.core.config['reconnect']['activated'] = False
+ self.core.config.set("reconnect", "activated", False)
self.reconnecting.clear()
if self.core.debug:
print_exc()
diff --git a/pyload/manager/thread/Server.py b/pyload/manager/thread/Server.py
index 990325f5d..83e886253 100644
--- a/pyload/manager/thread/Server.py
+++ b/pyload/manager/thread/Server.py
@@ -66,7 +66,7 @@ class WebServer(threading.Thread):
self.server = "builtin"
else:
self.core.log.info(_("Server set to threaded, due to known performance problems on windows."))
- self.core.config['webui']['server'] = "threaded"
+ self.core.config.set("webui", "server", "threaded")
self.server = "threaded"
if self.server == "threaded":
diff --git a/pyload/plugin/account/ZeveraCom.py b/pyload/plugin/account/ZeveraCom.py
index 25c2c5512..1e5eacb4c 100644
--- a/pyload/plugin/account/ZeveraCom.py
+++ b/pyload/plugin/account/ZeveraCom.py
@@ -19,11 +19,6 @@ class ZeveraCom(Account):
HOSTER_DOMAIN = "zevera.com"
- def __init__(self, manager, accounts): #@TODO: remove in 0.4.10
- self.init()
- return super(ZeveraCom, self).__init__(manager, accounts)
-
-
def init(self):
if not self.HOSTER_DOMAIN:
self.logError(_("Missing HOSTER_DOMAIN"))