summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--docs/module_overview.rst7
-rw-r--r--module/interaction/InteractionManager.py4
-rw-r--r--module/plugins/Base.py17
-rw-r--r--module/plugins/Crypter.py61
-rw-r--r--module/plugins/crypter/LinkList.py4
-rw-r--r--module/threads/BaseThread.py21
6 files changed, 68 insertions, 46 deletions
diff --git a/docs/module_overview.rst b/docs/module_overview.rst
index d51202c88..309dccdfd 100644
--- a/docs/module_overview.rst
+++ b/docs/module_overview.rst
@@ -7,11 +7,14 @@ You can find an overview of some important classes here:
:toctree: module
module.Api.Api
- module.plugins.Plugin.Base
- module.plugins.Plugin.Plugin
+ module.plugins.Base.Base
+ module.plugins.Hoster.Hoster
module.plugins.Crypter.Crypter
module.plugins.Account.Account
module.plugins.Hook.Hook
module.HookManager.HookManager
+ module.interaction.EventManager.EventManager
+ module.interaction.InteractionManager.InteractionManager
+ module.interaction.InteractionTask.InteractionTask
module.PyFile.PyFile
module.PyPackage.PyPackage
diff --git a/module/interaction/InteractionManager.py b/module/interaction/InteractionManager.py
index 8bb500f3b..5ebcd1fcd 100644
--- a/module/interaction/InteractionManager.py
+++ b/module/interaction/InteractionManager.py
@@ -15,14 +15,10 @@
@author: RaNaN
"""
-from time import time
from utils import lock
from traceback import print_exc
from threading import Lock
-
-
-
class InteractionManager:
"""
Class that gives ability to interact with the user.
diff --git a/module/plugins/Base.py b/module/plugins/Base.py
index b2338a01f..0ad0d5caa 100644
--- a/module/plugins/Base.py
+++ b/module/plugins/Base.py
@@ -90,18 +90,13 @@ class Base(object):
getattr(self.log, level)("%s: %s" % (self.__name__, sep.join([a if isinstance(a, basestring) else str(a) for a in args])))
- def setConf(self, option, value):
- """ see `setConfig` """
- self.core.config.set(self.__name__, option, value)
-
def setConfig(self, option, value):
""" Set config value for current plugin
:param option:
:param value:
- :return:
"""
- self.setConf(option, value)
+ self.core.config.set(self.__name__, option, value)
def getConf(self, option):
""" see `getConfig` """
@@ -148,11 +143,11 @@ class Base(object):
def load(self, url, get={}, post={}, ref=True, cookies=True, just_header=False, decode=False):
"""Load content at url and returns it
- :param url:
- :param get:
- :param post:
- :param ref:
- :param cookies:
+ :param url: url as string
+ :param get: GET as dict
+ :param post: POST as dict
+ :param ref: Set HTTP_REFERER header
+ :param cookies: use saved cookies
:param just_header: if True only the header will be retrieved and returned as dict
:param decode: Wether to decode the output according to http header, should be True in most cases
:return: Loaded content
diff --git a/module/plugins/Crypter.py b/module/plugins/Crypter.py
index c645f2a72..fe7f0deb8 100644
--- a/module/plugins/Crypter.py
+++ b/module/plugins/Crypter.py
@@ -27,23 +27,27 @@ class Package:
class PyFileMockup:
""" Legacy class needed by old crypter plugins """
- def __init__(self, url):
+ def __init__(self, url, pack):
self.url = url
self.name = url
+ self._package = pack
+ self.packageid = pack.id if pack else -1
+
+ def package(self):
+ return self._package
class Crypter(Base):
"""
Base class for (de)crypter plugins. Overwrite decrypt* methods.
- How to use decrypt* methods
- ---------------------------
+ How to use decrypt* methods:
You have to overwrite at least one method of decryptURL, decryptURLs, decryptFile.
- After decrypting and generating urls/packages you have to return the result at the\
- end of your method. Valid return Data is:
+ After decrypting and generating urls/packages you have to return the result.
+ Valid return Data is:
- `Package` instance
+ :class:`Package` instance Crypter.Package
A **new** package will be created with the name and the urls of the object.
List of urls and `Package` instances
@@ -52,9 +56,13 @@ class Crypter(Base):
"""
+ #: Prefix to annotate that the submited string for decrypting is indeed file content
+ CONTENT_PREFIX = "filecontent:"
+
@classmethod
def decrypt(cls, core, url_or_urls):
"""Static method to decrypt, something. Can be used by other plugins.
+ To decrypt file content prefix the string with ``CONTENT_PREFIX `` as seen above.
:param core: pyLoad `Core`, needed in decrypt context
:param url_or_urls: List of urls or single url/ file content
@@ -105,15 +113,18 @@ class Crypter(Base):
"""Decrypt a single url
:param url: url to decrypt
- :return: See `Crypter` Documentation
+ :return: See :class:`Crypter` Documentation
"""
- raise NotImplementedError
+ if url.startswith("http"): # basic method to redirect
+ return self.decryptFile(self.load(url))
+ else:
+ self.fail(_("Not existing file or unsupported protocol"))
def decryptURLs(self, urls):
"""Decrypt a bunch of urls
:param urls: list of urls
- :return: See `Crypter` Documentation
+ :return: See :class:`Crypter` Documentation
"""
raise NotImplementedError
@@ -121,12 +132,12 @@ class Crypter(Base):
"""Decrypt file content
:param content: content to decrypt as string
- :return: See `Crypter Documentation
+ :return: See :class:`Crypter` Documentation
"""
raise NotImplementedError
def generatePackages(self, urls):
- """Generates `Package` instances and names from urls. Usefull for many different link and no\
+ """Generates :class:`Package` instances and names from urls. Usefull for many different links and no\
given package name.
:param urls: list of urls
@@ -155,9 +166,12 @@ class Crypter(Base):
result.extend(to_list(self.decryptURL(url)))
elif has_method(cls, "decrypt"):
self.logDebug("Deprecated .decrypt() method in Crypter plugin")
- self.setup()
- self.decrypt()
- result = self.convertPackages()
+ result = []
+ for url in urls:
+ self.pyfile = PyFileMockup(url, self.package)
+ self.setup()
+ self.decrypt(self.pyfile)
+ result.extend(self.convertPackages())
else:
if not has_method(cls, "decryptFile") or urls:
self.logDebug("No suited decrypting method was overwritten in plugin")
@@ -175,7 +189,7 @@ class Crypter(Base):
return result
def processDecrypt(self, urls):
- """ Catches all exceptions in decrypt methods and return results
+ """Catches all exceptions in decrypt methods and return results
:return: Decrypting results
"""
@@ -187,10 +201,10 @@ class Crypter(Base):
return []
def getLocalContent(self, urls):
- """Load files from disk
+ """Load files from disk and seperate to file content and url list
:param urls:
- :return: content, remote urls
+ :return: list of (filename, content), remote urls
"""
content = []
# do nothing if no decryptFile method
@@ -198,8 +212,10 @@ class Crypter(Base):
remote = []
for url in urls:
path = None
- if url.startswith("http"):
+ if url.startswith("http"): # skip urls directly
pass
+ elif url.startswith(self.CONTENT_PREFIX):
+ path = url
elif exists(url):
path = url
elif exists(self.core.path(url)):
@@ -207,9 +223,12 @@ class Crypter(Base):
if path:
try:
- f = open(fs_encode(path), "rb")
- content.append((f.name, f.read()))
- f.close()
+ if path.startswith(self.CONTENT_PREFIX):
+ content.append(("", path[len(self.CONTENT_PREFIX)]))
+ else:
+ f = open(fs_encode(path), "rb")
+ content.append((f.name, f.read()))
+ f.close()
except IOError, e:
self.logError("IOError", e)
else:
diff --git a/module/plugins/crypter/LinkList.py b/module/plugins/crypter/LinkList.py
index 8e46f88a9..ebfa373eb 100644
--- a/module/plugins/crypter/LinkList.py
+++ b/module/plugins/crypter/LinkList.py
@@ -11,6 +11,10 @@ class LinkList(Crypter):
__author_name__ = ("spoob", "jeix")
__author_mail__ = ("spoob@pyload.org", "jeix@hasnomail.com")
+ # method declaration is needed here
+ def decryptURL(self, url):
+ return Crypter.decryptURL(self, url)
+
def decryptFile(self, content):
links = content.splitlines()
diff --git a/module/threads/BaseThread.py b/module/threads/BaseThread.py
index 1ba3f7a9f..f4885aadc 100644
--- a/module/threads/BaseThread.py
+++ b/module/threads/BaseThread.py
@@ -12,7 +12,7 @@ from types import MethodType
from pprint import pformat
from traceback import format_exc
-from module.utils.fs import listdir, join, save_join, stat
+from module.utils.fs import listdir, join, save_join, stat, exists
class BaseThread(Thread):
"""abstract base class for thread types"""
@@ -37,17 +37,22 @@ class BaseThread(Thread):
zip = zipfile.ZipFile(dump_name, "w")
- for f in listdir(join("tmp", name)):
- try:
- # avoid encoding errors
- zip.write(join("tmp", name, f), save_join(name, f))
- except:
- pass
+ if exists(join("tmp", name)):
+ for f in listdir(join("tmp", name)):
+ try:
+ # avoid encoding errors
+ zip.write(join("tmp", name, f), save_join(name, f))
+ except:
+ pass
info = zipfile.ZipInfo(save_join(name, "debug_Report.txt"), gmtime())
info.external_attr = 0644 << 16L # change permissions
-
zip.writestr(info, dump)
+
+ info = zipfile.ZipInfo(save_join(name, "system_Report.txt"), gmtime())
+ info.external_attr = 0644 << 16L
+ zip.writestr(info, self.getSystemDump())
+
zip.close()
if not stat(dump_name).st_size: