summaryrefslogtreecommitdiffstats
path: root/module/plugins
diff options
context:
space:
mode:
authorGravatar RaNaN <Mast3rRaNaN@hotmail.de> 2011-12-15 23:18:21 +0100
committerGravatar RaNaN <Mast3rRaNaN@hotmail.de> 2011-12-15 23:18:21 +0100
commit5499be89203a18ca61a21cfc7266cf0f4ebe6547 (patch)
tree55f3d207573920be3a6970dbc099d058f417c05f /module/plugins
parentAdded tag v0.4.9 for changeset 1babca12c25f (diff)
downloadpyload-5499be89203a18ca61a21cfc7266cf0f4ebe6547.tar.xz
refractoring
Diffstat (limited to 'module/plugins')
-rw-r--r--module/plugins/AccountManager.py2
-rw-r--r--module/plugins/Base.py116
-rw-r--r--module/plugins/Hoster.py22
-rw-r--r--module/plugins/Plugin.py96
-rw-r--r--module/plugins/PluginManager.py6
5 files changed, 136 insertions, 106 deletions
diff --git a/module/plugins/AccountManager.py b/module/plugins/AccountManager.py
index fc521d36c..4f4d9f68d 100644
--- a/module/plugins/AccountManager.py
+++ b/module/plugins/AccountManager.py
@@ -22,7 +22,7 @@ from shutil import copy
from threading import Lock
-from module.PullEvents import AccountUpdateEvent
+from module.interaction.PullEvents import AccountUpdateEvent
from module.utils import chmod, lock
ACC_VERSION = 1
diff --git a/module/plugins/Base.py b/module/plugins/Base.py
new file mode 100644
index 000000000..98573ea63
--- /dev/null
+++ b/module/plugins/Base.py
@@ -0,0 +1,116 @@
+# -*- 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 <http://www.gnu.org/licenses/>.
+
+ @author: RaNaN
+"""
+
+class Base(object):
+ """
+ The Base plugin class with all shared methods and every possible attribute for plugin definition.
+ """
+ __version__ = "0.4"
+ #: Regexp pattern which will be matched for download plugins
+ __pattern__ = r""
+ #: Flat config definition
+ __config__ = tuple()
+ #: Short description, one liner
+ __description__ = ""
+ #: More detailed text
+ __long_description__ = """"""
+ #: List of needed modules
+ __dependencies__ = tuple()
+ #: Tags to categorize the plugin
+ __tags__ = tuple()
+ #: Base64 encoded .png icon
+ __icon__ = ""
+ #: Alternative, link to png icon
+ __icon_url__ = ""
+ #: Url with general information/support/discussion
+ __url__ = ""
+ __author_name__ = tuple()
+ __author_mail__ = tuple()
+
+
+ def __init__(self, core):
+ self.__name__ = self.__class__.__name__
+
+ #: Core instance
+ self.core = core
+ #: logging instance
+ self.log = core.log
+ #: core config
+ self.config = core.config
+
+ #log functions
+ def logInfo(self, *args):
+ self.log.info("%s: %s" % (self.__name__, " | ".join([a if isinstance(a, basestring) else str(a) for a in args])))
+
+ def logWarning(self, *args):
+ self.log.warning("%s: %s" % (self.__name__, " | ".join([a if isinstance(a, basestring) else str(a) for a in args])))
+
+ def logError(self, *args):
+ self.log.error("%s: %s" % (self.__name__, " | ".join([a if isinstance(a, basestring) else str(a) for a in args])))
+
+ def logDebug(self, *args):
+ self.log.debug("%s: %s" % (self.__name__, " | ".join([a if isinstance(a, basestring) else str(a) for a in args])))
+
+
+ def setConf(self, option, value):
+ """ see `setConfig` """
+ self.core.config.setPlugin(self.__name__, option, value)
+
+ def setConfig(self, option, value):
+ """ Set config value for current plugin
+
+ :param option:
+ :param value:
+ :return:
+ """
+ self.setConf(option, value)
+
+ def getConf(self, option):
+ """ see `getConfig` """
+ return self.core.config.getPlugin(self.__name__, option)
+
+ def getConfig(self, option):
+ """ Returns config value for current plugin
+
+ :param option:
+ :return:
+ """
+ return self.getConf(option)
+
+ def setStorage(self, key, value):
+ """ Saves a value persistently to the database """
+ self.core.db.setStorage(self.__name__, key, value)
+
+ def store(self, key, value):
+ """ same as `setStorage` """
+ self.core.db.setStorage(self.__name__, key, value)
+
+ def getStorage(self, key=None, default=None):
+ """ Retrieves saved value or dict of all saved entries if key is None """
+ if key is not None:
+ return self.core.db.getStorage(self.__name__, key) or default
+ return self.core.db.getStorage(self.__name__, key)
+
+ def retrieve(self, *args, **kwargs):
+ """ same as `getStorage` """
+ return self.getStorage(*args, **kwargs)
+
+ def delStorage(self, key):
+ """ Delete entry in db """
+ self.core.db.delStorage(self.__name__, key)
diff --git a/module/plugins/Hoster.py b/module/plugins/Hoster.py
index 814a70949..aa50099fb 100644
--- a/module/plugins/Hoster.py
+++ b/module/plugins/Hoster.py
@@ -19,15 +19,15 @@
from module.plugins.Plugin import Plugin
-def getInfo(self):
- #result = [ .. (name, size, status, url) .. ]
- return
-
class Hoster(Plugin):
- __name__ = "Hoster"
- __version__ = "0.1"
- __pattern__ = None
- __type__ = "hoster"
- __description__ = """Base hoster plugin"""
- __author_name__ = ("mkaay")
- __author_mail__ = ("mkaay@mkaay.de")
+
+ @staticmethod
+ def getInfo(urls):
+ """This method is used to retrieve the online status of files for hoster plugins.
+ It has to *yield* list of tuples with the result in this format (name, size, status, url),
+ where status is one of API pyfile statusses.
+
+ :param urls: List of urls
+ :return:
+ """
+ pass \ No newline at end of file
diff --git a/module/plugins/Plugin.py b/module/plugins/Plugin.py
index f7587d3f2..b3c22f983 100644
--- a/module/plugins/Plugin.py
+++ b/module/plugins/Plugin.py
@@ -29,17 +29,9 @@ if os.name != "nt":
from pwd import getpwnam
from grp import getgrnam
-from itertools import islice
-
-from module.utils import save_join, save_path, fs_encode
-
-def chunks(iterable, size):
- it = iter(iterable)
- item = list(islice(it, size))
- while item:
- yield item
- item = list(islice(it, size))
+from Base import Base
+from module.utils import save_join, save_path, fs_encode, chunks
class Abort(Exception):
""" raised when aborted """
@@ -61,95 +53,11 @@ class SkipDownload(Exception):
""" raised when download should be skipped """
-class Base(object):
- """
- A Base class with log/config/db methods *all* plugin types can use
- """
-
- def __init__(self, core):
- #: Core instance
- self.core = core
- #: logging instance
- self.log = core.log
- #: core config
- self.config = core.config
-
- #log functions
- def logInfo(self, *args):
- self.log.info("%s: %s" % (self.__name__, " | ".join([a if isinstance(a, basestring) else str(a) for a in args])))
-
- def logWarning(self, *args):
- self.log.warning("%s: %s" % (self.__name__, " | ".join([a if isinstance(a, basestring) else str(a) for a in args])))
-
- def logError(self, *args):
- self.log.error("%s: %s" % (self.__name__, " | ".join([a if isinstance(a, basestring) else str(a) for a in args])))
-
- def logDebug(self, *args):
- self.log.debug("%s: %s" % (self.__name__, " | ".join([a if isinstance(a, basestring) else str(a) for a in args])))
-
-
- def setConf(self, option, value):
- """ see `setConfig` """
- self.core.config.setPlugin(self.__name__, option, value)
-
- def setConfig(self, option, value):
- """ Set config value for current plugin
-
- :param option:
- :param value:
- :return:
- """
- self.setConf(option, value)
-
- def getConf(self, option):
- """ see `getConfig` """
- return self.core.config.getPlugin(self.__name__, option)
-
- def getConfig(self, option):
- """ Returns config value for current plugin
-
- :param option:
- :return:
- """
- return self.getConf(option)
-
- def setStorage(self, key, value):
- """ Saves a value persistently to the database """
- self.core.db.setStorage(self.__name__, key, value)
-
- def store(self, key, value):
- """ same as `setStorage` """
- self.core.db.setStorage(self.__name__, key, value)
-
- def getStorage(self, key=None, default=None):
- """ Retrieves saved value or dict of all saved entries if key is None """
- if key is not None:
- return self.core.db.getStorage(self.__name__, key) or default
- return self.core.db.getStorage(self.__name__, key)
-
- def retrieve(self, *args, **kwargs):
- """ same as `getStorage` """
- return self.getStorage(*args, **kwargs)
-
- def delStorage(self, key):
- """ Delete entry in db """
- self.core.db.delStorage(self.__name__, key)
-
-
class Plugin(Base):
"""
Base plugin for hoster/crypter.
Overwrite `process` / `decrypt` in your subclassed plugin.
"""
- __name__ = "Plugin"
- __version__ = "0.4"
- __pattern__ = None
- __type__ = "hoster"
- __config__ = [("name", "type", "desc", "default")]
- __description__ = """Base Plugin"""
- __author_name__ = ("RaNaN", "spoob", "mkaay")
- __author_mail__ = ("RaNaN@pyload.org", "spoob@pyload.org", "mkaay@mkaay.de")
-
def __init__(self, pyfile):
Base.__init__(self, pyfile.m.core)
diff --git a/module/plugins/PluginManager.py b/module/plugins/PluginManager.py
index f3f5f47bc..4bf41484a 100644
--- a/module/plugins/PluginManager.py
+++ b/module/plugins/PluginManager.py
@@ -29,6 +29,10 @@ from traceback import print_exc
from module.lib.SafeEval import const_eval as literal_eval
from module.ConfigParser import IGNORE
+from namedtuple import namedtuple
+
+PluginTuple = namedtuple("PluginTuple", "version pattern desc long_desc deps user name module")
+
class PluginManager:
ROOT = "module.plugins."
USERROOT = "userplugins."
@@ -40,6 +44,8 @@ class PluginManager:
DESC = re.compile(r'__description__.?=.?("|"""|\')([^"\']+)')
+ ATTR = re.compile(r'__([a-z0-9_])__\s*=\s*({|\[|\(|"|\')([^__]+)', re.M | re.I)
+
def __init__(self, core):
self.core = core