Esempio n. 1
0
    def test_load_external_py_file(self):
        self.assertFalse(plugnplay.normalize_path(self.full_path) + '.someplugin' in sys.modules)

        plugnplay.set_plugin_dirs(self.full_path)
        plugnplay.load_plugins()

        self.assertTrue(plugnplay.normalize_path(self.full_path) + '.someplugin' in sys.modules)
        import someplugin  # Test de importing of the new plugin
        self.assertTrue(someplugin.SomePlugin is not None)
        p = someplugin.SomePlugin()
        self.assertTrue(isinstance(p, someplugin.SomePlugin))
Esempio n. 2
0
 def test_load_plugin_with_error(self):
     import sys
     plugnplay.set_plugin_dirs(join(self.basepath, 'wrong-plugins/'))
     mock_logger = Mock()
     plugnplay.load_plugins(logger = mock_logger)
     self.assertEquals(1, mock_logger.debug.call_count)
     call_args = mock_logger.debug.call_args
     self.assertEquals("Error loading plugin: myplugin",  call_args[0][0])
     self.assertTrue('exc_info' in call_args[1])
     self.assertTrue(call_args[1]['exc_info'] is not None)
     self.assertTrue('myplugin' not in sys.modules)
     self.assertTrue('otherplug' in sys.modules)
Esempio n. 3
0
 def test_load_plugin_with_error(self):
     import sys
     plugindir = join(self.basepath, 'wrong-plugins/')
     plugnplay.set_plugin_dirs(plugindir)
     mock_logger = Mock()
     plugnplay.load_plugins(logger=mock_logger)
     self.assertEquals(1, mock_logger.debug.call_count)
     call_args = mock_logger.debug.call_args
     self.assertEquals("Error loading plugin: myplugin",  call_args[0][0])
     self.assertTrue('exc_info' in call_args[1])
     self.assertTrue(call_args[1]['exc_info'] is not None)
     self.assertTrue('myplugin' not in sys.modules)
     self.assertTrue(plugnplay.normalize_path(plugindir) + '.otherplug' in sys.modules)
Esempio n. 4
0
    def test_load_plugin_with_error(self):
        import sys

        plugindir = join(self.basepath, "wrong-plugins/")
        plugnplay.set_plugin_dirs(plugindir)
        mock_logger = Mock()
        plugnplay.load_plugins(logger=mock_logger)
        self.assertEquals(1, mock_logger.debug.call_count)
        call_args = mock_logger.debug.call_args
        self.assertEquals("Error loading plugin: myplugin", call_args[0][0])
        self.assertTrue("exc_info" in call_args[1])
        self.assertTrue(call_args[1]["exc_info"] is not None)
        self.assertTrue("myplugin" not in sys.modules)
        self.assertTrue(plugnplay.normalize_path(plugindir) + ".otherplug" in sys.modules)
Esempio n. 5
0
    def test_load_same_name_different_folders(self):
        import sys
        dir1 = join(self.basepath, 'plugin/dir1')
        dir2 = join(self.basepath, 'plugin/dir2')
        plugnplay.set_plugin_dirs(dir1, dir2)
        plugnplay.load_plugins()

        dir1_norm = plugnplay.normalize_path(dir1)
        dir2_norm = plugnplay.normalize_path(dir2)

        self.assertTrue(dir1_norm + '.otherplugin' in sys.modules)
        self.assertTrue(dir2_norm + '.otherplugin' in sys.modules)

        mod1 = sys.modules[dir1_norm + '.otherplugin']
        self.assertTrue(mod1.MyPlugin.dir1)

        mod2 = sys.modules[dir2_norm + '.otherplugin']
        self.assertTrue(mod2.MyPlugin.dir2)
Esempio n. 6
0
  def run(self):
    if run_command():
      sys.exit(0)

    options = parser.parse_options()
    validate_input_params(app_path=options.app_path,\
        recv=options.recv, send=options.send)

    self.options = options  # Will be used by the signal handlers
    try:
      daemon_options = self._create_daemon_options(options)
      ctx = daemon.DaemonContext(**daemon_options)

      with ctx:
        # Now that we are chrooted (if desired) we should correct
        # the paths
        options.app_path = self._normalize_path(options)
        self._set_loggers(options)

        wsgidapp = WsgidApp(options.app_path)
        self.log.debug("Loading plugins from {pluginsdir}".format(pluginsdir=wsgidapp.pluginsdir))
        plugnplay.set_plugin_dirs(wsgidapp.pluginsdir)
        plugnplay.load_plugins(logger = self.log)

        self.log.debug("Using configs values {cfg}".format(cfg=options))
        self.log.debug("Dropping privileges to: uid={uid}, gid={gid}".format(uid=daemon_options['uid'], gid=daemon_options['gid']))
        self.log.info("Master process started")
        self.log.debug("Creating master pid file at {0}".format(self._return_pid_file_path(os.getpid(), self.MASTER)))
        self._write_pid(os.getpid(), self.MASTER)
        self._load_plugins(options)

        self.workers = []
        for worker in range(options.workers):
          pid = self._create_worker(options)
          self.workers.append(pid)
        #Now we can register the master process SIGTERM handler
        signal.signal(signal.SIGTERM, self._sigterm_handler)
        self._wait_workers()
    except Exception, e:
      import traceback
      exc = sys.exc_info()
      self.log.info("".join(traceback.format_exception(exc[0], exc[1], exc[2])))
      self._remove_pid(os.getpid(), self.MASTER)
      sys.exit(1)
Esempio n. 7
0
    def test_load_plugins_from_a_python_package(self):
        """
        See github issue #6.
        """
        from allinone.interface import AllInOne
        import allinone
        from allinone import interface
        all_in_one_dir = join(self.basepath, 'allinone')
        plugnplay.set_plugin_dirs(all_in_one_dir)
        logger = Mock()
        plugnplay.load_plugins(logger)

        # Check that we did not try to load a plugin named __init__.
        # See Github issue #9
        self.assertEquals(0, logger.debug.call_count)
        self.assertTrue(dirname(all_in_one_dir) in sys.path, "sys.path not modified correctly")
        self.assertEquals(len(AllInOne.implementors()), 1)
        self.assertEquals(len(allinone.interface.AllInOne.implementors()), 1)
        self.assertEquals(len(interface.AllInOne.implementors()), 1)
Esempio n. 8
0
def loadplugins( interfaces=[] ):    

    import time
    if not interfaces or len(interfaces) <= 0: return
    
    plugin_dirs = [plugins_path]
    from glob import glob
    plugin_dirs.extend( glob( os.path.join( os.path.dirname(addon_path), addon_id + '.extn.*', 'plugins' ) ) )
    
    import plugnplay
    plugnplay.set_plugin_dirs(*plugin_dirs)

    len_ifcs = len(interfaces)
    if len_ifcs == 1:
        interface = interfaces[0]
        plugnplay.load_plugins(interface.filecode)
    elif len_ifcs > 1:
        ifcs = []
        for interface in interfaces:
            ifcs.append(interface.filecode)
        plugnplay.load_plugins(ifcs)
Esempio n. 9
0
    def test_load_plugins_in_alphabetical_order(self):
        import os
        base_dir = os.path.join(self.basepath, 'sortedloading')
        dir1 = os.path.join(base_dir, 'dir1')
        dir2 = os.path.join(base_dir, 'dir2')
        dirs = [base_dir, dir1, dir2]

        plugnplay.set_plugin_dirs(*dirs)
        with mock.patch('plugnplay._import_module') as import_mock:
            plugnplay.load_plugins()
            assert 7 == import_mock.call_count
            #``aplug.py, dir1/aplug.py, dir2/bplug.by, dir1/cplug.py, dir2/dplug.py, dir2/pplug.py, zplug.py``
            call_list = [
                    mock.call(base_dir, 'aplug', logger=None),
                    mock.call(dir1, 'aplug', logger=None),
                    mock.call(dir2, 'bplug', logger=None),
                    mock.call(dir1, 'cplug', logger=None),
                    mock.call(dir2, 'dplug', logger=None),
                    mock.call(dir2, 'pplug', logger=None),
                    mock.call(base_dir, 'zplug', logger=None),
                    ]
            assert call_list == import_mock.call_args_list
Esempio n. 10
0
    def test_load_plugins_in_alphabetical_order(self):
        import os

        base_dir = os.path.join(self.basepath, "sortedloading")
        dir1 = os.path.join(base_dir, "dir1")
        dir2 = os.path.join(base_dir, "dir2")
        dirs = [base_dir, dir1, dir2]

        plugnplay.set_plugin_dirs(*dirs)
        with mock.patch("plugnplay._import_module") as import_mock:
            plugnplay.load_plugins()
            assert 7 == import_mock.call_count
            # ``aplug.py, dir1/aplug.py, dir2/bplug.by, dir1/cplug.py, dir2/dplug.py, dir2/pplug.py, zplug.py``
            call_list = [
                mock.call(base_dir, "aplug", logger=None),
                mock.call(dir1, "aplug", logger=None),
                mock.call(dir2, "bplug", logger=None),
                mock.call(dir1, "cplug", logger=None),
                mock.call(dir2, "dplug", logger=None),
                mock.call(dir2, "pplug", logger=None),
                mock.call(base_dir, "zplug", logger=None),
            ]
            assert call_list == import_mock.call_args_list
Esempio n. 11
0
def loadplugins(interfaces=[]):

    import time
    if not interfaces or len(interfaces) <= 0: return

    plugin_dirs = [plugins_path]
    from glob import glob
    plugin_dirs.extend(
        glob(
            os.path.join(os.path.dirname(addon_path), addon_id + '.extn.*',
                         'plugins')))

    import plugnplay
    plugnplay.set_plugin_dirs(*plugin_dirs)

    len_ifcs = len(interfaces)
    if len_ifcs == 1:
        interface = interfaces[0]
        plugnplay.load_plugins(interface.filecode)
    elif len_ifcs > 1:
        ifcs = []
        for interface in interfaces:
            ifcs.append(interface.filecode)
        plugnplay.load_plugins(ifcs)
Esempio n. 12
0
This module provides the main API for accessing the urlresolver features.

For most cases you probably want to use :func:`urlresolver.resolve` or 
:func:`urlresolver.choose_source`.
'''

import os
import common
import plugnplay
from plugnplay.interfaces import UrlResolver
from plugnplay.interfaces import PluginSettings
from plugnplay.interfaces import SiteAuth
import xbmcgui

#load all available plugins
plugnplay.set_plugin_dirs(common.plugins_path)
plugnplay.load_plugins()

def resolve(web_url):
    """
    Resolve a web page to a media stream.
    
    It is usually as simple as::
        
        import urlresolver
        media_url = urlresolver.resolve(web_url) 
        
    where ``web_url`` is the address of a web page which is associated with a 
    media file and ``media_url`` is the direct URL to the media. 

    Behind the scenes, :mod:`urlresolver` will check each of the available 
Esempio n. 13
0
 def test_add_plugin_path(self):
     plugnplay.set_plugin_dirs(self.full_path)
     self.assertEquals([self.full_path], plugnplay.plugin_dirs)
Esempio n. 14
0
 def test_add_relative_plugin_dir(self):
     try:
         plugnplay.set_plugin_dirs(['some/relative/path'])
         self.fail("Did not raise exception")
     except Exception:
         pass
Esempio n. 15
0
  '''
   Returns a tuple (short-help, long-help)
   about the command
  '''
  def help(self):
    pass

  '''
   Returns true if the command name passed as a paramater
   matches the command implemented by this interface
  '''
  def match_name(self, command):
    pass

  '''
   Run the specific command. Returns a string.
   Receives the username of the sender and any parameters
   passed on the message, eg:

    sender: process arg0 arg1 arg2

   would be translated to: run(sender, 'process', arg0, arg1, arg2)
  '''
  def run(self, user, command, *args):
    pass

commands_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), 'commands'))
plugnplay.set_plugin_dirs(commands_dir)
plugnplay.load_plugins()
Esempio n. 16
0
	:class:`HostedMediaFile`


'''

import os
import common
import plugnplay
from types import HostedMediaFile
from plugnplay.interfaces import UrlResolver
from plugnplay.interfaces import PluginSettings
from plugnplay.interfaces import SiteAuth
import xbmcgui

#load all available plugins
plugnplay.set_plugin_dirs(common.plugins_path)
plugnplay.load_plugins()


def resolve(web_url):
    '''
    Resolve a web page to a media stream.
    
    It is usually as simple as::
        
        import urlresolver
        media_url = urlresolver.resolve(web_url) 
        
    where ``web_url`` is the address of a web page which is associated with a 
    media file and ``media_url`` is the direct URL to the media. 
Esempio n. 17
0
import plugnplay
from alfredo.PyGtalkRobot import GtalkRobot

try:
    from bot_config import gmail_account, gmail_pass
except:
    gmail_account = 'your_gmail_account'
    gmail_pass = '******'

plugnplay.set_plugin_dirs('commands')
plugnplay.load_plugins()

bot = GtalkRobot()
bot.start(gmail_account, gmail_pass)
Esempio n. 18
0
'''
Skeleton framework, from Eldorados urlresolver, to allow the inclusion of modules at runtime.
Outline the base class in plugnplay/interfaces.py
Plugins go in the plugins folder and should use a class outlined in plugnplay/interfaces.py
plugnplay.man.implementors(YourClass), will return a list of plugins that implement specified class
'''

import os
import plugnplay
from plugnplay.interfaces import PnPTest

plugnplay.set_plugin_dirs(os.getcwd() + '/pnpimporter/plugins/')
plugnplay.load_plugins()

print plugnplay.man.implementors(PnPTest)
Esempio n. 19
0
File: cli.py Progetto: ildus/wsgid
 def _load_plugins(self, options):
   if options.loader_dir:
     plugnplay.set_plugin_dirs(*options.loader_dir)
     plugnplay.load_plugins()
Esempio n. 20
0
 def test_add_relative_plugin_dir(self):
     try:
         plugnplay.set_plugin_dirs(['some/relative/path'])
         self.fail("Did not raise exception")
     except Exception:
         pass
Esempio n. 21
0
 def test_add_plugin_path(self):
     plugnplay.set_plugin_dirs(self.full_path)
     self.assertEquals([self.full_path], plugnplay.plugin_dirs)
    import logging

    log_debug = logging.debug
    log_error = logging.error
    get_setting = lambda key: None
    import os

    plugins_path = os.path.join(os.path.dirname(__file__), "plugins")

# Load classes
from types import HostedMediaFile

# Load xbmc unrelated functions
from util import resolve
from util import filter_source_list

# Try to load xbmc related functions aswell
try:
    from xutil import choose_source
    from xutil import display_settings
    from xutil import show_small_
except ImportError:
    choose_source = NotImplemented
    display_settings = NotImplemented

#load all available plugins
import plugnplay

plugnplay.set_plugin_dirs(plugins_path)
plugnplay.load_plugins()
Esempio n. 23
0
 def _load_plugins(self, options):
     if options.loader_dir:
         plugnplay.set_plugin_dirs(*options.loader_dir)
         plugnplay.load_plugins()