Пример #1
0
def deploy():
    loadPlugins()
    if not os.path.isfile(configurations_file_path()):
        print('The configuration file "%s" doesn\'t exist, create one by running the the application '
              'with "-dump" option' % configurations_file_path())
        sys.exit(1)
    with open(configurations_file_path(), 'r') as f: config = load(f)

    PACKAGE_EXTENDER.addFreezedPackage('__plugin__.')
    pluginModules = aop.modulesIn('__plugin__.**')
    for module in pluginModules.load().asList():
        if not isPackage(module) and re.match('__plugin__\\.[^\\.]+$', module.__name__):
            raise SetupError('The plugin setup module %r is not allowed directly in the __plugin__ package it needs '
                             'to be in a sub package' % module.__name__)

    assembly = ioc.open(pluginModules, config=config)
    try:
        assembly.processStart()
        from __plugin__.plugin.registry import services
        services = services()
    finally: ioc.deactivate()

    try: import application
    except ImportError: raise SetupError('Cannot access the application module')
    resourcesRegister = entityFor(IResourcesRegister, application.assembly)
    assert isinstance(resourcesRegister, IResourcesRegister), 'There is no resource register for the services'

    assert log.debug('Registered REST services:\n\t%s', '\n\t'.join(str(srv) for srv in services)) or True
    for service in services:
        resourcesRegister.register(service)
Пример #2
0
def plugins():
    PACKAGE_EXTENDER.addFreezedPackage('__plugin__.')
    pluginModules = aop.modulesIn('__plugin__.**')
    for module in pluginModules.load().asList():
        if not isPackage(module) and re.match('__plugin__\\.[^\\.]+$', module.__name__):
            raise SetupError('The plugin setup module \'%s\' is not allowed directly in the __plugin__ package it needs '
                             'to be in a sub package' % module.__name__)

    return context.open(pluginModules, included=True)
Пример #3
0
def plugins():
    PACKAGE_EXTENDER.addFreezedPackage('__plugin__.')
    pluginModules = aop.modulesIn('__plugin__.**')
    for module in pluginModules.load().asList():
        if not isPackage(module) and re.match('__plugin__\\.[^\\.]+$',
                                              module.__name__):
            raise SetupError(
                'The plugin setup module \'%s\' is not allowed directly in the __plugin__ package it needs '
                'to be in a sub package' % module.__name__)

    return context.open(pluginModules, included=True)
Пример #4
0
def openPlugins():
    ''' Add the plugins to the python path and also open the assembly for plugins'''
    loadPlugins()
    if not os.path.isfile(configurations_file_path()):
        print('The configuration file "%s" does not exist, create one by running the the application '
              'with "-dump" option' % configurations_file_path())
        sys.exit(1)
    with open(configurations_file_path(), 'r') as f: config = load(f)

    PACKAGE_EXTENDER.addFreezedPackage('__plugin__.')
    pluginModules = aop.modulesIn('__plugin__.**')
    for module in pluginModules.load().asList():
        if not isPackage(module) and re.match('__plugin__\\.[^\\.]+$', module.__name__):
            raise SetupError('The plugin setup module \'%s\' is not allowed directly in the __plugin__ package it needs '
                             'to be in a sub package' % module.__name__)

    context.open(pluginModules, config=config, included=True)
Пример #5
0
def deploy():
    for name in os.listdir(plugins_path()):
        fullPath = os.path.join(plugins_path(), name)
        if os.path.isfile(fullPath) and fullPath.endswith('.egg'):
            for exclude in excluded_plugins():
                if name.startswith(exclude): break
            else:
                if fullPath not in sys.path: sys.path.append(fullPath)

    isConfig, filePathConfig = os.path.isfile(configurations_file_path()), configurations_file_path()
    if isConfig:
        with open(filePathConfig, 'r') as f: config = load(f)
    else: config = {}

    PACKAGE_EXTENDER.addFreezedPackage('__plugin__.')
    pluginModules = aop.modulesIn('__plugin__.**')
    for module in pluginModules.load().asList():
        if not isPackage(module) and re.match('__plugin__\\.[^\\.]+$', module.__name__):
            raise SetupError('The plugin setup module %r is not allowed directly in the __plugin__ package it needs '
                             'to be in a sub package' % module.__name__)

    assembly = ioc.open(pluginModules, config=config)
    try:
        assembly.processStart()
        from __plugin__.plugin.registry import services
        services = services()
    except (ConfigError, SetupError):
        # We save the file in case there are missing configuration
        with open(filePathConfig, 'w') as f: save(assembly.trimmedConfigurations(), f)
        isConfig = True
        raise
    finally:
        if not isConfig:
            with open(filePathConfig, 'w') as f: save(assembly.trimmedConfigurations(), f)
        ioc.deactivate()

    import ally_deploy_application
    resourcesRegister = entityFor(IResourcesRegister, ally_deploy_application.assembly)
    assert isinstance(resourcesRegister, IResourcesRegister), 'There is no resource register for the services'

    assert log.debug('Registered REST services:\n\t%s', '\n\t'.join(str(srv) for srv in services)) or True
    for service in services:
        resourcesRegister.register(service)