summaryrefslogtreecommitdiffstats
path: root/pyload/config/convert.py
diff options
context:
space:
mode:
authorGravatar RaNaN <Mast3rRaNaN@hotmail.de> 2013-07-17 11:50:15 +0200
committerGravatar RaNaN <Mast3rRaNaN@hotmail.de> 2013-07-17 11:50:15 +0200
commita3dfd09a8d560f6e6591de2e1de95e82ed2ddce3 (patch)
treec3ebfd206a532a91300e69ac04c6229abf615ba5 /pyload/config/convert.py
parentfixed last commit (diff)
downloadpyload-a3dfd09a8d560f6e6591de2e1de95e82ed2ddce3.tar.xz
improved inputTypes, config api
Diffstat (limited to 'pyload/config/convert.py')
-rw-r--r--pyload/config/convert.py38
1 files changed, 38 insertions, 0 deletions
diff --git a/pyload/config/convert.py b/pyload/config/convert.py
new file mode 100644
index 000000000..f25f6a7ba
--- /dev/null
+++ b/pyload/config/convert.py
@@ -0,0 +1,38 @@
+
+from pyload.Api import Input, InputType
+from pyload.utils import decode, to_bool
+
+# Maps old config formats to new values
+input_dict = {
+ "int": InputType.Int,
+ "bool": InputType.Bool,
+ "time": InputType.Time,
+ "file": InputType.File,
+ "folder": InputType.Folder
+}
+
+
+def to_input(typ):
+ """ Converts old config format to input type"""
+ return input_dict.get(typ, InputType.Text)
+
+
+def from_string(value, typ=None):
+ """ cast value to given type, unicode for strings """
+
+ # value is no string
+ if not isinstance(value, basestring):
+ return value
+
+ value = decode(value)
+
+ if typ == InputType.Int:
+ return int(value)
+ elif typ == InputType.Bool:
+ return to_bool(value)
+ elif typ == InputType.Time:
+ if not value: value = "0:00"
+ if not ":" in value: value += ":00"
+ return value
+ else:
+ return value \ No newline at end of file