summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--module/HookManager.py31
-rw-r--r--module/database/FileDatabase.py30
-rw-r--r--module/interaction/EventManager.py22
-rw-r--r--module/plugins/Account.py4
-rw-r--r--module/plugins/AccountManager.py2
-rw-r--r--module/plugins/Base.py12
-rw-r--r--module/plugins/Hook.py48
-rw-r--r--pavement.py2
-rwxr-xr-xpyLoadCli.py4
-rwxr-xr-xpyLoadCore.py6
10 files changed, 86 insertions, 75 deletions
diff --git a/module/HookManager.py b/module/HookManager.py
index 386be0f5c..4b24f590a 100644
--- a/module/HookManager.py
+++ b/module/HookManager.py
@@ -15,7 +15,6 @@
along with this program; if not, see <http://www.gnu.org/licenses/>.
@author: RaNaN, mkaay
- @interface-version: 0.1
"""
import __builtin__
@@ -30,35 +29,7 @@ from module.plugins.PluginManager import literal_eval
from utils import lock
class HookManager:
- """Manages hooks, delegates and handles Events.
-
- Every plugin can define events, \
- but some very usefull events are called by the Core.
- Contrary to overwriting hook methods you can use event listener,
- which provides additional entry point in the control flow.
- Only do very short tasks or use threads.
-
- **Known Events:**
- Most hook methods exists as events. These are some additional known events.
-
- ===================== ============== ==================================
- Name Arguments Description
- ===================== ============== ==================================
- downloadPreparing fid A download was just queued and will be prepared now.
- downloadStarts fid A plugin will immediately starts the download afterwards.
- linksAdded links, pid Someone just added links, you are able to modify the links.
- allDownloadsProcessed Every link was handled, pyload would idle afterwards.
- allDownloadsFinished Every download in queue is finished.
- unrarFinished folder, fname An Unrar job finished
- configChanged sec,opt,value The config was changed.
- ===================== ============== ==================================
-
- | Notes:
- | allDownloadsProcessed is *always* called before allDownloadsFinished.
- | configChanged is *always* called before pluginConfigChanged.
-
-
- """
+ """ Manages hooks, loading, unloading. """
def __init__(self, core):
self.core = core
diff --git a/module/database/FileDatabase.py b/module/database/FileDatabase.py
index 116f2b02b..23e657ee4 100644
--- a/module/database/FileDatabase.py
+++ b/module/database/FileDatabase.py
@@ -39,7 +39,7 @@ class FileHandler:
def __init__(self, core):
"""Constructor"""
self.core = core
- self.ev = None #event manager, set later
+ self.evm = core.eventManager
# translations
self.statusMsg = [_("finished"), _("offline"), _("online"), _("queued"), _("skipped"), _("waiting"), _("temp. offline"), _("starting"), _("failed"), _("aborted"), _("decrypting"), _("custom"), _("downloading"), _("processing"), _("unknown")]
@@ -119,7 +119,7 @@ class FileHandler:
def addLinks(self, data, package):
"""Add links, data = (plugin, url) tuple. Internal method you should use API."""
self.db.addLinks(data, package)
- self.ev.dispatchEvent("packageUpdated", package)
+ self.evm.dispatchEvent("packageUpdated", package)
@lock
@@ -129,7 +129,7 @@ class FileHandler:
pid = self.db.addPackage(name, folder, queue, password)
p = self.db.getPackage(pid)
- self.ev.dispatchEvent("packageInserted", pid, p.queue, p.order)
+ self.evm.dispatchEvent("packageInserted", pid, p.queue, p.order)
return pid
@@ -155,7 +155,7 @@ class FileHandler:
pyfile.release()
self.db.deletePackage(p)
- self.ev.dispatchEvent("packageDeleted", id)
+ self.evm.dispatchEvent("packageDeleted", id)
if id in self.packageCache:
del self.packageCache[id]
@@ -187,7 +187,7 @@ class FileHandler:
self.db.deleteLink(f)
- self.ev.dispatchEvent("linkDeleted", id, pid)
+ self.evm.dispatchEvent("linkDeleted", id, pid)
p = self.getPackage(pid)
p.deleteIfEmpty()
@@ -211,12 +211,12 @@ class FileHandler:
def updateLink(self, pyfile):
"""updates link"""
self.db.updateLink(pyfile)
- self.ev.dispatchEvent("linkUpdated", pyfile.id, pyfile.packageid)
+ self.evm.dispatchEvent("linkUpdated", pyfile.id, pyfile.packageid)
def updatePackage(self, pypack):
"""updates a package"""
self.db.updatePackage(pypack)
- self.ev.dispatchEvent("packageUpdated", pypack.id)
+ self.evm.dispatchEvent("packageUpdated", pypack.id)
def getPackage(self, id):
"""return package instance"""
@@ -365,7 +365,7 @@ class FileHandler:
if id in self.packageCache:
self.packageCache[id].setFinished = False
- self.ev.dispatchEvent("packageUpdated", id)
+ self.evm.dispatchEvent("packageUpdated", id)
@lock
@change
@@ -379,7 +379,7 @@ class FileHandler:
self.db.restartFile(id)
- self.ev.dispatchEvent("linkUpdated", id)
+ self.evm.dispatchEvent("linkUpdated", id)
@lock
@@ -404,8 +404,8 @@ class FileHandler:
self.db.commit()
self.releasePackage(id)
- self.ev.dispatchEvent("packageDeleted", id)
- self.ev.dispatchEvent("packageInserted", id, p.queue, p.order)
+ self.evm.dispatchEvent("packageDeleted", id)
+ self.evm.dispatchEvent("packageInserted", id, p.queue, p.order)
@lock
@change
@@ -429,8 +429,8 @@ class FileHandler:
p.order = position
self.db.commit()
- self.ev.dispatchEvent("packageDeleted", id)
- self.ev.dispatchEvent("packageInserted", id, p.queue, p.order)
+ self.evm.dispatchEvent("packageDeleted", id)
+ self.evm.dispatchEvent("packageInserted", id, p.queue, p.order)
@lock
@change
@@ -457,14 +457,14 @@ class FileHandler:
self.db.commit()
- self.ev.dispatchEvent("packageUpdated", f["package"])
+ self.evm.dispatchEvent("packageUpdated", f["package"])
@change
def updateFileInfo(self, data, pid):
""" updates file info (name, size, status, url)"""
ids = self.db.updateLinkInfo(data)
- self.ev.dispatchEvent("packageUpdated", pid)
+ self.evm.dispatchEvent("packageUpdated", pid)
def checkPackageFinished(self, pyfile):
""" checks if package is finished and calls hookmanager """
diff --git a/module/interaction/EventManager.py b/module/interaction/EventManager.py
index 8a80553cf..931f50446 100644
--- a/module/interaction/EventManager.py
+++ b/module/interaction/EventManager.py
@@ -4,6 +4,28 @@ from time import time
from module.utils import uniqify
class EventManager:
+ """
+ Handles all Event related task, also stores an Event queue for clients, so they can retrieve them later.
+
+ **Known Events:**
+ Most hook methods exists as events. These are some additional known events.
+
+ ===================== ============== ==================================
+ Name Arguments Description
+ ===================== ============== ==================================
+ downloadPreparing fid A download was just queued and will be prepared now.
+ downloadStarts fid A plugin will immediately starts the download afterwards.
+ linksAdded links, pid Someone just added links, you are able to modify the links.
+ allDownloadsProcessed Every link was handled, pyload would idle afterwards.
+ allDownloadsFinished Every download in queue is finished.
+ unrarFinished folder, fname An Unrar job finished
+ configChanged sec,opt,value The config was changed.
+ ===================== ============== ==================================
+
+ | Notes:
+ | allDownloadsProcessed is *always* called before allDownloadsFinished.
+ | configChanged is *always* called before pluginConfigChanged.
+ """
def __init__(self, core):
self.core = core
self.clients = []
diff --git a/module/plugins/Account.py b/module/plugins/Account.py
index dcf36f8a0..59ce87ed2 100644
--- a/module/plugins/Account.py
+++ b/module/plugins/Account.py
@@ -48,6 +48,10 @@ class Account(Base, AccountInfo):
else:
activated = Account.activated
+ for opt in self.known_opt:
+ if opt not in options:
+ options[opt] = ""
+
for opt in options.keys():
if opt not in self.known_opt:
del options[opt]
diff --git a/module/plugins/AccountManager.py b/module/plugins/AccountManager.py
index 77139206c..00dd2ccc6 100644
--- a/module/plugins/AccountManager.py
+++ b/module/plugins/AccountManager.py
@@ -23,7 +23,7 @@ from random import choice
from module.common.json_layer import json
from module.utils import lock
-class AccountManager():
+class AccountManager:
"""manages all accounts"""
def __init__(self, core):
diff --git a/module/plugins/Base.py b/module/plugins/Base.py
index 0ad0d5caa..1477356ea 100644
--- a/module/plugins/Base.py
+++ b/module/plugins/Base.py
@@ -40,7 +40,7 @@ class Base(object):
__pattern__ = r""
#: Config definition: list of (name, type, verbose_name, default_value) or
#: (name, type, verbose_name, short_description, default_value)
- __config__ = tuple()
+ __config__ = list()
#: Short description, one liner
__description__ = ""
#: More detailed text
@@ -68,9 +68,17 @@ class Base(object):
self.log = core.log
#: core config
self.config = core.config
+ #: :class:`EventManager`
+ self.evm = core.eventManager
+ #: :class:`InteractionManager`
+ self.im = core.interActionManager
- #log functions
def logInfo(self, *args, **kwargs):
+ """ Print args to log at specific level
+
+ :param args: Arbitary object which should be logged
+ :param kwargs: sep=(how to seperate arguments), default = " | "
+ """
self._log("info", *args, **kwargs)
def logWarning(self, *args, **kwargs):
diff --git a/module/plugins/Hook.py b/module/plugins/Hook.py
index a3b86a794..fe464bdaa 100644
--- a/module/plugins/Hook.py
+++ b/module/plugins/Hook.py
@@ -14,8 +14,7 @@
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: mkaay
- @interface-version: 0.2
+ @author: RaNaN
"""
from traceback import print_exc
@@ -24,11 +23,24 @@ from Base import Base
class Expose(object):
""" used for decoration to declare rpc services """
-
def __new__(cls, f, *args, **kwargs):
hookManager.addRPC(f.__module__, f.func_name, f.func_doc)
return f
+def AddEventListener(event):
+ """ used to register method for events """
+ class _klass(object):
+ def __new__(cls, f, *args, **kwargs):
+ hookManager.addEventListener(f.__module__, f.func_name, event)
+ return f
+ return _klass
+
+class ConfigHandler(object):
+ """ register method as config handler """
+ def __new__(cls, f, *args, **kwargs):
+ hookManager.addConfigHandler(f.__module__, f.func_name)
+ return f
+
def threaded(f):
def run(*args,**kwargs):
hookManager.startThread(f, *args, **kwargs)
@@ -38,14 +50,6 @@ class Hook(Base):
"""
Base class for hook plugins.
"""
- __name__ = "Hook"
- __version__ = "0.2"
- __type__ = "hook"
- __threaded__ = []
- __config__ = [ ("name", "type", "desc" , "default") ]
- __description__ = """interface for hook"""
- __author_name__ = ("mkaay", "RaNaN")
- __author_mail__ = ("mkaay@mkaay.de", "RaNaN@pyload.org")
#: automatically register event listeners for functions, attribute will be deleted dont use it yourself
event_map = None
@@ -108,7 +112,11 @@ class Hook(Base):
def __repr__(self):
return "<Hook %s>" % self.__name__
-
+
+ def isActivated(self):
+ """ checks if hook is activated"""
+ return self.getConfig("activated")
+
def setup(self):
""" more init stuff if needed """
pass
@@ -116,11 +124,12 @@ class Hook(Base):
def unload(self):
""" called when hook was deactivated """
pass
-
- def isActivated(self):
- """ checks if hook is activated"""
- return self.config.get(self.__name__, "activated")
-
+
+ def deactivate(self):
+ pass
+
+ def activate(self):
+ pass
#event methods - overwrite these if needed
def coreReady(self):
@@ -134,10 +143,7 @@ class Hook(Base):
def downloadFinished(self, pyfile):
pass
-
- def downloadFailed(self, pyfile):
- pass
-
+
def packageFinished(self, pypack):
pass
diff --git a/pavement.py b/pavement.py
index ac9a6fa1a..8ebd5bfc5 100644
--- a/pavement.py
+++ b/pavement.py
@@ -23,7 +23,7 @@ if sys.version_info <= (2, 5):
setup(
name="pyload",
- version="0.4.9",
+ version="0.5.0",
description='Fast, lightweight and full featured download manager.',
long_description=open(PROJECT_DIR / "README").read(),
keywords = ('pyload', 'download-manager', 'one-click-hoster', 'download'),
diff --git a/pyLoadCli.py b/pyLoadCli.py
index 97e64dfee..d68b5faec 100755
--- a/pyLoadCli.py
+++ b/pyLoadCli.py
@@ -289,14 +289,14 @@ class Cli:
print _("Please use this syntax: add <Package name> <link> <link2> ...")
return
- self.client.addPackage(args[0], args[1:], Destination.Queue)
+ self.client.addPackage(args[0], args[1:], Destination.Queue, "")
elif command == "add_coll":
if len(args) < 2:
print _("Please use this syntax: add <Package name> <link> <link2> ...")
return
- self.client.addPackage(args[0], args[1:], Destination.Collector)
+ self.client.addPackage(args[0], args[1:], Destination.Collector, "")
elif command == "del_file":
self.client.deleteFiles([int(x) for x in args])
diff --git a/pyLoadCore.py b/pyLoadCore.py
index d1a557c43..f8b1ad6e8 100755
--- a/pyLoadCore.py
+++ b/pyLoadCore.py
@@ -362,6 +362,8 @@ class Core(object):
if self.config['ssl']['activated']:
self.check_install("OpenSSL", _("OpenSSL for secure connection"))
+
+ self.eventManager = EventManager(self)
self.setupDB()
if self.deleteLinks:
@@ -387,15 +389,13 @@ class Core(object):
#hell yeah, so many important managers :D
self.pluginManager = PluginManager(self)
- self.eventManager = EventManager(self)
+ self.interActionManager = None #stub
self.accountManager = AccountManager(self)
self.threadManager = ThreadManager(self)
self.captchaManager = CaptchaManager(self)
self.hookManager = HookManager(self)
self.remoteManager = RemoteManager(self)
- self.files.ev = self.eventManager
-
self.js = JsEngine()
self.log.info(_("Downloadtime: %s") % self.api.isTimeDownload())