summaryrefslogtreecommitdiffstats
path: root/module/plugins/hooks
diff options
context:
space:
mode:
authorGravatar Walter Purcaro <vuolter@users.noreply.github.com> 2015-12-28 16:04:35 +0100
committerGravatar Walter Purcaro <vuolter@users.noreply.github.com> 2015-12-28 16:04:35 +0100
commit58a00607a64cc26820c8a995f5f7863e2465911d (patch)
tree8d25c0afe8b1115b00ffdc5cda036fb95063ea16 /module/plugins/hooks
parentSpare code fixes (diff)
downloadpyload-58a00607a64cc26820c8a995f5f7863e2465911d.tar.xz
Spare code fixes (2)
Diffstat (limited to 'module/plugins/hooks')
-rw-r--r--module/plugins/hooks/AntiVirus.py26
-rw-r--r--module/plugins/hooks/Checksum.py24
-rw-r--r--module/plugins/hooks/ExtractArchive.py52
-rw-r--r--module/plugins/hooks/MergeFiles.py10
-rw-r--r--module/plugins/hooks/UpdateManager.py24
-rw-r--r--module/plugins/hooks/XFileSharing.py10
6 files changed, 76 insertions, 70 deletions
diff --git a/module/plugins/hooks/AntiVirus.py b/module/plugins/hooks/AntiVirus.py
index 049e92ab8..55b883684 100644
--- a/module/plugins/hooks/AntiVirus.py
+++ b/module/plugins/hooks/AntiVirus.py
@@ -10,13 +10,13 @@ except ImportError:
pass
from module.plugins.internal.Addon import Addon, Expose, threaded
-from module.plugins.internal.utils import encode, exists, fs_join
+from module.plugins.internal.misc import encode, exists, fsjoin
class AntiVirus(Addon):
__name__ = "AntiVirus"
__type__ = "hook"
- __version__ = "0.15"
+ __version__ = "0.16"
__status__ = "testing"
#@TODO: add trash option (use Send2Trash lib)
@@ -38,18 +38,18 @@ class AntiVirus(Addon):
@Expose
@threaded
def scan(self, pyfile, thread):
- avfile = encode(self.get_config('avfile'))
- avargs = encode(self.get_config('avargs').strip())
+ avfile = encode(self.config.get('avfile'))
+ avargs = encode(self.config.get('avargs').strip())
if not os.path.isfile(avfile):
self.fail(_("Antivirus executable not found"))
- scanfolder = self.get_config('avtarget') is "folder"
+ scanfolder = self.config.get('avtarget') is "folder"
if scanfolder:
dl_folder = self.pyload.config.get("general", "download_folder")
package_folder = pyfile.package().folder if self.pyload.config.get("general", "folder_per_package") else ""
- target = fs_join(dl_folder, package_folder, pyfile.name)
+ target = fsjoin(dl_folder, package_folder, pyfile.name)
target_repr = "Folder: " + package_folder or dl_folder
else:
target = encode(pyfile.plugin.last_download)
@@ -75,12 +75,12 @@ class AntiVirus(Addon):
if err:
self.log_warning(target_repr, err)
- if not self.get_config('ignore-err'):
+ if not self.config.get('ignore-err'):
self.log_debug("Delete/Quarantine task aborted due scan error")
return
if p.returncode:
- action = self.get_config('action')
+ action = self.config.get('action')
if scanfolder:
if action is "Antivirus default":
@@ -91,7 +91,7 @@ class AntiVirus(Addon):
try:
if action is "Delete":
- if not self.get_config('deltotrash'):
+ if not self.config.get('deltotrash'):
os.remove(file)
else:
@@ -101,19 +101,19 @@ class AntiVirus(Addon):
except NameError:
self.log_warning(_("Send2Trash lib not found, moving to quarantine instead"))
pyfile.setCustomStatus(_("file moving"))
- shutil.move(file, self.get_config('quardir'))
+ shutil.move(file, self.config.get('quardir'))
except Exception, e:
self.log_warning(_("Unable to move file to trash: %s, moving to quarantine instead") % e.message)
pyfile.setCustomStatus(_("file moving"))
- shutil.move(file, self.get_config('quardir'))
+ shutil.move(file, self.config.get('quardir'))
else:
self.log_debug("Successfully moved file to trash")
elif action is "Quarantine":
pyfile.setCustomStatus(_("file moving"))
- shutil.move(file, self.get_config('quardir'))
+ shutil.move(file, self.config.get('quardir'))
except (IOError, shutil.Error), e:
self.log_error(target_repr, action + " action failed!", e)
@@ -132,5 +132,5 @@ class AntiVirus(Addon):
def download_failed(self, pyfile):
#: Check if pyfile is still "failed", maybe might has been restarted in meantime
- if pyfile.status is 8 and self.get_config('scanfailed'):
+ if pyfile.status is 8 and self.config.get('scanfailed'):
return self.scan(pyfile)
diff --git a/module/plugins/hooks/Checksum.py b/module/plugins/hooks/Checksum.py
index cf5ed2147..28fdeafee 100644
--- a/module/plugins/hooks/Checksum.py
+++ b/module/plugins/hooks/Checksum.py
@@ -8,7 +8,7 @@ import re
import zlib
from module.plugins.internal.Addon import Addon
-from module.plugins.internal.utils import encode, fs_join
+from module.plugins.internal.misc import encode, fsjoin
def compute_checksum(local_file, algorithm):
@@ -38,7 +38,7 @@ def compute_checksum(local_file, algorithm):
class Checksum(Addon):
__name__ = "Checksum"
__type__ = "hook"
- __version__ = "0.23"
+ __version__ = "0.24"
__status__ = "testing"
__config__ = [("activated" , "bool" , "Activated" , False ),
@@ -65,7 +65,7 @@ class Checksum(Addon):
def activate(self):
- if not self.get_config('check_checksum'):
+ if not self.config.get('check_checksum'):
self.log_info(_("Checksum validation is disabled in plugin configuration"))
@@ -105,7 +105,7 @@ class Checksum(Addon):
local_file = encode(pyfile.plugin.last_download)
# dl_folder = self.pyload.config.get("general", "download_folder")
- # local_file = encode(fs_join(dl_folder, pyfile.package().folder, pyfile.name))
+ # local_file = encode(fsjoin(dl_folder, pyfile.package().folder, pyfile.name))
if not os.path.isfile(local_file):
self.check_failed(pyfile, None, "File does not exist")
@@ -122,7 +122,7 @@ class Checksum(Addon):
data.pop('size', None)
#: Validate checksum
- if data and self.get_config('check_checksum'):
+ if data and self.config.get('check_checksum'):
if not 'md5' in data:
for type in ("checksum", "hashsum", "hash"):
@@ -149,14 +149,14 @@ class Checksum(Addon):
def check_failed(self, pyfile, local_file, msg):
- check_action = self.get_config('check_action')
+ check_action = self.config.get('check_action')
if check_action == "retry":
- max_tries = self.get_config('max_tries')
- retry_action = self.get_config('retry_action')
+ max_tries = self.config.get('max_tries')
+ retry_action = self.config.get('retry_action')
if pyfile.plugin.retries < max_tries:
if local_file:
os.remove(local_file)
- pyfile.plugin.retry(max_tries, self.get_config('wait_time'), msg)
+ pyfile.plugin.retry(max_tries, self.config.get('wait_time'), msg)
elif retry_action == "nothing":
return
elif check_action == "nothing":
@@ -166,7 +166,7 @@ class Checksum(Addon):
def package_finished(self, pypack):
- dl_folder = fs_join(self.pyload.config.get("general", "download_folder"), pypack.folder, "")
+ dl_folder = fsjoin(self.pyload.config.get("general", "download_folder"), pypack.folder, "")
for link in pypack.getChildren().values():
file_type = os.path.splitext(link['name'])[1][1:].lower()
@@ -174,7 +174,7 @@ class Checksum(Addon):
if file_type not in self.formats:
continue
- hash_file = encode(fs_join(dl_folder, link['name']))
+ hash_file = encode(fsjoin(dl_folder, link['name']))
if not os.path.isfile(hash_file):
self.log_warning(_("File not found"), link['name'])
continue
@@ -186,7 +186,7 @@ class Checksum(Addon):
data = m.groupdict()
self.log_debug(link['name'], data)
- local_file = encode(fs_join(dl_folder, data['NAME']))
+ local_file = encode(fsjoin(dl_folder, data['NAME']))
algorithm = self.methods.get(file_type, file_type)
checksum = compute_checksum(local_file, algorithm)
diff --git a/module/plugins/hooks/ExtractArchive.py b/module/plugins/hooks/ExtractArchive.py
index c001000c8..96c8d7ed3 100644
--- a/module/plugins/hooks/ExtractArchive.py
+++ b/module/plugins/hooks/ExtractArchive.py
@@ -51,7 +51,7 @@ except ImportError:
from module.plugins.internal.Addon import Addon, Expose, threaded
from module.plugins.internal.Extractor import ArchiveError, CRCError, PasswordError
-from module.plugins.internal.utils import encode, exists, fs_join, replace_patterns, uniqify
+from module.plugins.internal.misc import encode, exists, fsjoin, replace_patterns, uniqify
class ArchiveQueue(object):
@@ -98,7 +98,7 @@ class ArchiveQueue(object):
class ExtractArchive(Addon):
__name__ = "ExtractArchive"
__type__ = "hook"
- __version__ = "1.53"
+ __version__ = "1.54"
__status__ = "testing"
__config__ = [("activated" , "bool" , "Activated" , True ),
@@ -149,7 +149,7 @@ class ExtractArchive(Addon):
if klass.find():
self.extractors.append(klass)
if klass.REPAIR:
- self.repair = self.get_config('repair')
+ self.repair = self.config.get('repair')
except OSError, e:
if e.errno == 2:
@@ -206,7 +206,7 @@ class ExtractArchive(Addon):
"""
for id in ids:
self.queue.add(id)
- if not self.get_config('waitall') and not self.extracting:
+ if not self.config.get('waitall') and not self.extracting:
self.extract_queued()
@@ -216,13 +216,13 @@ class ExtractArchive(Addon):
def package_finished(self, pypack):
self.queue.add(pypack.id)
- if not self.get_config('waitall') and not self.extracting:
+ if not self.config.get('waitall') and not self.extracting:
self.extract_queued()
def all_downloads_processed(self):
self.last_package = True
- if self.get_config('waitall') and not self.extracting:
+ if self.config.get('waitall') and not self.extracting:
self.extract_queued()
@@ -237,16 +237,16 @@ class ExtractArchive(Addon):
toList = lambda string: string.replace(' ', '').replace(',', '|').replace(';', '|').split('|')
- destination = self.get_config('destination')
- subfolder = self.get_config('subfolder')
- fullpath = self.get_config('fullpath')
- overwrite = self.get_config('overwrite')
- priority = self.get_config('priority')
- recursive = self.get_config('recursive')
- keepbroken = self.get_config('keepbroken')
+ destination = self.config.get('destination')
+ subfolder = self.config.get('subfolder')
+ fullpath = self.config.get('fullpath')
+ overwrite = self.config.get('overwrite')
+ priority = self.config.get('priority')
+ recursive = self.config.get('recursive')
+ keepbroken = self.config.get('keepbroken')
- extensions = [x.lstrip('.').lower() for x in toList(self.get_config('extensions'))]
- excludefiles = toList(self.get_config('excludefiles'))
+ extensions = [x.lstrip('.').lower() for x in toList(self.config.get('extensions'))]
+ excludefiles = toList(self.config.get('excludefiles'))
if extensions:
self.log_debug("Use for extensions: %s" % "|.".join(extensions))
@@ -267,17 +267,17 @@ class ExtractArchive(Addon):
self.log_info(_("Check package: %s") % pypack.name)
#: Determine output folder
- out = fs_join(dl_folder, pypack.folder, destination, "") #: Force trailing slash
+ out = fsjoin(dl_folder, pypack.folder, destination, "") #: Force trailing slash
if subfolder:
- out = fs_join(out, pypack.folder)
+ out = fsjoin(out, pypack.folder)
if not exists(out):
os.makedirs(out)
matched = False
success = True
- files_ids = dict((pylink['name'], ((fs_join(dl_folder, pypack.folder, pylink['name'])), pylink['id'], out)) for pylink \
+ files_ids = dict((pylink['name'], ((fsjoin(dl_folder, pypack.folder, pylink['name'])), pylink['id'], out)) for pylink \
in sorted(pypack.getChildren().values(), key=lambda k: k['name'])).values() #: Remove duplicates
#: Check as long there are unseen files
@@ -338,7 +338,7 @@ class ExtractArchive(Addon):
self.set_permissions(file)
for filename in new_files:
- file = encode(fs_join(os.path.dirname(archive.filename), filename))
+ file = encode(fsjoin(os.path.dirname(archive.filename), filename))
if not exists(file):
self.log_debug("New file %s does not exists" % filename)
continue
@@ -383,7 +383,7 @@ class ExtractArchive(Addon):
encrypted = False
try:
self.log_debug("Password: %s" % (password or "None provided"))
- passwords = uniqify([password] + self.get_passwords(False)) if self.get_config('usepasswordfile') else [password]
+ passwords = uniqify([password] + self.get_passwords(False)) if self.config.get('usepasswordfile') else [password]
for pw in passwords:
try:
pyfile.setCustomStatus(_("archive testing"))
@@ -410,7 +410,7 @@ class ExtractArchive(Addon):
repaired = archive.repair()
pyfile.setProgress(100)
- if not repaired and not self.get_config('keepbroken'):
+ if not repaired and not self.config.get('keepbroken'):
raise CRCError("Archive damaged")
else:
@@ -427,7 +427,7 @@ class ExtractArchive(Addon):
pyfile.setCustomStatus(_("archive extracting"))
pyfile.setProgress(0)
- if not encrypted or not self.get_config('usepasswordfile'):
+ if not encrypted or not self.config.get('usepasswordfile'):
self.log_debug("Extracting using password: %s" % (password or "None"))
archive.extract(password)
else:
@@ -450,10 +450,10 @@ class ExtractArchive(Addon):
delfiles = archive.items()
self.log_debug("Would delete: " + ", ".join(delfiles))
- if self.get_config('delete'):
+ if self.config.get('delete'):
self.log_info(_("Deleting %s files") % len(delfiles))
- deltotrash = self.get_config('deltotrash')
+ deltotrash = self.config.get('deltotrash')
for f in delfiles:
file = encode(f)
if not exists(file):
@@ -523,7 +523,7 @@ class ExtractArchive(Addon):
try:
passwords = []
- file = encode(self.get_config('passwordfile'))
+ file = encode(self.config.get('passwordfile'))
with open(file) as f:
for pw in f.read().splitlines():
passwords.append(pw)
@@ -552,7 +552,7 @@ class ExtractArchive(Addon):
try:
self.passwords = uniqify([password] + self.passwords)
- file = encode(self.get_config('passwordfile'))
+ file = encode(self.config.get('passwordfile'))
with open(file, "wb") as f:
for pw in self.passwords:
f.write(pw + '\n')
diff --git a/module/plugins/hooks/MergeFiles.py b/module/plugins/hooks/MergeFiles.py
index dbe7b1f5f..963f8c15b 100644
--- a/module/plugins/hooks/MergeFiles.py
+++ b/module/plugins/hooks/MergeFiles.py
@@ -6,13 +6,13 @@ import os
import re
from module.plugins.internal.Addon import Addon, threaded
-from module.plugins.internal.utils import fs_join
+from module.plugins.internal.misc import fsjoin
class MergeFiles(Addon):
__name__ = "MergeFiles"
__type__ = "hook"
- __version__ = "0.18"
+ __version__ = "0.19"
__status__ = "testing"
__config__ = [("activated", "bool", "Activated", True)]
@@ -40,12 +40,12 @@ class MergeFiles(Addon):
dl_folder = self.pyload.config.get("general", "download_folder")
if self.pyload.config.get("general", "folder_per_package"):
- dl_folder = fs_join(dl_folder, pack.folder)
+ dl_folder = fsjoin(dl_folder, pack.folder)
for name, file_list in files.items():
self.log_info(_("Starting merging of"), name)
- with open(fs_join(dl_folder, name), "wb") as final_file:
+ with open(fsjoin(dl_folder, name), "wb") as final_file:
for splitted_file in file_list:
self.log_debug("Merging part", splitted_file)
@@ -54,7 +54,7 @@ class MergeFiles(Addon):
pyfile.setStatus("processing")
try:
- with open(fs_join(dl_folder, splitted_file), "rb") as s_file:
+ with open(fsjoin(dl_folder, splitted_file), "rb") as s_file:
size_written = 0
s_file_size = int(os.path.getsize(os.path.join(dl_folder, splitted_file)))
while True:
diff --git a/module/plugins/hooks/UpdateManager.py b/module/plugins/hooks/UpdateManager.py
index e235b0e47..cf36a6d40 100644
--- a/module/plugins/hooks/UpdateManager.py
+++ b/module/plugins/hooks/UpdateManager.py
@@ -9,13 +9,13 @@ import sys
import time
from module.plugins.internal.Addon import Expose, Addon, threaded
-from module.plugins.internal.utils import encode, exists, fs_join
+from module.plugins.internal.misc import encode, exists, fsjoin
class UpdateManager(Addon):
__name__ = "UpdateManager"
__type__ = "hook"
- __version__ = "1.04"
+ __version__ = "1.05"
__status__ = "testing"
__config__ = [("activated" , "bool", "Activated" , True ),
@@ -45,7 +45,7 @@ class UpdateManager(Addon):
if self.do_restart is False:
self.pyload.api.unpauseServer()
- self.start_periodical(10)
+ self.periodical.start(10)
def init(self):
@@ -53,7 +53,7 @@ class UpdateManager(Addon):
self.mtimes = {} #: Store modification time for each plugin
self.event_map = {'allDownloadsProcessed': "all_downloads_processed"}
- if self.get_config('checkonstart'):
+ if self.config.get('checkonstart'):
self.pyload.api.pauseServer()
self.checkonstart = True
else:
@@ -67,16 +67,16 @@ class UpdateManager(Addon):
self.pyload.api.restart()
- def periodical(self):
+ def periodical_task(self):
if self.pyload.debug:
- if self.get_config('reloadplugins'):
+ if self.config.get('reloadplugins'):
self.autoreload_plugins()
- if self.get_config('nodebugupdate'):
+ if self.config.get('nodebugupdate'):
return
- if self.get_config('checkperiod') and \
- time.time() - max(self.CHECK_INTERVAL, self.get_config('checkinterval') * 60 * 60) > self.info['last_check']:
+ if self.config.get('checkperiod') and \
+ time.time() - max(self.CHECK_INTERVAL, self.config.get('checkinterval') * 60 * 60) > self.info['last_check']:
self.update()
@@ -146,7 +146,7 @@ class UpdateManager(Addon):
"""
Check for updates
"""
- if self._update() is not 2 or not self.get_config('autorestart'):
+ if self._update() is not 2 or not self.config.get('autorestart'):
return
if not self.pyload.api.statusDownloads():
@@ -304,7 +304,7 @@ class UpdateManager(Addon):
m = self._VERSION.search(content)
if m and m.group(2) == plugin_version:
- with open(fs_join("userplugins", plugin_type, plugin_name + ".py"), "wb") as f:
+ with open(fsjoin("userplugins", plugin_type, plugin_name + ".py"), "wb") as f:
f.write(encode(content))
updated.append((plugin_type, plugin_name))
@@ -342,7 +342,7 @@ class UpdateManager(Addon):
rootplugins = os.path.join(pypath, "module", "plugins")
for basedir in ("userplugins", rootplugins):
- py_filename = fs_join(basedir, plugin_type, plugin_name + ".py")
+ py_filename = fsjoin(basedir, plugin_type, plugin_name + ".py")
pyc_filename = py_filename + "c"
if plugin_type is "hook":
diff --git a/module/plugins/hooks/XFileSharing.py b/module/plugins/hooks/XFileSharing.py
index e2f25e13f..201cbab53 100644
--- a/module/plugins/hooks/XFileSharing.py
+++ b/module/plugins/hooks/XFileSharing.py
@@ -9,7 +9,7 @@ from module.plugins.internal.Addon import Addon
class XFileSharing(Addon):
__name__ = "XFileSharing"
__type__ = "hook"
- __version__ = "0.53"
+ __version__ = "0.54"
__status__ = "testing"
__config__ = [("activated" , "bool", "Activated" , True ),
@@ -91,7 +91,13 @@ class XFileSharing(Addon):
isXFS = lambda klass: any(k.__name__.startswith("XFS") for k in inspect.getmro(klass))
for p in self.pyload.pluginManager.plugins[type].values():
- klass = self.pyload.pluginManager.loadClass(type, p['name'])
+ try:
+ klass = self.pyload.pluginManager.loadClass(type, p['name'])
+
+ except AttributeError, e:
+ self.log_debug(e, trace=True)
+ continue
+
if hasattr(klass, "PLUGIN_DOMAIN") and klass.PLUGIN_DOMAIN and isXFS(klass):
plugin_list.append(klass.PLUGIN_DOMAIN)