Example #1
0
def start_modules(conf):
	ldebug('loading modules')

	modules_listeners = conf['modules']['listeners'].split(',')
	for key in range(0, len(modules_listeners)):
		modules_listeners[key] = modules_listeners[key].strip()
	modules_handlers = conf['modules']['handlers'].split(',')
	for key in range(0, len(modules_handlers)):
		modules_handlers[key] = modules_handlers[key].strip()
	modules_all = modules_listeners + modules_handlers

	plugins = {}
	for module_name in modules_all:

		if (modules.has_key(module_name)):
			continue

		ldebug('loading module %s' % module_name)
		try:
			module_file, module_path, module_info = find_module(module_name, conf['general']['modulepath'].split(','))
		except:
			lerror('unable to load module: %s' % module_name)
			continue

		try:
			module_object = load_module(module_name, module_file, module_path, module_info)
		finally:
			if (module_file):
				module_file.close()

		if (module_name in modules_listeners):
			try:
				for module_class in module_object.classes_list(1):
					plugins[module_class.__name__] = {}
					plugins[module_class.__name__]['type'] = [1,]
					ldebug('loading listener %s' % module_class.__name__)
					plugins[module_class.__name__]['object'] = module_class()
			except:
				lerror('unable to load listeners of module: %s' % module_name)

		if (module_name in modules_handlers):
			try:
				for module_class in module_object.classes_list(2):
					if (plugins.has_key(module_class.__name__)):
						plugins[module_class.__name__]['type'].append(2)
						continue

					plugins[module_class.__name__] = {}
					plugins[module_class.__name__]['type'] = [2,]
					
					ldebug('loading handler %s' % module_class.__name__)
					plugins[module_class.__name__]['object'] = module_class()
			except:
				lerror('unable to load handlers of module: %s' % module_name)
			
	return plugins
 def test_get_loaded_modules(self):
     
     #these can start to fail if other tests get ran before
     #and have imported modules that have not been previously been
     #deleted
     
     # detecting local modules
     from sys import modules
     self.assertFalse(modules.has_key('email'))
     self.assertFalse(modules.has_key('json'))
     
     import json        
     self.assertTrue(modules.has_key('json'))
     
     # when you select a component does the module get loaded too
     from threading import current_thread
     self.assertTrue(modules.has_key('threading'))
     
     # detecting global modules loaded
     # import pickle        
     self.assertTrue(modules.has_key('pickle'))
    def test_get_loaded_modules(self):

        #these can start to fail if other tests get ran before
        #and have imported modules that have not been previously been
        #deleted

        # detecting local modules
        from sys import modules
        self.assertFalse(modules.has_key('email'))
        self.assertFalse(modules.has_key('json'))

        import json
        self.assertTrue(modules.has_key('json'))

        # when you select a component does the module get loaded too
        from threading import current_thread
        self.assertTrue(modules.has_key('threading'))

        # detecting global modules loaded
        # import pickle
        self.assertTrue(modules.has_key('pickle'))
    def test_module_dynamic_loading(self):

        from importlib import import_module
        from sys import modules
        from os.path import basename, splitext

        module, ext = splitext(basename(self.tmp_module1))

        # load module dynamically
        import_module(module)
        self.assertTrue(modules.has_key(module))

        # make accessible in the global namespace
        self.assertEqual(modules['tmp_module'].foobar().boo(), "boo")
        globals()['tmp_module'] = modules[module]
        self.assertEqual(tmp_module.foobar().boo(), "boo")
 def test_module_dynamic_loading(self):
     
     from importlib import import_module    
     from sys import modules
     from os.path import basename, splitext
     
     module_filename = "tmp_module.py"
     module, ext = splitext(basename(module_filename))
     
     # load module dynamically
     import_module(module)
     self.assertTrue(modules.has_key(module)) 
     
     # make accessible in the global namespace
     self.assertEqual(modules['tmp_module'].foobar().boo(),"boo")
     globals()['tmp_module'] = modules[module]
     self.assertEqual(tmp_module.foobar().boo(),"boo")
    def test_get_loaded_modules_components(self):
        from sys import modules
        from inspect import getmembers
        
        # detecting components of local modules loaded
        from datetime import tzinfo
        
        m = _getmembers(modules[__name__])
        
        # the module gets loaded anyway
        self.assertTrue(modules.has_key('datetime'))
        # but is not in the namespace
        self.assertFalse(locals().has_key('datetime'))

        # the component however is in the namespace
        self.assertTrue(locals().has_key('tzinfo'))
                
        # detecting components of global modules loaded
        self.assertTrue(globals().has_key('randint'))
    def test_get_loaded_modules_components(self):
        from sys import modules
        from inspect import getmembers

        # detecting components of local modules loaded
        from datetime import tzinfo

        m = _getmembers(modules[__name__])

        # the module gets loaded anyway
        self.assertTrue(modules.has_key('datetime'))
        # but is not in the namespace
        self.assertFalse(locals().has_key('datetime'))

        # the component however is in the namespace
        self.assertTrue(locals().has_key('tzinfo'))

        # detecting components of global modules loaded
        self.assertTrue(globals().has_key('randint'))
Example #8
0
def __load_module__(module_abspathname, allowdupe=False):

    from importlib import import_module
    from sys import modules
    from os.path import basename, splitext, join, realpath
    import os
    import sys

    reldir = realpath(join(module_abspathname, ".."))
    module_name, ext = splitext(basename(module_abspathname))

    if modules.has_key(module_name) and allowdupe == False:
        raise Exception("dupe module", module_name)

    sys.path.append(reldir)
    import_module(module_name)

    globals()[module_name] = modules[module_name]

    return (modules[module_name])
Example #9
0
def __load_module__(module_abspathname,allowdupe=False):
    
    from importlib import import_module    
    from sys import modules
    from os.path import basename, splitext, join, realpath
    import os
    import sys
    
    reldir = realpath(join(module_abspathname,".."))
    module_name, ext = splitext(basename(module_abspathname))
    
    if modules.has_key(module_name) and allowdupe==False:
        raise Exception("dupe module",module_name)
        
    sys.path.append(reldir)
    import_module(module_name)
    
    globals()[module_name] = modules[module_name] 
    
    return(modules[module_name])
Example #10
0
def start_modules(conf):
    ldebug('loading modules')

    modules_listeners = conf['modules']['listeners'].split(',')
    for key in range(0, len(modules_listeners)):
        modules_listeners[key] = modules_listeners[key].strip()
    modules_handlers = conf['modules']['handlers'].split(',')
    for key in range(0, len(modules_handlers)):
        modules_handlers[key] = modules_handlers[key].strip()
    modules_all = modules_listeners + modules_handlers

    plugins = {}
    for module_name in modules_all:

        if (modules.has_key(module_name)):
            continue

        ldebug('loading module %s' % module_name)
        try:
            module_file, module_path, module_info = find_module(
                module_name, conf['general']['modulepath'].split(','))
        except:
            lerror('unable to load module: %s' % module_name)
            continue

        try:
            module_object = load_module(module_name, module_file, module_path,
                                        module_info)
        finally:
            if (module_file):
                module_file.close()

        if (module_name in modules_listeners):
            try:
                for module_class in module_object.classes_list(1):
                    plugins[module_class.__name__] = {}
                    plugins[module_class.__name__]['type'] = [
                        1,
                    ]
                    ldebug('loading listener %s' % module_class.__name__)
                    plugins[module_class.__name__]['object'] = module_class()
            except:
                lerror('unable to load listeners of module: %s' % module_name)

        if (module_name in modules_handlers):
            try:
                for module_class in module_object.classes_list(2):
                    if (plugins.has_key(module_class.__name__)):
                        plugins[module_class.__name__]['type'].append(2)
                        continue

                    plugins[module_class.__name__] = {}
                    plugins[module_class.__name__]['type'] = [
                        2,
                    ]

                    ldebug('loading handler %s' % module_class.__name__)
                    plugins[module_class.__name__]['object'] = module_class()
            except:
                lerror('unable to load handlers of module: %s' % module_name)

    return plugins
Example #11
0
#these few lines are taken from AppleMovieTrailers script
# Shared resources
BASE_RESOURCE_PATH = join( home, "resources" )
#DATA_PATH = xbmc.translatePath( "special://profile/addon_data/plugin.image.mypicsdb/")
DATA_PATH = Addon.getAddonInfo('profile')
PIC_PATH = join( BASE_RESOURCE_PATH, "images")
DB_PATH = xbmc.translatePath( "special://database/")
syspath.append( join( BASE_RESOURCE_PATH, "lib" ) )



__language__ = Addon.getLocalizedString

from urllib import unquote_plus
from traceback import print_exc,format_tb
if sysmodules.has_key("MypicsDB"):
    del sysmodules["MypicsDB"]
import MypicsDB as MPDB

global pictureDB
pictureDB = join(DB_PATH,"MyPictures.db")

from time import strftime,gmtime

from DialogAddonScan import AddonScan
from file_item import Thumbnails
global Exclude_folders #TODO
Exclude_folders = []
for path,recursive,update,exclude in MPDB.RootFolders():
    if exclude:
        #print path
Example #12
0
ID_BUSCARHEX= 105
ID_VEL=106
ID_PORT=107
ID_RTS=108


#Flag that indicates if the pic should be reseted using the RTS pin
RESET_RTS=False

# Use wxversion to import wxpython 
MIN_WX_VERSION  = '2.6'
GET_WXPYTHON    = 'Get it from http://www.wxpython.org!'

try:
    import wxversion
    if modules.has_key('wx') or modules.has_key('wxPython'):
        pass    #probably not the first call to this module: wxPython already loaded
    else:
        #wxversion.select('2.6')
        wxversion.ensureMinimal(MIN_WX_VERSION)
except ImportError:
    #the old fashioned way as not everyone seems to have wxversion installed
    try:
        import wx
        if wx.VERSION_STRING < MIN_WX_VERSION:
            print 'You need to upgrade wxPython to v%s (or higher) to run pytbl.'%MIN_WX_VERSION
            print GET_WXPYTHON
            exit()
    except ImportError:
            print "Error: pytbl requires wxPython, which doesn't seem to be installed."
            print GET_WXPYTHON
Example #13
0
ID_TRANSFERFILE = 104
ID_BUSCARHEX = 105
ID_VEL = 106
ID_PORT = 107
ID_RTS = 108

#Flag that indicates if the pic should be reseted using the RTS pin
RESET_RTS = False

# Use wxversion to import wxpython
MIN_WX_VERSION = '2.6'
GET_WXPYTHON = 'Get it from http://www.wxpython.org!'

try:
    import wxversion
    if modules.has_key('wx') or modules.has_key('wxPython'):
        pass  #probably not the first call to this module: wxPython already loaded
    else:
        #wxversion.select('2.6')
        wxversion.ensureMinimal(MIN_WX_VERSION)
except ImportError:
    #the old fashioned way as not everyone seems to have wxversion installed
    try:
        import wx
        if wx.VERSION_STRING < MIN_WX_VERSION:
            print 'You need to upgrade wxPython to v%s (or higher) to run pytbl.' % MIN_WX_VERSION
            print GET_WXPYTHON
            exit()
    except ImportError:
        print "Error: pytbl requires wxPython, which doesn't seem to be installed."
        print GET_WXPYTHON