From 2945a72664d4b6e8ca6b50fa8efde483edfb9723 Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Fri, 27 Jun 2014 00:59:12 +0200 Subject: Spare fixes --- module/plugins/hooks/HotFolder.py | 1 - 1 file changed, 1 deletion(-) (limited to 'module/plugins/hooks/HotFolder.py') diff --git a/module/plugins/hooks/HotFolder.py b/module/plugins/hooks/HotFolder.py index 38bcaf440..a63b314d1 100644 --- a/module/plugins/hooks/HotFolder.py +++ b/module/plugins/hooks/HotFolder.py @@ -38,7 +38,6 @@ class HotFolder(Hook): ("watch_file", "bool", "Observe link file", False), ("keep", "bool", "Keep added containers", True), ("file", "str", "Link file", "links.txt")] - __threaded__ = [] __author_name__ = "RaNaN" __author_mail__ = "RaNaN@pyload.de" -- cgit v1.2.3 From 48c0c42fd6faffc56432d5f037cd575979f180cc Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Mon, 14 Jul 2014 02:23:37 +0200 Subject: Removed all @author flags + key attributes cleanup for internal & hooks plugins --- module/plugins/hooks/HotFolder.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'module/plugins/hooks/HotFolder.py') diff --git a/module/plugins/hooks/HotFolder.py b/module/plugins/hooks/HotFolder.py index a63b314d1..bd57712af 100644 --- a/module/plugins/hooks/HotFolder.py +++ b/module/plugins/hooks/HotFolder.py @@ -13,9 +13,6 @@ You should have received a copy of the GNU General Public License along with this program; if not, see . - - @author: RaNaN - @interface-version: 0.2 """ from os import makedirs @@ -32,15 +29,19 @@ from module.plugins.Hook import Hook class HotFolder(Hook): __name__ = "HotFolder" __version__ = "0.11" - __description__ = """Observe folder and file for changes and add container and links""" + __type__ = "hook" + __config__ = [("activated", "bool", "Activated", False), ("folder", "str", "Folder to observe", "container"), ("watch_file", "bool", "Observe link file", False), ("keep", "bool", "Keep added containers", True), ("file", "str", "Link file", "links.txt")] + + __description__ = """Observe folder and file for changes and add container and links""" __author_name__ = "RaNaN" __author_mail__ = "RaNaN@pyload.de" + def setup(self): self.interval = 10 -- cgit v1.2.3 From 5060e4c6374a5116d0d8b02528f910f8c5f8bcf9 Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Tue, 15 Jul 2014 16:25:41 +0200 Subject: Fix code indentation, some bad whitespaces and missing authors + use 'not' instead 'is None' + replace __pattern__'s r" with r' + other minor cosmetics --- module/plugins/hooks/HotFolder.py | 1 - 1 file changed, 1 deletion(-) (limited to 'module/plugins/hooks/HotFolder.py') diff --git a/module/plugins/hooks/HotFolder.py b/module/plugins/hooks/HotFolder.py index bd57712af..08ef93812 100644 --- a/module/plugins/hooks/HotFolder.py +++ b/module/plugins/hooks/HotFolder.py @@ -46,7 +46,6 @@ class HotFolder(Hook): self.interval = 10 def periodical(self): - if not exists(join(self.getConfig("folder"), "finished")): makedirs(join(self.getConfig("folder"), "finished")) -- cgit v1.2.3 From ba916633f2bedb04c7358000b91aed69f52e8e43 Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Fri, 1 Aug 2014 19:35:59 +0200 Subject: Remove trailing whitespaces + remove license headers + import urllib methods directly + sort and fix key attributes + use save_join instead join + sort some import declarations + other minor code cosmetics --- module/plugins/hooks/HotFolder.py | 27 +++++---------------------- 1 file changed, 5 insertions(+), 22 deletions(-) (limited to 'module/plugins/hooks/HotFolder.py') diff --git a/module/plugins/hooks/HotFolder.py b/module/plugins/hooks/HotFolder.py index 08ef93812..4c81292e3 100644 --- a/module/plugins/hooks/HotFolder.py +++ b/module/plugins/hooks/HotFolder.py @@ -1,35 +1,18 @@ # -*- coding: utf-8 -*- -""" - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 3 of the License, - or (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, see . -""" - -from os import makedirs -from os import listdir -from os.path import exists -from os.path import join -from os.path import isfile -from shutil import move import time +from os import listdir, makedirs +from os.path import exists, isfile, join +from shutil import move + from module.plugins.Hook import Hook class HotFolder(Hook): __name__ = "HotFolder" - __version__ = "0.11" __type__ = "hook" + __version__ = "0.11" __config__ = [("activated", "bool", "Activated", False), ("folder", "str", "Folder to observe", "container"), -- cgit v1.2.3 From b0868ae6446078bacf1635dde5e4ab316b4a94cb Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Tue, 7 Oct 2014 18:57:59 +0200 Subject: New __authors__ key replaces __author_name__ and __author_mail__ + Whitespaces and EOF fixup --- module/plugins/hooks/HotFolder.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'module/plugins/hooks/HotFolder.py') diff --git a/module/plugins/hooks/HotFolder.py b/module/plugins/hooks/HotFolder.py index 4c81292e3..d38e240ca 100644 --- a/module/plugins/hooks/HotFolder.py +++ b/module/plugins/hooks/HotFolder.py @@ -21,8 +21,7 @@ class HotFolder(Hook): ("file", "str", "Link file", "links.txt")] __description__ = """Observe folder and file for changes and add container and links""" - __author_name__ = "RaNaN" - __author_mail__ = "RaNaN@pyload.de" + __authors__ = [("RaNaN", "RaNaN@pyload.de")] def setup(self): -- cgit v1.2.3 From ae7a7e66981456e5bbe2b54006d79b6f907be7a4 Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Wed, 8 Oct 2014 20:18:13 +0200 Subject: Add __license__ key attribute to plugins --- module/plugins/hooks/HotFolder.py | 1 + 1 file changed, 1 insertion(+) (limited to 'module/plugins/hooks/HotFolder.py') diff --git a/module/plugins/hooks/HotFolder.py b/module/plugins/hooks/HotFolder.py index d38e240ca..34a9ff49b 100644 --- a/module/plugins/hooks/HotFolder.py +++ b/module/plugins/hooks/HotFolder.py @@ -21,6 +21,7 @@ class HotFolder(Hook): ("file", "str", "Link file", "links.txt")] __description__ = """Observe folder and file for changes and add container and links""" + __license__ = "GPLv3" __authors__ = [("RaNaN", "RaNaN@pyload.de")] -- cgit v1.2.3 From 0eb6e7ec4a1144dcca824d8add049787d3da1762 Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Wed, 22 Oct 2014 19:44:59 +0200 Subject: Two space before function declaration --- module/plugins/hooks/HotFolder.py | 1 + 1 file changed, 1 insertion(+) (limited to 'module/plugins/hooks/HotFolder.py') diff --git a/module/plugins/hooks/HotFolder.py b/module/plugins/hooks/HotFolder.py index 34a9ff49b..688dcbf48 100644 --- a/module/plugins/hooks/HotFolder.py +++ b/module/plugins/hooks/HotFolder.py @@ -28,6 +28,7 @@ class HotFolder(Hook): def setup(self): self.interval = 10 + def periodical(self): if not exists(join(self.getConfig("folder"), "finished")): makedirs(join(self.getConfig("folder"), "finished")) -- cgit v1.2.3 From 885f8ed782e64d9e73367905e642a84d0a8999f1 Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Tue, 28 Oct 2014 04:01:38 +0100 Subject: Update __config__ --- module/plugins/hooks/HotFolder.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'module/plugins/hooks/HotFolder.py') diff --git a/module/plugins/hooks/HotFolder.py b/module/plugins/hooks/HotFolder.py index 688dcbf48..00eac266c 100644 --- a/module/plugins/hooks/HotFolder.py +++ b/module/plugins/hooks/HotFolder.py @@ -14,8 +14,7 @@ class HotFolder(Hook): __type__ = "hook" __version__ = "0.11" - __config__ = [("activated", "bool", "Activated", False), - ("folder", "str", "Folder to observe", "container"), + __config__ = [("folder", "str", "Folder to observe", "container"), ("watch_file", "bool", "Observe link file", False), ("keep", "bool", "Keep added containers", True), ("file", "str", "Link file", "links.txt")] -- cgit v1.2.3 From 34984dae733c3f3d47b41a0acfba3724d53c65a1 Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Tue, 28 Oct 2014 16:52:10 +0100 Subject: Code cosmetics: plugin class attributes --- module/plugins/hooks/HotFolder.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'module/plugins/hooks/HotFolder.py') diff --git a/module/plugins/hooks/HotFolder.py b/module/plugins/hooks/HotFolder.py index 00eac266c..d7e8093b3 100644 --- a/module/plugins/hooks/HotFolder.py +++ b/module/plugins/hooks/HotFolder.py @@ -10,8 +10,8 @@ from module.plugins.Hook import Hook class HotFolder(Hook): - __name__ = "HotFolder" - __type__ = "hook" + __name__ = "HotFolder" + __type__ = "hook" __version__ = "0.11" __config__ = [("folder", "str", "Folder to observe", "container"), @@ -20,8 +20,8 @@ class HotFolder(Hook): ("file", "str", "Link file", "links.txt")] __description__ = """Observe folder and file for changes and add container and links""" - __license__ = "GPLv3" - __authors__ = [("RaNaN", "RaNaN@pyload.de")] + __license__ = "GPLv3" + __authors__ = [("RaNaN", "RaNaN@pyload.de")] def setup(self): -- cgit v1.2.3 From bd8259220ab4d56ab419b7b32045b08cc9b0a7c8 Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Sun, 9 Nov 2014 03:08:19 +0100 Subject: Use with statement instead open method when accessing fod + handle i/o error --- module/plugins/hooks/HotFolder.py | 67 +++++++++++++++++++-------------------- 1 file changed, 33 insertions(+), 34 deletions(-) (limited to 'module/plugins/hooks/HotFolder.py') diff --git a/module/plugins/hooks/HotFolder.py b/module/plugins/hooks/HotFolder.py index d7e8093b3..5e9dd9547 100644 --- a/module/plugins/hooks/HotFolder.py +++ b/module/plugins/hooks/HotFolder.py @@ -7,6 +7,7 @@ from os.path import exists, isfile, join from shutil import move from module.plugins.Hook import Hook +from module.utils import fs_encode, save_join class HotFolder(Hook): @@ -29,37 +30,35 @@ class HotFolder(Hook): def periodical(self): - if not exists(join(self.getConfig("folder"), "finished")): - makedirs(join(self.getConfig("folder"), "finished")) - - if self.getConfig("watch_file"): - - if not exists(self.getConfig("file")): - f = open(self.getConfig("file"), "wb") - f.close() - - f = open(self.getConfig("file"), "rb") - content = f.read().strip() - f.close() - f = open(self.getConfig("file"), "wb") - f.close() - if content: - name = "%s_%s.txt" % (self.getConfig("file"), time.strftime("%H-%M-%S_%d%b%Y")) - - f = open(join(self.getConfig("folder"), "finished", name), "wb") - f.write(content) - f.close() - - self.core.api.addPackage(f.name, [f.name], 1) - - for f in listdir(self.getConfig("folder")): - path = join(self.getConfig("folder"), f) - - if not isfile(path) or f.endswith("~") or f.startswith("#") or f.startswith("."): - continue - - newpath = join(self.getConfig("folder"), "finished", f if self.getConfig("keep") else "tmp_" + f) - move(path, newpath) - - self.logInfo(_("Added %s from HotFolder") % f) - self.core.api.addPackage(f, [newpath], 1) + folder = fs_encode(self.getConfig("folder")) + + try: + if not exists(join(folder, "finished")): + makedirs(join(folder, "finished")) + + if self.getConfig("watch_file"): + with open(fs_encode(self.getConfig("file")), "a+") as f: + content = f.read().strip() + + if content: + name = "%s_%s.txt" % (self.getConfig("file"), time.strftime("%H-%M-%S_%d%b%Y")) + + with open(save_join(folder, "finished", name), "wb") as f: + f.write(content) + + self.core.api.addPackage(f.name, [f.name], 1) + + for f in listdir(folder): + path = join(folder, f) + + if not isfile(path) or f.endswith("~") or f.startswith("#") or f.startswith("."): + continue + + newpath = join(folder, "finished", f if self.getConfig("keep") else "tmp_" + f) + move(path, newpath) + + self.logInfo(_("Added %s from HotFolder") % f) + self.core.api.addPackage(f, [newpath], 1) + + except IOError, e: + self.logError(str(e)) -- cgit v1.2.3 From 59f72bfc5ed721c80c821bd0ca1bc8daf0d49880 Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Sun, 9 Nov 2014 03:12:41 +0100 Subject: Code cosmetics --- module/plugins/hooks/HotFolder.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'module/plugins/hooks/HotFolder.py') diff --git a/module/plugins/hooks/HotFolder.py b/module/plugins/hooks/HotFolder.py index 5e9dd9547..15a8f43d5 100644 --- a/module/plugins/hooks/HotFolder.py +++ b/module/plugins/hooks/HotFolder.py @@ -31,7 +31,7 @@ class HotFolder(Hook): def periodical(self): folder = fs_encode(self.getConfig("folder")) - + try: if not exists(join(folder, "finished")): makedirs(join(folder, "finished")) @@ -39,7 +39,7 @@ class HotFolder(Hook): if self.getConfig("watch_file"): with open(fs_encode(self.getConfig("file")), "a+") as f: content = f.read().strip() - + if content: name = "%s_%s.txt" % (self.getConfig("file"), time.strftime("%H-%M-%S_%d%b%Y")) @@ -59,6 +59,6 @@ class HotFolder(Hook): self.logInfo(_("Added %s from HotFolder") % f) self.core.api.addPackage(f, [newpath], 1) - + except IOError, e: self.logError(str(e)) -- cgit v1.2.3 From c9e31d875d32de31e54959b82bc35eff2b3e0f3f Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Mon, 10 Nov 2014 00:19:51 +0100 Subject: Code cosmetics --- module/plugins/hooks/HotFolder.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'module/plugins/hooks/HotFolder.py') diff --git a/module/plugins/hooks/HotFolder.py b/module/plugins/hooks/HotFolder.py index 15a8f43d5..518bbac2b 100644 --- a/module/plugins/hooks/HotFolder.py +++ b/module/plugins/hooks/HotFolder.py @@ -61,4 +61,4 @@ class HotFolder(Hook): self.core.api.addPackage(f, [newpath], 1) except IOError, e: - self.logError(str(e)) + self.logError(e) -- cgit v1.2.3 From 52664e6fe8dd99fc9bb78ea8cf158c17705b6ded Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Fri, 5 Dec 2014 19:18:11 +0100 Subject: Fix with statement on old env like python 2.5 (2) --- module/plugins/hooks/HotFolder.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'module/plugins/hooks/HotFolder.py') diff --git a/module/plugins/hooks/HotFolder.py b/module/plugins/hooks/HotFolder.py index 518bbac2b..b0b59e2ba 100644 --- a/module/plugins/hooks/HotFolder.py +++ b/module/plugins/hooks/HotFolder.py @@ -1,5 +1,7 @@ # -*- coding: utf-8 -*- +from __future__ import with_statement + import time from os import listdir, makedirs @@ -13,7 +15,7 @@ from module.utils import fs_encode, save_join class HotFolder(Hook): __name__ = "HotFolder" __type__ = "hook" - __version__ = "0.11" + __version__ = "0.12" __config__ = [("folder", "str", "Folder to observe", "container"), ("watch_file", "bool", "Observe link file", False), -- cgit v1.2.3