summaryrefslogtreecommitdiffstats
path: root/pyload/plugins
diff options
context:
space:
mode:
authorGravatar RaNaN <Mast3rRaNaN@hotmail.de> 2013-11-22 23:00:43 +0100
committerGravatar RaNaN <Mast3rRaNaN@hotmail.de> 2013-11-22 23:00:43 +0100
commit7a386102e272abf12fc8a03733538421b2711045 (patch)
tree4d1f1ef511bf3e3b3d95f78d35067885deffc01e /pyload/plugins
parentfixed and improved last pull request (diff)
downloadpyload-7a386102e272abf12fc8a03733538421b2711045.tar.xz
improved addonManager, new property to expose addon information, new functionality to interact with addons
Diffstat (limited to 'pyload/plugins')
-rw-r--r--pyload/plugins/Addon.py65
-rw-r--r--pyload/plugins/Hoster.py4
-rw-r--r--pyload/plugins/addons/ExtractArchive.py47
3 files changed, 73 insertions, 43 deletions
diff --git a/pyload/plugins/Addon.py b/pyload/plugins/Addon.py
index c1a297d28..5c27fa983 100644
--- a/pyload/plugins/Addon.py
+++ b/pyload/plugins/Addon.py
@@ -1,7 +1,5 @@
# -*- coding: utf-8 -*-
-from traceback import print_exc
-
#from functools import wraps
from pyload.utils import has_method, to_list
@@ -27,23 +25,58 @@ def AddEventListener(event):
return _klass
-def AddonHandler(desc, media=None):
- """ Register Handler for files, packages, or arbitrary callable methods.
- To let the method work on packages/files, media must be set and the argument named pid or fid.
+def AddonHandler(label, desc, package=True, media=-1):
+ """ Register Handler for files, packages, or arbitrary callable methods. In case package is True (default)
+ The method should only accept a pid as argument. When media is set it will work on files
+ and should accept a fileid. Only when both is None the method can be arbitrary.
- :param desc: verbose description
- :param media: if True or bits of media type
+ :param label: verbose name
+ :param desc: short description
+ :param package: True if method works withs packages
+ :param media: media type of the file to work with.
"""
- pass
+ class _klass(object):
+ def __new__(cls, f, *args, **kwargs):
+ addonManager.addAddonHandler(class_name(f.__module__), f.func_name, label, desc,
+ f.func_code.co_varnames[1:], package, media)
+ return f
+
+ return _klass
-def AddonInfo(desc):
- """ Called to retrieve information about the current state.
- Decorated method must return anything convertable into string.
+def AddonProperty(name, desc, default=None, fire_event=True):
+ """ Use this function to declare class variables, that will be exposed as :class:`AddonInfo`.
+ It works similar to the @property function. You declare the variable like `state = AddonProperty(...)`
+ and use it as any other variable.
+
+ :param name: display name
:param desc: verbose description
+ :param default: the default value
+ :param fire_event: Fire `addon:property:change` event, when modified
"""
- pass
+
+ # generated name for the attribute
+ h = "__Property" + str(hash(name) ^ hash(desc))
+
+ addonManager.addInfoProperty(h, name, desc)
+
+ def _get(self):
+ if not hasattr(self, h):
+ return default
+
+ return getattr(self, h)
+
+ def _set(self, value):
+ if fire_event:
+ self.manager.dispatchEvent("addon:property:change", value)
+
+ return setattr(self, h, value)
+
+ def _del(self):
+ return delattr(self, h)
+
+ return property(_get, _set, _del)
def threaded(f):
@@ -73,9 +106,6 @@ class Addon(Base):
def __init__(self, core, manager, user=None):
Base.__init__(self, core, user)
- #: Provide information in dict here, usable by API `getInfo`
- self.info = None
-
#: Callback of periodical job task, used by addonManager
self.cb = None
@@ -130,9 +160,8 @@ class Addon(Base):
try:
if self.isActivated(): self.periodical()
except Exception, e:
- self.core.log.error(_("Error executing addons: %s") % str(e))
- if self.core.debug:
- print_exc()
+ self.core.log.error(_("Error executing addon: %s") % str(e))
+ self.core.print_exc()
if self.cb:
self.cb = self.core.scheduler.addJob(self.interval, self._periodical, threaded=False)
diff --git a/pyload/plugins/Hoster.py b/pyload/plugins/Hoster.py
index 976918c0d..6bfe47e1f 100644
--- a/pyload/plugins/Hoster.py
+++ b/pyload/plugins/Hoster.py
@@ -9,7 +9,7 @@ if os.name != "nt":
from grp import getgrnam
from pyload.utils import chunks as _chunks
-from pyload.utils.fs import save_join, save_filename, fs_encode, fs_decode, \
+from pyload.utils.fs import save_join, safe_filename, fs_encode, fs_decode, \
remove, makedirs, chmod, stat, exists, join
from Base import Base, Fail, Retry
@@ -268,7 +268,7 @@ class Hoster(Base):
# convert back to unicode
location = fs_decode(location)
- name = save_filename(self.pyfile.name)
+ name = safe_filename(self.pyfile.name)
filename = join(location, name)
diff --git a/pyload/plugins/addons/ExtractArchive.py b/pyload/plugins/addons/ExtractArchive.py
index be023301c..67fa5c820 100644
--- a/pyload/plugins/addons/ExtractArchive.py
+++ b/pyload/plugins/addons/ExtractArchive.py
@@ -49,12 +49,13 @@ if os.name != "nt":
from pwd import getpwnam
from grp import getgrnam
-from module.utils import save_join, fs_encode
-from module.plugins.Hook import Hook, threaded, Expose
-from module.plugins.internal.AbstractExtractor import ArchiveError, CRCError, WrongPassword
+from pyload.utils.fs import safe_join as save_join, fs_encode
+from pyload.plugins.Addon import Addon, threaded, AddonHandler, AddonProperty
+from pyload.plugins.internal.AbstractExtractor import ArchiveError, CRCError, WrongPassword
-class ExtractArchive(Hook):
+
+class ExtractArchive(Addon):
"""
Provides: unrarFinished (folder, filename)
"""
@@ -77,7 +78,7 @@ class ExtractArchive(Hook):
event_list = ["allDownloadsProcessed"]
- def setup(self):
+ def init(self):
self.plugins = []
self.passwords = []
names = []
@@ -111,10 +112,10 @@ class ExtractArchive(Hook):
# queue with package ids
self.queue = []
- @Expose
- def extractPackage(self, id):
+ @AddonHandler(_("Extract package"), _("Scans package for archives and extract them"))
+ def extractPackage(self, pid):
""" Extract package with given id"""
- self.manager.startThread(self.extract, [id])
+ self.manager.startThread(self.extract, [pid])
def packageFinished(self, pypack):
if self.getConfig("queue"):
@@ -267,25 +268,12 @@ class ExtractArchive(Hook):
return []
- @Expose
+ # TODO: config handler for passwords?
+
def getPasswords(self):
""" List of saved passwords """
return self.passwords
- def reloadPasswords(self):
- pwfile = self.getConfig("passwordfile")
- if not exists(pwfile):
- open(pwfile, "wb").close()
-
- passwords = []
- f = open(pwfile, "rb")
- for pw in f.read().splitlines():
- passwords.append(pw)
- f.close()
-
- self.passwords = passwords
-
- @Expose
def addPassword(self, pw):
""" Adds a password to saved list"""
pwfile = self.getConfig("passwordfile")
@@ -299,6 +287,19 @@ class ExtractArchive(Hook):
f.write(pw + "\n")
f.close()
+ def reloadPasswords(self):
+ pwfile = self.getConfig("passwordfile")
+ if not exists(pwfile):
+ open(pwfile, "wb").close()
+
+ passwords = []
+ f = open(pwfile, "rb")
+ for pw in f.read().splitlines():
+ passwords.append(pw)
+ f.close()
+
+ self.passwords = passwords
+
def setPermissions(self, files):
for f in files:
if not exists(f):