diff options
Diffstat (limited to 'pyload')
-rw-r--r-- | pyload/AddonManager.py | 24 | ||||
-rw-r--r-- | pyload/FileManager.py | 8 | ||||
-rw-r--r-- | pyload/api/AddonApi.py | 8 | ||||
-rw-r--r-- | pyload/api/FileApi.py | 14 | ||||
-rw-r--r-- | pyload/datatypes/PyPackage.py | 6 | ||||
-rw-r--r-- | pyload/plugins/addons/ExtractArchive.py | 5 | ||||
-rw-r--r-- | pyload/remote/apitypes.py | 16 | ||||
-rw-r--r-- | pyload/remote/apitypes_debug.py | 12 | ||||
-rw-r--r-- | pyload/remote/pyload.thrift | 32 | ||||
-rw-r--r-- | pyload/web/app/scripts/models/AddonHandler.js | 7 | ||||
-rw-r--r-- | pyload/web/app/scripts/views/dashboard/packageView.js | 2 |
11 files changed, 76 insertions, 58 deletions
diff --git a/pyload/AddonManager.py b/pyload/AddonManager.py index 5c5524061..6fa0c5849 100644 --- a/pyload/AddonManager.py +++ b/pyload/AddonManager.py @@ -18,7 +18,6 @@ import __builtin__ from gettext import gettext -from copy import copy from thread import start_new_thread from threading import RLock @@ -27,7 +26,7 @@ from new_collections import namedtuple from types import MethodType -from pyload.Api import AddonService, AddonInfo +from pyload.Api import AddonService, AddonInfo, ServiceException, ServiceDoesNotExist from pyload.threads.AddonThread import AddonThread from utils import lock, to_string @@ -70,14 +69,27 @@ class AddonManager: self.call(inst, event, *args) self.dispatchEvent(eventName, *args) - def call(self, addon, f, *args): + def call(self, plugin, f, *args): try: - func = getattr(addon, f) + func = getattr(plugin, f) return func(*args) except Exception, e: - addon.logError(_("Error when executing %s" % f), e) + plugin.logError(_("Error when executing %s" % f), e) self.core.print_exc() + def invoke(self, plugin, func_name, args): + """ Invokes a registered method """ + + if plugin not in self.plugins and func_name not in self.plugins[plugin].handler: + raise ServiceDoesNotExist(plugin, func_name) + + # TODO: choose correct instance + try: + func = getattr(self.plugins[plugin].instances[0], func_name) + return func(*args) + except Exception, e: + raise ServiceException(e.message) + @lock def createIndex(self): active = [] @@ -159,7 +171,7 @@ class AddonManager: self.log.debug("Removed callback %s" % self.core.scheduler.removeJob(addon.cb)) # todo: only delete instances, meta data is lost otherwise - del self.plugins[addon.__name__] + del self.plugins[addon.__name__].instances[:] # TODO: could be improved #remove event listener diff --git a/pyload/FileManager.py b/pyload/FileManager.py index 614418f99..61c164316 100644 --- a/pyload/FileManager.py +++ b/pyload/FileManager.py @@ -21,7 +21,7 @@ from ReadWriteLock import ReadWriteLock from pyload.utils import lock, read_lock -from Api import PackageStatus, DownloadStatus as DS, TreeCollection, PackageDoesNotExists +from Api import PackageStatus, DownloadStatus as DS, TreeCollection, PackageDoesNotExist from datatypes.PyFile import PyFile from datatypes.PyPackage import PyPackage, RootPackage @@ -529,8 +529,8 @@ class FileManager: p = self.getPackageInfo(pid) dest = self.getPackageInfo(root) - if not p: raise PackageDoesNotExists(pid) - if not dest: raise PackageDoesNotExists(root) + if not p: raise PackageDoesNotExist(pid) + if not dest: raise PackageDoesNotExist(root) # cantor won't be happy if we put the package in itself if pid == root or p.root == root: return False @@ -552,7 +552,7 @@ class FileManager: if not f or f.package == pid: return False if not self.getPackageInfo(pid): - raise PackageDoesNotExists(pid) + raise PackageDoesNotExist(pid) # TODO move real files diff --git a/pyload/api/AddonApi.py b/pyload/api/AddonApi.py index 7a1a651fc..cb82781b1 100644 --- a/pyload/api/AddonApi.py +++ b/pyload/api/AddonApi.py @@ -39,14 +39,14 @@ class AddonApi(ApiComponent): return handler @RequirePerm(Permission.Interaction) - def callAddon(self, plugin, func, arguments): + def invokeAddon(self, plugin, func, func_args): """ Calls any function exposed by an addon """ - pass + return self.core.addonManager.invoke(plugin, func, func_args) @RequirePerm(Permission.Interaction) - def callAddonHandler(self, plugin, func, pid_or_fid): + def invokeAddonHandler(self, plugin, func, pid_or_fid): """ Calls an addon handler registered to work with packages or files """ - pass + return self.invokeAddon(plugin, func, (pid_or_fid, )) if Api.extend(AddonApi): diff --git a/pyload/api/FileApi.py b/pyload/api/FileApi.py index 984729b8c..5bb8e21e7 100644 --- a/pyload/api/FileApi.py +++ b/pyload/api/FileApi.py @@ -1,7 +1,7 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -from pyload.Api import Api, RequirePerm, Permission, DownloadState, PackageDoesNotExists, FileDoesNotExists +from pyload.Api import Api, RequirePerm, Permission, DownloadState, PackageDoesNotExist, FileDoesNotExist from pyload.utils import uniqify from ApiComponent import ApiComponent @@ -52,12 +52,12 @@ class FileApi(ApiComponent): """Returns information about package, without detailed information about containing files :param pid: package id - :raises PackageDoesNotExists: + :raises PackageDoesNotExist: :return: :class:`PackageInfo` """ info = self.core.files.getPackageInfo(pid) if not info: - raise PackageDoesNotExists(pid) + raise PackageDoesNotExist(pid) return info @RequirePerm(Permission.All) @@ -65,13 +65,13 @@ class FileApi(ApiComponent): """ Info for specific file :param fid: file id - :raises FileDoesNotExists: + :raises FileDoesNotExist: :return: :class:`FileInfo` """ info = self.core.files.getFileInfo(fid) if not info: - raise FileDoesNotExists(fid) + raise FileDoesNotExist(fid) return info def getFilePath(self, fid): @@ -103,7 +103,7 @@ class FileApi(ApiComponent): """ pid = pack.pid p = self.core.files.getPackage(pid) - if not p: raise PackageDoesNotExists(pid) + if not p: raise PackageDoesNotExist(pid) #TODO: fix for key, value in data.iteritems(): @@ -124,7 +124,7 @@ class FileApi(ApiComponent): :param pid: package id :param root: package id of new root - :raises PackageDoesNotExists: When pid or root is missing + :raises PackageDoesNotExist: When pid or root is missing :return: False if package can't be moved """ return self.core.files.movePackage(pid, root) diff --git a/pyload/datatypes/PyPackage.py b/pyload/datatypes/PyPackage.py index ba38781eb..fa58c0fd2 100644 --- a/pyload/datatypes/PyPackage.py +++ b/pyload/datatypes/PyPackage.py @@ -66,9 +66,9 @@ class PyPackage: self.comment, self.password, self.added, self.tags, self.status, self.shared, self.packageorder ) - def getChildren(self): - """get fids of container files""" - return self.m.getPackageInfo(self.pid).fids + def getFiles(self): + """get contaied files data""" + return self.m.core.db.getAllFiles(package=self.pid) def getPath(self, name=""): self.timestamp = time() diff --git a/pyload/plugins/addons/ExtractArchive.py b/pyload/plugins/addons/ExtractArchive.py index 67fa5c820..c3c5dbeb7 100644 --- a/pyload/plugins/addons/ExtractArchive.py +++ b/pyload/plugins/addons/ExtractArchive.py @@ -51,9 +51,10 @@ if os.name != "nt": from pyload.utils.fs import safe_join as save_join, fs_encode -from pyload.plugins.Addon import Addon, threaded, AddonHandler, AddonProperty +from pyload.plugins.Addon import Addon, threaded, AddonHandler from pyload.plugins.internal.AbstractExtractor import ArchiveError, CRCError, WrongPassword +# TODO: plugin needs a rewrite to work on unfinished packages class ExtractArchive(Addon): """ @@ -161,7 +162,7 @@ class ExtractArchive(Addon): if not exists(out): makedirs(out) - files_ids = [(save_join(dl, p.folder, x["name"]), x["id"]) for x in p.getChildren().itervalues()] + files_ids = [(save_join(dl, p.folder, f.name), f.fid) for f in p.getFiles().itervalues()] matched = False # check as long there are unseen files diff --git a/pyload/remote/apitypes.py b/pyload/remote/apitypes.py index 6a7d2f063..decfbb8b3 100644 --- a/pyload/remote/apitypes.py +++ b/pyload/remote/apitypes.py @@ -194,7 +194,7 @@ class EventInfo(BaseObject): self.eventname = eventname self.event_args = event_args -class FileDoesNotExists(ExceptionObject): +class FileDoesNotExist(ExceptionObject): __slots__ = ['fid'] def __init__(self, fid=None): @@ -261,7 +261,7 @@ class OnlineCheck(BaseObject): self.rid = rid self.data = data -class PackageDoesNotExists(ExceptionObject): +class PackageDoesNotExist(ExceptionObject): __slots__ = ['pid'] def __init__(self, pid=None): @@ -323,7 +323,7 @@ class ServerStatus(BaseObject): self.download = download self.reconnect = reconnect -class ServiceDoesNotExists(ExceptionObject): +class ServiceDoesNotExist(ExceptionObject): __slots__ = ['plugin', 'func'] def __init__(self, plugin=None, func=None): @@ -364,7 +364,7 @@ class UserData(BaseObject): self.user = user self.templateName = templateName -class UserDoesNotExists(ExceptionObject): +class UserDoesNotExist(ExceptionObject): __slots__ = ['user'] def __init__(self, user=None): @@ -383,10 +383,6 @@ class Iface(object): pass def addUser(self, username, password): pass - def callAddon(self, plugin, func, arguments): - pass - def callAddonHandler(self, plugin, func, pid_or_fid): - pass def checkContainer(self, filename, data): pass def checkHTML(self, html, url): @@ -463,6 +459,10 @@ class Iface(object): pass def getWSAddress(self): pass + def invokeAddon(self, plugin, func, func_args): + pass + def invokeAddonHandler(self, plugin, func, pid_or_fid): + pass def isInteractionWaiting(self, mode): pass def loadConfig(self, name): diff --git a/pyload/remote/apitypes_debug.py b/pyload/remote/apitypes_debug.py index 14b0cc98e..7c19235c2 100644 --- a/pyload/remote/apitypes_debug.py +++ b/pyload/remote/apitypes_debug.py @@ -27,23 +27,23 @@ classes = { 'DownloadInfo' : [basestring, basestring, basestring, int, basestring, basestring], 'DownloadProgress' : [int, int, int, int], 'EventInfo' : [basestring, (list, basestring)], - 'FileDoesNotExists' : [int], + 'FileDoesNotExist' : [int], 'FileInfo' : [int, basestring, int, int, int, int, int, int, int, (None, DownloadInfo)], 'Input' : [int, (None, basestring), (None, basestring)], 'InteractionTask' : [int, int, Input, basestring, basestring, basestring], 'InvalidConfigSection' : [basestring], 'LinkStatus' : [basestring, basestring, int, int, (None, basestring), (None, basestring)], 'OnlineCheck' : [int, (dict, basestring, LinkStatus)], - 'PackageDoesNotExists' : [int], + 'PackageDoesNotExist' : [int], 'PackageInfo' : [int, basestring, basestring, int, int, basestring, basestring, basestring, int, (list, basestring), int, bool, int, PackageStats, (list, int), (list, int)], 'PackageStats' : [int, int, int, int], 'ProgressInfo' : [basestring, basestring, basestring, int, int, int, (None, DownloadProgress)], 'ServerStatus' : [int, int, int, int, int, bool, bool, bool, bool], - 'ServiceDoesNotExists' : [basestring, basestring], + 'ServiceDoesNotExist' : [basestring, basestring], 'ServiceException' : [basestring], 'TreeCollection' : [PackageInfo, (dict, int, FileInfo), (dict, int, PackageInfo)], 'UserData' : [int, basestring, basestring, int, int, basestring, int, int, basestring, int, int, basestring], - 'UserDoesNotExists' : [basestring], + 'UserDoesNotExist' : [basestring], } methods = { @@ -53,8 +53,6 @@ methods = { 'addPackageChild': int, 'addPackageP': int, 'addUser': UserData, - 'callAddon': basestring, - 'callAddonHandler': basestring, 'checkContainer': OnlineCheck, 'checkHTML': OnlineCheck, 'checkLinks': OnlineCheck, @@ -93,6 +91,8 @@ methods = { 'getServerVersion': basestring, 'getUserData': UserData, 'getWSAddress': basestring, + 'invokeAddon': basestring, + 'invokeAddonHandler': basestring, 'isInteractionWaiting': bool, 'loadConfig': ConfigHolder, 'login': bool, diff --git a/pyload/remote/pyload.thrift b/pyload/remote/pyload.thrift index 07782ef42..da00bc680 100644 --- a/pyload/remote/pyload.thrift +++ b/pyload/remote/pyload.thrift @@ -306,19 +306,19 @@ struct OnlineCheck { // exceptions -exception PackageDoesNotExists { +exception PackageDoesNotExist { 1: PackageID pid } -exception FileDoesNotExists { +exception FileDoesNotExist { 1: FileID fid } -exception UserDoesNotExists { +exception UserDoesNotExist { 1: string user } -exception ServiceDoesNotExists { +exception ServiceDoesNotExist { 1: string plugin 2: string func } @@ -414,8 +414,8 @@ service Pyload { PackageID uploadContainer(1: string filename, 2: binary data), - void addLinks(1: PackageID pid, 2: LinkList links) throws (1: PackageDoesNotExists e), - void addLocalFile(1: PackageID pid, 2: string name, 3: string path) throws (1: PackageDoesNotExists e) + void addLinks(1: PackageID pid, 2: LinkList links) throws (1: PackageDoesNotExist e), + void addLocalFile(1: PackageID pid, 2: string name, 3: string path) throws (1: PackageDoesNotExist e) // these are real file operations and WILL delete files on disk void deleteFiles(1: list<FileID> fids), @@ -444,8 +444,8 @@ service Pyload { // same as above with full=False TreeCollection getPackageContent(1: PackageID pid), - PackageInfo getPackageInfo(1: PackageID pid) throws (1: PackageDoesNotExists e), - FileInfo getFileInfo(1: FileID fid) throws (1: FileDoesNotExists e), + PackageInfo getPackageInfo(1: PackageID pid) throws (1: PackageDoesNotExist e), + FileInfo getFileInfo(1: FileID fid) throws (1: FileDoesNotExist e), TreeCollection findFiles(1: string pattern), TreeCollection findPackages(1: list<string> tags), @@ -454,12 +454,12 @@ service Pyload { // Modify Files/Packages // moving package while downloading is not possible, so they will return bool to indicate success - void updatePackage(1: PackageInfo pack) throws (1: PackageDoesNotExists e), - bool setPackageFolder(1: PackageID pid, 2: string path) throws (1: PackageDoesNotExists e), + void updatePackage(1: PackageInfo pack) throws (1: PackageDoesNotExist e), + bool setPackageFolder(1: PackageID pid, 2: string path) throws (1: PackageDoesNotExist e), // as above, this will move files on disk - bool movePackage(1: PackageID pid, 2: PackageID root) throws (1: PackageDoesNotExists e), - bool moveFiles(1: list<FileID> fids, 2: PackageID pid) throws (1: PackageDoesNotExists e), + bool movePackage(1: PackageID pid, 2: PackageID root) throws (1: PackageDoesNotExist e), + bool moveFiles(1: list<FileID> fids, 2: PackageID pid) throws (1: PackageDoesNotExist e), void orderPackage(1: list<PackageID> pids, 2: i16 position), void orderFiles(1: list<FileID> fids, 2: PackageID pid, 3: i16 position), @@ -518,12 +518,12 @@ service Pyload { map<PluginName, list<AddonService>> getAddonHandler(), - JSONString callAddon(1: PluginName plugin, 2: string func, 3: list<JSONString> arguments) - throws (1: ServiceDoesNotExists e, 2: ServiceException ex), + JSONString invokeAddon(1: PluginName plugin, 2: string func, 3: list<JSONString> func_args) + throws (1: ServiceDoesNotExist e, 2: ServiceException ex), // special variant of callAddon that works on the media types, acccepting integer - JSONString callAddonHandler(1: PluginName plugin, 2: string func, 3: PackageID pid_or_fid) - throws (1: ServiceDoesNotExists e, 2: ServiceException ex), + JSONString invokeAddonHandler(1: PluginName plugin, 2: string func, 3: PackageID pid_or_fid) + throws (1: ServiceDoesNotExist e, 2: ServiceException ex), //scheduler diff --git a/pyload/web/app/scripts/models/AddonHandler.js b/pyload/web/app/scripts/models/AddonHandler.js index 8a138b45d..8e69d0410 100644 --- a/pyload/web/app/scripts/models/AddonHandler.js +++ b/pyload/web/app/scripts/models/AddonHandler.js @@ -49,7 +49,12 @@ define(['jquery', 'backbone', 'underscore', 'app', 'utils/apitypes'], // dispatches call to the plugin invoke: function(plugin, func, args, success) { - console.log(plugin, func, args); + console.log('Invoking addon', plugin, func, args); + return $.ajax(App.apiRequest('invokeAddon', { + plugin: plugin, + func: func, + func_args: args + }, {sucess: success})); } }); });
\ No newline at end of file diff --git a/pyload/web/app/scripts/views/dashboard/packageView.js b/pyload/web/app/scripts/views/dashboard/packageView.js index 30121c344..1bb250f27 100644 --- a/pyload/web/app/scripts/views/dashboard/packageView.js +++ b/pyload/web/app/scripts/views/dashboard/packageView.js @@ -87,7 +87,7 @@ define(['jquery', 'app', 'views/abstract/itemView', 'underscore', 'hbs!tpl/dashb if (el.context.tagName === 'IMG') el = el.parent(); - App.addons.invoke(el.data('plugin'), el.data('func'), this.model.get('pid')); + App.addons.invoke(el.data('plugin'), el.data('func'), [this.model.get('pid')]); } }); |