diff options
author | Walter Purcaro <vuolter@users.noreply.github.com> | 2015-07-31 02:21:35 +0200 |
---|---|---|
committer | Walter Purcaro <vuolter@users.noreply.github.com> | 2015-07-31 02:21:35 +0200 |
commit | 092112b44af84c7a59b1fa2cfff5c5875e778a8f (patch) | |
tree | 455f8192b0da79f3f325481a60feb239cc33d37d /module | |
parent | Fix https://github.com/pyload/pyload/issues/1624 (diff) | |
download | pyload-092112b44af84c7a59b1fa2cfff5c5875e778a8f.tar.xz |
Fix https://github.com/pyload/pyload/issues/1625
Diffstat (limited to 'module')
-rw-r--r-- | module/plugins/hooks/ExtractArchive.py | 26 | ||||
-rw-r--r-- | module/plugins/internal/Crypter.py | 8 | ||||
-rw-r--r-- | module/plugins/internal/Hoster.py | 66 | ||||
-rw-r--r-- | module/plugins/internal/Plugin.py | 33 |
4 files changed, 65 insertions, 68 deletions
diff --git a/module/plugins/hooks/ExtractArchive.py b/module/plugins/hooks/ExtractArchive.py index 62139ccc5..a71ec0e98 100644 --- a/module/plugins/hooks/ExtractArchive.py +++ b/module/plugins/hooks/ExtractArchive.py @@ -355,7 +355,9 @@ class ExtractArchive(Addon): files_ids = [(fname, fid, fout) for fname, fid, fout in files_ids \ if fname not in archive.get_delete_files()] self.log_debug("Extracted files: %s" % new_files) - self.set_permissions(new_files) + + for file in new_files: + self.set_permissions(file) for filename in new_files: file = fs_encode(fs_join(os.path.dirname(archive.filename), filename)) @@ -584,25 +586,3 @@ class ExtractArchive(Addon): except IOError, e: self.log_error(e) - - - def set_permissions(self, files): - for f in files: - if not os.path.exists(f): - continue - - try: - if self.pyload.config.get("permission", "change_file"): - if os.path.isfile(f): - os.chmod(f, int(self.pyload.config.get("permission", "file"), 8)) - - elif os.path.isdir(f): - os.chmod(f, int(self.pyload.config.get("permission", "folder"), 8)) - - if self.pyload.config.get("permission", "change_dl") and os.name != "nt": - uid = getpwnam(self.pyload.config.get("permission", "user"))[2] - gid = getgrnam(self.pyload.config.get("permission", "group"))[2] - os.chown(f, uid, gid) - - except Exception, e: - self.log_warning(_("Setting User and Group failed"), e) diff --git a/module/plugins/internal/Crypter.py b/module/plugins/internal/Crypter.py index 13d82c2ea..0fdec559d 100644 --- a/module/plugins/internal/Crypter.py +++ b/module/plugins/internal/Crypter.py @@ -84,19 +84,19 @@ class Crypter(Hoster): self.pyload.api.setPackageData(pid, {'password': package_password}) #: Workaround to do not break API addPackage method - setFolder = lambda x: self.pyload.api.setPackageData(pid, {'folder': x or ""}) + set_folder = lambda x: self.pyload.api.setPackageData(pid, {'folder': x or ""}) if use_subfolder: if not subfolder_per_package: - setFolder(package_folder) + set_folder(package_folder) self.log_debug("Set package %(name)s folder to: %(folder)s" % {'name': name, 'folder': folder}) elif not folder_per_package or name is not folder: if not folder: folder = urlparse.urlparse(name).path.split("/")[-1] - setFolder(safe_filename(folder)) + set_folder(safe_filename(folder)) self.log_debug("Set package %(name)s folder to: %(folder)s" % {'name': name, 'folder': folder}) elif folder_per_package: - setFolder(None) + set_folder(None) diff --git a/module/plugins/internal/Hoster.py b/module/plugins/internal/Hoster.py index 1b96f1201..c54adf4b3 100644 --- a/module/plugins/internal/Hoster.py +++ b/module/plugins/internal/Hoster.py @@ -47,7 +47,7 @@ def create_getInfo(klass): class Hoster(Plugin): __name__ = "Hoster" __type__ = "hoster" - __version__ = "0.12" + __version__ = "0.13" __status__ = "testing" __pattern__ = r'^unmatchable$' @@ -179,7 +179,7 @@ class Hoster(Plugin): self.pyfile.setStatus("starting") - self.log_debug("PROCESS URL " + self.pyfile.url) + self.log_debug("PROCESS URL " + self.pyfile.url, "PLUGIN VERSION %s" % self.__version__) return self.process(self.pyfile) @@ -190,12 +190,6 @@ class Hoster(Plugin): raise NotImplementedError - def get_chunk_count(self): - if self.chunk_limit <= 0: - return self.pyload.config.get("download", "chunks") - return min(self.pyload.config.get("download", "chunks"), self.chunk_limit) - - def set_reconnect(self, reconnect): reconnect = bool(reconnect) @@ -385,29 +379,27 @@ class Hoster(Plugin): self.pyfile.setStatus("downloading") - download_folder = self.pyload.config.get("general", "download_folder") - location = fs_join(download_folder, self.pyfile.package().folder) + download_folder = self.pyload.config.get("general", "download_folder") + download_location = fs_join(download_folder, self.pyfile.package().folder) - if not exists(location): + if not exists(download_location): try: - os.makedirs(location, int(self.pyload.config.get("permission", "folder"), 8)) - - if self.pyload.config.get("permission", "change_dl") and os.name != "nt": - uid = pwd.getpwnam(self.pyload.config.get("permission", "user"))[2] - gid = grp.getgrnam(self.pyload.config.get("permission", "group"))[2] - os.chown(location, uid, gid) + os.makedirs(download_location) except Exception, e: self.fail(e) - #: Convert back to unicode - location = fs_decode(location) - name = safe_filename(self.pyfile.name) + self.set_permissions(download_location) + location = fs_decode(download_location) + name = safe_filename(urlparse.urlparse(self.pyfile.name).path.split('/')[-1] or self.pyfile.name) filename = os.path.join(location, name) self.pyload.hookManager.dispatchEvent("download_start", self.pyfile, url, filename) + if self.pyfile.abort: + self.abort() + try: newname = self.req.httpDownload(url, filename, get=get, post=post, ref=ref, cookies=cookies, chunks=self.get_chunk_count(), resume=self.resume_download, @@ -415,32 +407,26 @@ class Hoster(Plugin): finally: self.pyfile.size = self.req.size - if newname: - newname = urlparse.urlparse(newname).path.split('/')[-1].split(' filename*=')[0] #@TODO: Remove in 0.4.10 - - if disposition and newname is not name: - self.log_info(_("%(name)s saved as %(newname)s") % {'name': name, 'newname': newname}) - self.pyfile.name = newname - filename = os.path.join(location, newname) + #@TODO: Recheck in 0.4.10 + if disposition: + finalname = urlparse.urlparse(newname).path.split('/')[-1].split(' filename*=')[0] - fs_filename = fs_encode(filename) + if finalname != newname != name: + try: + os.rename(fs_join(location, newname), fs_join(location, finalname)) - if self.pyload.config.get("permission", "change_file"): - try: - os.chmod(fs_filename, int(self.pyload.config.get("permission", "file"), 8)) - except Exception, e: - self.log_warning(_("Setting file mode failed"), e) + except OSError, e: + self.log_warning(_("Error renaming `%s` to `%s`") % (newname, finalname), e) + finalname = newname - if self.pyload.config.get("permission", "change_dl") and os.name != "nt": - try: - uid = pwd.getpwnam(self.pyload.config.get("permission", "user"))[2] - gid = grp.getgrnam(self.pyload.config.get("permission", "group"))[2] - os.chown(fs_filename, uid, gid) + self.log_info(_("`%s` saved as `%s`") % (name, finalname)) + self.pyfile.name = finalname + filename = os.path.join(location, finalname) - except Exception, e: - self.log_warning(_("Setting User and Group failed"), e) + self.set_permissions(fs_encode(filename)) self.last_download = filename + return self.last_download diff --git a/module/plugins/internal/Plugin.py b/module/plugins/internal/Plugin.py index 76056c66d..70494561c 100644 --- a/module/plugins/internal/Plugin.py +++ b/module/plugins/internal/Plugin.py @@ -138,7 +138,7 @@ def chunks(iterable, size): class Plugin(object): __name__ = "Plugin" __type__ = "hoster" - __version__ = "0.19" + __version__ = "0.20" __status__ = "testing" __pattern__ = r'^unmatchable$' @@ -196,6 +196,37 @@ class Plugin(object): return self._log("critical", self.__type__, self.__name__, args) + def set_permissions(self, path): + if not os.path.exists(path): + return + + try: + if self.pyload.config.get("permission", "change_file"): + if os.path.isfile(path): + os.chmod(path, int(self.pyload.config.get("permission", "file"), 8)) + + elif os.path.isdir(path): + os.chmod(path, int(self.pyload.config.get("permission", "folder"), 8)) + + except OSError, e: + self.log_warning(_("Setting path mode failed"), e) + + try: + if os.name != "nt" and self.pyload.config.get("permission", "change_dl"): + uid = pwd.getpwnam(self.pyload.config.get("permission", "user"))[2] + gid = grp.getgrnam(self.pyload.config.get("permission", "group"))[2] + os.chown(path, uid, gid) + + except OSError, e: + self.log_warning(_("Setting owner and group failed"), e) + + + def get_chunk_count(self): + if self.chunk_limit <= 0: + return self.pyload.config.get("download", "chunks") + return min(self.pyload.config.get("download", "chunks"), self.chunk_limit) + + def set_config(self, option, value): """ Set config value for current plugin |