From e1baccf1ec914563d3b2b845906cce024e7cd3b1 Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Tue, 13 Jan 2015 23:14:50 +0100 Subject: Replace 'except' with 'except Exception' --- module/plugins/container/LinkList.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'module/plugins/container/LinkList.py') diff --git a/module/plugins/container/LinkList.py b/module/plugins/container/LinkList.py index c6173ad73..69461249e 100644 --- a/module/plugins/container/LinkList.py +++ b/module/plugins/container/LinkList.py @@ -23,7 +23,7 @@ class LinkList(Container): def decrypt(self, pyfile): try: file_enc = codecs.lookup(self.getConfig("encoding")).name - except: + except Exception: file_enc = "utf-8" file_name = fs_encode(pyfile.url) @@ -64,7 +64,7 @@ class LinkList(Container): try: txt = open(file_name, 'wb') txt.close() - except: + except Exception: self.logWarning(_("LinkList could not be cleared")) for name, links in packages.iteritems(): -- cgit v1.2.3 From 64b48b5cae505aa0bab310687cf2f6c9f48057f1 Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Fri, 23 Jan 2015 00:51:00 +0100 Subject: Improve container __pattern__ --- module/plugins/container/LinkList.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'module/plugins/container/LinkList.py') diff --git a/module/plugins/container/LinkList.py b/module/plugins/container/LinkList.py index 69461249e..9c76c4341 100644 --- a/module/plugins/container/LinkList.py +++ b/module/plugins/container/LinkList.py @@ -8,9 +8,9 @@ from module.utils import fs_encode class LinkList(Container): __name__ = "LinkList" - __version__ = "0.12" + __version__ = "0.13" - __pattern__ = r'.+\.txt' + __pattern__ = r'.+\.txt$' __config__ = [("clear", "bool", "Clear Linklist after adding", False), ("encoding", "string", "File encoding (default utf-8)", "")] -- cgit v1.2.3 From cb9e67a5437ddfafd6a93f5a208b9faf3f2d5575 Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Thu, 29 Jan 2015 15:56:57 +0100 Subject: Some file encoding fixup + optimizations --- module/plugins/container/LinkList.py | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) (limited to 'module/plugins/container/LinkList.py') diff --git a/module/plugins/container/LinkList.py b/module/plugins/container/LinkList.py index 9c76c4341..cff1b9915 100644 --- a/module/plugins/container/LinkList.py +++ b/module/plugins/container/LinkList.py @@ -8,11 +8,12 @@ from module.utils import fs_encode class LinkList(Container): __name__ = "LinkList" - __version__ = "0.13" + __type__ = "container" + __version__ = "0.14" __pattern__ = r'.+\.txt$' - __config__ = [("clear", "bool", "Clear Linklist after adding", False), - ("encoding", "string", "File encoding (default utf-8)", "")] + __config__ = [("clear" , "bool" , "Clear Linklist after adding" , False), + ("encoding", "string", "File encoding (default utf-8)", "" )] __description__ = """Read link lists in txt format""" __license__ = "GPLv3" @@ -22,38 +23,42 @@ class LinkList(Container): def decrypt(self, pyfile): try: - file_enc = codecs.lookup(self.getConfig("encoding")).name - except Exception: - file_enc = "utf-8" + encoding = codecs.lookup(self.getConfig("encoding")).name - file_name = fs_encode(pyfile.url) + except Exception: + encoding = "utf-8" - txt = codecs.open(file_name, 'r', file_enc) - links = txt.readlines() + file = fs_encode(pyfile.url.strip()) + txt = codecs.open(file, 'r', encoding) + links = txt.readlines() curPack = "Parsed links from %s" % pyfile.name packages = {curPack:[],} for link in links: link = link.strip() + if not link: continue if link.startswith(";"): continue + if link.startswith("[") and link.endswith("]"): # new package curPack = link[1:-1] packages[curPack] = [] continue + packages[curPack].append(link) + txt.close() # empty packages fix delete = [] - for key,value in packages.iteritems(): + for key, value in packages.iteritems(): if not value: delete.append(key) @@ -62,8 +67,9 @@ class LinkList(Container): if self.getConfig("clear"): try: - txt = open(file_name, 'wb') + txt = open(file, 'wb') txt.close() + except Exception: self.logWarning(_("LinkList could not be cleared")) -- cgit v1.2.3 From 4722e1f6a0c5978617de52e1ec4611e5d6067142 Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Tue, 3 Feb 2015 00:22:10 +0100 Subject: Use method pop to remove item from dict --- module/plugins/container/LinkList.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'module/plugins/container/LinkList.py') diff --git a/module/plugins/container/LinkList.py b/module/plugins/container/LinkList.py index cff1b9915..86c5f88e7 100644 --- a/module/plugins/container/LinkList.py +++ b/module/plugins/container/LinkList.py @@ -63,7 +63,7 @@ class LinkList(Container): delete.append(key) for key in delete: - del packages[key] + packages.pop(key, None) if self.getConfig("clear"): try: -- cgit v1.2.3 From 193cb8dbe1b24c24fb919461f16b2215e85da739 Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Tue, 3 Feb 2015 16:09:13 +0100 Subject: Update container plugins --- module/plugins/container/LinkList.py | 28 ++++++++++------------------ 1 file changed, 10 insertions(+), 18 deletions(-) (limited to 'module/plugins/container/LinkList.py') diff --git a/module/plugins/container/LinkList.py b/module/plugins/container/LinkList.py index 86c5f88e7..ccb9b2fa3 100644 --- a/module/plugins/container/LinkList.py +++ b/module/plugins/container/LinkList.py @@ -12,8 +12,8 @@ class LinkList(Container): __version__ = "0.14" __pattern__ = r'.+\.txt$' - __config__ = [("clear" , "bool" , "Clear Linklist after adding" , False), - ("encoding", "string", "File encoding (default utf-8)", "" )] + __config__ = [("flush" , "bool" , "Flush list after adding", False ), + ("encoding", "string", "File encoding" , "utf-8")] __description__ = """Read link lists in txt format""" __license__ = "GPLv3" @@ -28,14 +28,12 @@ class LinkList(Container): except Exception: encoding = "utf-8" - file = fs_encode(pyfile.url.strip()) - txt = codecs.open(file, 'r', encoding) - links = txt.readlines() - curPack = "Parsed links from %s" % pyfile.name - + file = fs_encode(pyfile.url.strip()) + txt = codecs.open(file, 'r', encoding) + curPack = "Parsed links from %s" % pyfile.name packages = {curPack:[],} - for link in links: + for link in txt.readlines(): link = link.strip() if not link: @@ -55,23 +53,17 @@ class LinkList(Container): txt.close() # empty packages fix - - delete = [] - for key, value in packages.iteritems(): if not value: - delete.append(key) - - for key in delete: - packages.pop(key, None) + packages.pop(key, None) - if self.getConfig("clear"): + if self.getConfig("flush"): try: txt = open(file, 'wb') txt.close() - except Exception: - self.logWarning(_("LinkList could not be cleared")) + except IOError: + self.logWarning(_("Failed to flush list")) for name, links in packages.iteritems(): self.packages.append((name, links, name)) -- cgit v1.2.3 From c61412841c8ea6c456f7d3472166d81132b56e95 Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Thu, 19 Feb 2015 16:02:32 +0100 Subject: [LinkList] Rename to TXT --- module/plugins/container/LinkList.py | 69 ------------------------------------ 1 file changed, 69 deletions(-) delete mode 100644 module/plugins/container/LinkList.py (limited to 'module/plugins/container/LinkList.py') diff --git a/module/plugins/container/LinkList.py b/module/plugins/container/LinkList.py deleted file mode 100644 index ccb9b2fa3..000000000 --- a/module/plugins/container/LinkList.py +++ /dev/null @@ -1,69 +0,0 @@ -# -*- coding: utf-8 -*- - -import codecs - -from module.plugins.Container import Container -from module.utils import fs_encode - - -class LinkList(Container): - __name__ = "LinkList" - __type__ = "container" - __version__ = "0.14" - - __pattern__ = r'.+\.txt$' - __config__ = [("flush" , "bool" , "Flush list after adding", False ), - ("encoding", "string", "File encoding" , "utf-8")] - - __description__ = """Read link lists in txt format""" - __license__ = "GPLv3" - __authors__ = [("spoob", "spoob@pyload.org"), - ("jeix", "jeix@hasnomail.com")] - - - def decrypt(self, pyfile): - try: - encoding = codecs.lookup(self.getConfig("encoding")).name - - except Exception: - encoding = "utf-8" - - file = fs_encode(pyfile.url.strip()) - txt = codecs.open(file, 'r', encoding) - curPack = "Parsed links from %s" % pyfile.name - packages = {curPack:[],} - - for link in txt.readlines(): - link = link.strip() - - if not link: - continue - - if link.startswith(";"): - continue - - if link.startswith("[") and link.endswith("]"): - # new package - curPack = link[1:-1] - packages[curPack] = [] - continue - - packages[curPack].append(link) - - txt.close() - - # empty packages fix - for key, value in packages.iteritems(): - if not value: - packages.pop(key, None) - - if self.getConfig("flush"): - try: - txt = open(file, 'wb') - txt.close() - - except IOError: - self.logWarning(_("Failed to flush list")) - - for name, links in packages.iteritems(): - self.packages.append((name, links, name)) -- cgit v1.2.3