def load_plugin_file(filename, failover_filename=None, min_priority=0, max_priority=None): """ Load plugins from a file (able to restrict by priority). If the first file doesn't exist then the failover_filename is loaded. This is so that we can have a 'default' plugin file which can be optionally overwritten if another file exists. """ fn = filename if not os.path.exists(filename): if failover_filename and os.path.exists(failover_filename): fn = failover_filename else: return with open(fn) as f: for line in f.readlines(): line = line.strip() if line and not line.startswith("#"): priority, plugin = line.split(":") priority = int(priority) if not min_priority or priority > min_priority: if not max_priority or priority < max_priority: #Load this plugin print 'loading plugin %s at priority %s' % (plugin, priority) try: util.import_class(plugin) print 'enabling plugin %s' % (plugin, ) enable_plugin(plugin) except: log.err()
def load_class(controller, *args, **kwargs): """ Load the class given by the string 'controller' """ if controller in controllers: return controllers[controller] attempts = [ controller, "%s.%s" % (config.app_name, controller), "%s.controllers.%s" % (config.app_name, controller), "gyro.%s" % (controller, ), "gyro.builtins.%s" % (controller, ), "gyro.builtins.%s.%s" % (controller, controller), ] common = set(attempts).intersection(controllers.keys()) if common: c = controllers[list(common)[0]] return c for attempt in attempts: try: cls = util.import_class(attempt) controllers[attempt] = cls(*args, **kwargs) controllers[attempt].on_loaded() return controllers[attempt] except ImportError: pass raise ImportError("Unable to find import for %s" % (controller, ))
def __call__(self, cls): if not self.provider: p = config.get("gyro-auth-provider", "gyro.auth.AuthProvider") provider = util.import_class(p) cls.auth_provider = provider else: cls.auth_provider = self.provider return cls
def __init__(self, storage=None): if not storage: s = config.get("gyro-session-storage", "gyro.builtins.session.InMemorySessionStorage") self.storage = util.import_class(s)() else: self.storage = storage self.session_timeout = datetime.timedelta(hours=config.get( "gyro-session-timeout", 24))
def __init__(self, storage=None): if not storage: s = config.get("gyro-auth-token-storage", "gyro.builtins.auth.InMemoryAuthTokenStorage") self.storage = util.import_class(s)() else: self.storage = storage self.token_valid_time = datetime.timedelta(days=config.get( "gyro-auth-token-timeout", 90))
def start(**kwargs): """ Start our HTTP server """ s = config.get('server', 'gyro.impl.twisted.server.HttpServer') port = kwargs.get("port", None) if not port: port = config.get("port", 9999) server = util.import_class(s) print 'Starting server %s on port %s' % (server, port) core.server = server() core.server.run(port) if not config.development and config.get("gyro-smart-reload", True): plugin.load_second_plugins()
def load(core_string): """ Load a core """ c = util.import_class(core_string)() core = sys.modules.get("gyro.core") core.Deferred = c.Deferred core.run = c.run core.call_later = c.call_later core.defer_later = c.defer_later core.call_when_running = c.call_when_running core.call_on_shutdown = c.call_on_shutdown core.cancel_call_on_shutdown = c.cancel_call_on_shutdown core.maybe_deferred = c.maybe_deferred global CORE CORE = c