summaryrefslogtreecommitdiffstats
path: root/pyload/config/convert.py
diff options
context:
space:
mode:
authorGravatar RaNaN <Mast3rRaNaN@hotmail.de> 2013-08-08 17:38:35 +0200
committerGravatar RaNaN <Mast3rRaNaN@hotmail.de> 2013-08-08 17:38:35 +0200
commit52f6599748ef61219112111dc5db71f3342b076d (patch)
treee3627ded64b7e98493ca1ec7bd182aaa1774252e /pyload/config/convert.py
parentMultiHosters: moved settings to addon plugins. (diff)
downloadpyload-52f6599748ef61219112111dc5db71f3342b076d.tar.xz
adapted account api to multi user, fixed http referer bug
Diffstat (limited to 'pyload/config/convert.py')
-rw-r--r--pyload/config/convert.py29
1 files changed, 29 insertions, 0 deletions
diff --git a/pyload/config/convert.py b/pyload/config/convert.py
index 7a110e0f3..59f814020 100644
--- a/pyload/config/convert.py
+++ b/pyload/config/convert.py
@@ -1,7 +1,14 @@
+# -*- coding: utf-8 -*-
+
+from gettext import gettext
+
+from new_collections import namedtuple
from pyload.Api import Input, InputType
from pyload.utils import decode, to_bool
+ConfigData = namedtuple("ConfigData", "label description input")
+
# Maps old config formats to new values
input_dict = {
"int": InputType.Int,
@@ -18,6 +25,28 @@ def to_input(typ):
return input_dict.get(typ, InputType.Text)
+def to_configdata(entry):
+ if len(entry) != 4:
+ raise ValueError("Config entry must be of length 4")
+
+ # Values can have different roles depending on the two config formats
+ conf_name, type_label, label_desc, default_input = entry
+
+ # name, label, desc, input
+ if isinstance(default_input, Input):
+ _input = default_input
+ conf_label = type_label
+ conf_desc = label_desc
+ # name, type, label, default
+ else:
+ _input = Input(to_input(type_label))
+ _input.default_value = from_string(default_input, _input.type)
+ conf_label = label_desc
+ conf_desc = ""
+
+ return conf_name, ConfigData(gettext(conf_label), gettext(conf_desc), _input)
+
+
def from_string(value, typ=None):
""" cast value to given type, unicode for strings """