summaryrefslogtreecommitdiffstats
path: root/module
diff options
context:
space:
mode:
Diffstat (limited to 'module')
-rw-r--r--module/ConfigParser.py19
-rw-r--r--module/PluginThread.py3
-rw-r--r--module/PyFile.py2
-rw-r--r--module/Utils.py18
-rw-r--r--module/network/Browser.py1
-rw-r--r--module/plugins/Plugin.py17
6 files changed, 48 insertions, 12 deletions
diff --git a/module/ConfigParser.py b/module/ConfigParser.py
index 0d681551a..e3e5d103a 100644
--- a/module/ConfigParser.py
+++ b/module/ConfigParser.py
@@ -13,7 +13,6 @@ IGNORE = ("FreakshareNet", "SpeedManager")
CONF_VERSION = 1
-########################################################################
class ConfigParser:
"""
holds and manage the configuration
@@ -301,7 +300,14 @@ class ConfigParser:
#----------------------------------------------------------------------
def get(self, section, option):
"""get value"""
- return self.config[section][option]["value"]
+ val = self.config[section][option]["value"]
+ try:
+ if type(val) in (str,unicode):
+ return val.decode("utf8")
+ else:
+ return val
+ except:
+ return val
#----------------------------------------------------------------------
def set(self, section, option, value):
@@ -315,7 +321,14 @@ class ConfigParser:
#----------------------------------------------------------------------
def getPlugin(self, plugin, option):
"""gets a value for a plugin"""
- return self.plugin[plugin][option]["value"]
+ val = self.plugin[plugin][option]["value"]
+ try:
+ if type(val) in (str, unicode):
+ return val.decode("utf8")
+ else:
+ return val
+ except:
+ return val
#----------------------------------------------------------------------
def setPlugin(self, plugin, option, value):
diff --git a/module/PluginThread.py b/module/PluginThread.py
index 4c1d93af2..d5f969f80 100644
--- a/module/PluginThread.py
+++ b/module/PluginThread.py
@@ -31,6 +31,7 @@ from os.path import join, exists
from pycurl import error
+from Utils import save_join
from module.plugins.Plugin import Abort
from module.plugins.Plugin import Fail
from module.plugins.Plugin import Reconnect
@@ -153,7 +154,7 @@ class DownloadThread(PluginThread):
if self.m.core.config["general"]["skip_existing"] and \
((not pyfile.name.startswith("http:") and exists(
- join(self.m.core.config["general"]["download_folder"], pyfile.package().folder, pyfile.name)
+ save_join(self.m.core.config["general"]["download_folder"], pyfile.package().folder, pyfile.name)
)) or current):
self.m.log.info(_("Download skipped: %(name)s @ %(plugin)s") % {"name": pyfile.name,
"plugin": pyfile.plugin.__name__
diff --git a/module/PyFile.py b/module/PyFile.py
index dc6a09025..68b25fd58 100644
--- a/module/PyFile.py
+++ b/module/PyFile.py
@@ -86,7 +86,7 @@ class PyFile():
self.progress.notify = self.notifyChange
self.m.cache[int(id)] = self
-
+
def __repr__(self):
return "PyFile %s: %s@%s" % (self.id, self.name, self.pluginname)
diff --git a/module/Utils.py b/module/Utils.py
new file mode 100644
index 000000000..9cea1bab2
--- /dev/null
+++ b/module/Utils.py
@@ -0,0 +1,18 @@
+# -*- coding: utf-8 -*-
+
+""" Store all usefull functions here """
+
+import sys
+from os.path import join
+
+def save_join(*args):
+ """ joins a path, encoding aware """
+ paths = []
+ for path in args:
+ # remove : for win comp.
+ tmp = path.replace(":", "").encode(sys.getfilesystemencoding(), "replace")
+ paths.append(tmp)
+ return join(*paths)
+
+if __name__ == "__main__":
+ print save_join("test","/test2") \ No newline at end of file
diff --git a/module/network/Browser.py b/module/network/Browser.py
index e163802bb..ab0a0951d 100644
--- a/module/network/Browser.py
+++ b/module/network/Browser.py
@@ -67,6 +67,7 @@ class Browser(object):
def abortDownloads(self):
self.http.abort = True
if self.dl:
+ self._size = self.dl.size
self.dl.abort = True
def httpDownload(self, url, filename, get={}, post={}, ref=True, cookies=True, chunks=1, resume=False):
diff --git a/module/plugins/Plugin.py b/module/plugins/Plugin.py
index d9ca4e5d9..0453206cd 100644
--- a/module/plugins/Plugin.py
+++ b/module/plugins/Plugin.py
@@ -42,6 +42,8 @@ from mimetypes import guess_type
from itertools import islice
+from module.Utils import save_join
+
def chunks(iterable, size):
it = iter(iterable)
item = list(islice(it, size))
@@ -308,9 +310,9 @@ class Plugin(object):
self.pyfile.size = 0
- download_folder = self.config['general']['download_folder'].decode("utf8")
+ download_folder = self.config['general']['download_folder']
- location = join(download_folder.encode(sys.getfilesystemencoding(), "replace"), self.pyfile.package().folder.replace(":", "").encode(sys.getfilesystemencoding(), "replace")) # remove : for win compability
+ location = save_join(download_folder, self.pyfile.package().folder) # remove : for win compability
if not exists(location):
makedirs(location, int(self.core.config["permission"]["folder"],8))
@@ -324,14 +326,15 @@ class Plugin(object):
except Exception,e:
self.log.warning(_("Setting User and Group failed: %s") % str(e))
- name = self.pyfile.name.encode(sys.getfilesystemencoding(), "replace")
- filename = join(location, name)
- self.req.httpDownload(url, filename, get=get, post=post, ref=ref, chunks=self.getChunkCount(), resume=self.resumeDownload)
+ name = self.pyfile.name
+ filename = save_join(location, name)
+ try:
+ self.req.httpDownload(url, filename, get=get, post=post, ref=ref, chunks=self.getChunkCount(), resume=self.resumeDownload)
+ finally:
+ self.pyfile.size = self.req.size
newname = basename(filename)
- self.pyfile.size = self.req.size
-
if newname and newname != name:
self.log.info("%(name)s saved as %(newname)s" % {"name": name, "newname": newname})
name = newname