Ejemplo n.º 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)
def deploy():
    package_extender.PACKAGE_EXTENDER.addFreezedPackage('__setup__.')
    from ally.container import ioc, aop
    from ally.container.ioc import ConfigError, SetupError
    from ally.container.config import save, load

    global assembly
    if assembly: raise ImportError('The application is already deployed')

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

        assembly = ioc.open(aop.modulesIn('__setup__.**'), config=config)
        try: assembly.processStart()
        except (ConfigError, SetupError):
            # We save the file in case there are missing configuration
            with open(configurationsFilePath, 'w') as f: save(assembly.trimmedConfigurations(), f)
            isConfig = True
            raise
        finally:
            if not isConfig:
                with open(configurationsFilePath, 'w') as f: save(assembly.trimmedConfigurations(), f)
            ioc.deactivate()
    except:
        print('-' * 150, file=sys.stderr)
        print('A problem occurred while deploying', file=sys.stderr)
        traceback.print_exc()
        print('-' * 150, file=sys.stderr)
Ejemplo n.º 3
0
def deploy():
    assert isinstance(application.options, OptionsCore), 'Invalid application options %s' % application.options
    if not application.options.start: return
    try:
        if not os.path.isfile(application.options.configurationPath):
            print('The configuration file "%s" doesn\'t exist, create one by running the the application '
                  'with "-dump" option' % application.options.configurationPath, file=sys.stderr)
            sys.exit(1)
        with open(application.options.configurationPath, 'r') as f: config = load(f)

        assembly = application.assembly = ioc.open(aop.modulesIn('__setup__.**'), config=config)
        assert isinstance(assembly, Assembly), 'Invalid assembly %s' % assembly
        
        import logging
        logging.basicConfig(format=format())
        for name in warning_for(): logging.getLogger(name).setLevel(logging.WARN)
        for name in info_for(): logging.getLogger(name).setLevel(logging.INFO)
        for name in debug_for(): logging.getLogger(name).setLevel(logging.DEBUG)
        
        try: assembly.processStart()
        finally: ioc.deactivate()
    except SystemExit: raise
    except (SetupError, ConfigError):
        print('-' * 150, file=sys.stderr)
        print('A setup or configuration error occurred while deploying, try to rebuild the application properties by '
              'running the the application with "configure components" options', file=sys.stderr)
        traceback.print_exc(file=sys.stderr)
        print('-' * 150, file=sys.stderr)
    except:
        print('-' * 150, file=sys.stderr)
        print('A problem occurred while deploying', file=sys.stderr)
        traceback.print_exc(file=sys.stderr)
        print('-' * 150, file=sys.stderr)
Ejemplo n.º 4
0
def dump():
    assert isinstance(application.options, OptionsCore), 'Invalid application options %s' % application.options
    if not application.options.writeConfigurations: return
    if not __debug__:
        print('Cannot dump configuration file if python is run with "-O" or "-OO" option', file=sys.stderr)
        sys.exit(1)
    try:
        context.activate(dumpAssembly())
        try: 
            loadPlugins()
            configFile = configurations_file_path()
        
            if os.path.isfile(configFile):
                with open(configFile, 'r') as f: config = load(f)
            else: config = {}
            
            context.open(aop.modulesIn('__plugin__.**'), config=config, included=True)
            try:
                if os.path.isfile(configFile): os.rename(configFile, configFile + '.bak')
                with open(configFile, 'w') as f: save(context.configurations(force=True), f)
                print('Created "%s" configuration file' % configFile)
            finally: context.deactivate()
        finally: context.deactivate()
    
    except SystemExit: raise
    except:
        print('-' * 150, file=sys.stderr)
        print('A problem occurred while dumping configurations', file=sys.stderr)
        traceback.print_exc(file=sys.stderr)
        print('-' * 150, file=sys.stderr)
Ejemplo n.º 5
0
def dump():
    assert isinstance(application.options, OptionsCore), 'Invalid application options %s' % application.options
    if not application.options.writeConfigurations: return
    if not __debug__:
        print('Cannot dump configuration file if python is run with "-O" or "-OO" option', file=sys.stderr)
        sys.exit(1)
    configFile = application.options.configurationPath
    try:
        if os.path.isfile(configFile):
            with open(configFile, 'r') as f: config = load(f)
        else: config = {}
        
        assembly = application.assembly = ioc.open(aop.modulesIn('__setup__.**'), config=config)
        assert isinstance(assembly, Assembly), 'Invalid assembly %s' % assembly
        try:
            if os.path.isfile(configFile): os.rename(configFile, configFile + '.bak')
            for config in assembly.configurations: assembly.processForName(config)
            # Forcing the processing of all configurations
            with open(configFile, 'w') as f: save(assembly.trimmedConfigurations(), f)
            print('Created "%s" configuration file' % configFile)
        finally: ioc.deactivate()
    except SystemExit: raise
    except:
        print('-' * 150, file=sys.stderr)
        print('A problem occurred while dumping configurations', file=sys.stderr)
        traceback.print_exc(file=sys.stderr)
        print('-' * 150, file=sys.stderr)
Ejemplo n.º 6
0
def __distribution__():
    # In the first stage we prepare the application deployment.
    with context.activate(context.open(aop.modulesIn('__distribution__.**')), 'deploy'):
        support.performEventsFor(APP_PREPARE)
        # In the second stage we parse the application arguments.
        parser.parse_args(namespace=options)
    
        support.performEventsFor(APP_START)
Ejemplo n.º 7
0
def __deploy__():
    # Deploy the application
    try:
        import package_extender
        package_extender.PACKAGE_EXTENDER.addFreezedPackage('__deploy__.')
        from ally.container import ioc, aop
    except ImportError:
        print(
            'Corrupted or missing ally-utilites component, make sure that this component is not missing from python path '
            'or components eggs',
            file=sys.stderr)
        sys.exit(1)

    application = sys.modules['application'] = ModuleType('application')
    try:
        # We create the parser to be prepared.
        application.parser = argparse.ArgumentParser(
            description='The ally distribution application deployer.')
        application.Options = object  # Prepare the option class

        # In the first stage we prepare the application deployment.
        assembly = ioc.open(aop.modulesIn('__deploy__.*.prepare'))
        try:
            assembly.processStart()
        finally:
            ioc.deactivate()

        # In the second stage we parse the application arguments.
        application.options = application.parser.parse_args(
            namespace=application.Options())

        # In the final stage we deploy the application.
        assembly = ioc.open(aop.modulesIn('__deploy__.*.deploy'))
        try:
            assembly.processStart()
        finally:
            ioc.deactivate()

    except SystemExit:
        raise
    except:
        print('-' * 150, file=sys.stderr)
        print('A problem occurred while deploying', file=sys.stderr)
        traceback.print_exc()
        print('-' * 150, file=sys.stderr)
        sys.exit(1)
Ejemplo n.º 8
0
 def getById(self, id):
     '''
     @see: IComponentService.getById
     '''
     assert isinstance(id, str), 'Invalid id %s' % id
     modules = modulesIn('%s.%s' % (self.package, id)).asList()
     if len(modules) != 1: raise InputError(Ref(_('Invalid component id'), ref=Component.Id))
     return self.componentFor(modules[0])
Ejemplo n.º 9
0
 def getById(self, id):
     '''
     @see: IPluginService.getById
     '''
     assert isinstance(id, str), 'Invalid id %s' % id
     modules = modulesIn('%s.%s' % ('__plugin__', id)).asList()
     if len(modules) != 1: raise InputError(Ref(_('Invalid plugin id'), ref=Plugin.Id))
     return self.pluginFor(modules[0])
Ejemplo n.º 10
0
 def getById(self, id):
     '''
     @see: IComponentService.getById
     '''
     assert isinstance(id, str), 'Invalid id %s' % id
     modules = modulesIn('%s.%s' % (self.package, id)).asList()
     if len(modules) != 1:
         raise InputError(Ref(_('Invalid component id'), ref=Component.Id))
     return self.componentFor(modules[0])
Ejemplo n.º 11
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)
Ejemplo n.º 12
0
 def modules(self):
     '''
     Provides the modules in the current distribution.
     '''
     if self._modules is None:
         modules = modulesIn('%s.*' % self.package).asList()
         modules.sort()
         self._modules = OrderedDict(((module[len(self.package) + 1:], module) for module in modules))
     return self._modules
Ejemplo n.º 13
0
 def getById(self, id):
     '''
     @see: IPluginService.getById
     '''
     assert isinstance(id, str), 'Invalid id %s' % id
     modules = modulesIn('%s.%s' % ('__plugin__', id)).asList()
     if len(modules) != 1:
         raise InputError(Ref(_('Invalid plugin id'), ref=Plugin.Id))
     return self.pluginFor(modules[0])
Ejemplo n.º 14
0
 def getById(self, id):
     """
     @see: IComponentService.getById
     """
     assert isinstance(id, str), "Invalid id %s" % id
     modules = modulesIn("%s.%s" % (self.package, id)).asList()
     if len(modules) != 1:
         raise InputError(Ref(_("Invalid component id"), ref=Component.Id))
     return self.componentFor(modules[0])
Ejemplo n.º 15
0
def __deploy__():
    # Deploy the application
    with context.activate(context.open(aop.modulesIn('__setup__.**')),
                          'deploy'):
        support.performEventsFor(APP_PREPARE)
        # In the second stage we parse the application arguments.
        parser.parse_args(namespace=options)

        support.performEventsFor(APP_START)
Ejemplo n.º 16
0
def dumpAssembly():
    assert isinstance(application.options, OptionsCore), 'Invalid application options %s' % application.options
    configFile = application.options.configurationPath

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

    return context.open(aop.modulesIn('__setup__.**'), config=config, active=False)
Ejemplo n.º 17
0
def openSetups():
    ''' Open the assembly for setups '''
    if not os.path.isfile(application.options.configurationPath):
        print('The configuration file "%s" doesn\'t exist, create one by running the the application '
              'with "-dump" option' % application.options.configurationPath, file=sys.stderr)
        sys.exit(1)
    with open(application.options.configurationPath, 'r') as f: config = load(f)

    context.open(aop.modulesIn('__setup__.ally.**'), config=config)
    
    logging.basicConfig(format=format())
    for name in warning_for(): logging.getLogger(name).setLevel(logging.WARN)
    for name in info_for(): logging.getLogger(name).setLevel(logging.INFO)
    for name in debug_for(): logging.getLogger(name).setLevel(logging.DEBUG)
    
    context.deactivate()
    
    context.open(aop.modulesIn('__setup__.**'), config=config)
Ejemplo n.º 18
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)
Ejemplo n.º 19
0
    def getPlugins(self, offset=None, limit=None):
        '''
        @see: IPluginService.getPlugins
        '''
        modules = modulesIn('__plugin__.*').asList()
        modules.sort()

        components = {cmp.Path:cmp.Id for cmp in self.componentService.getComponents()}
        plugins = (self.pluginFor(module, components) for module in modules)

        return IterPart(trimIter(plugins, len(modules), offset, limit), len(modules), offset, limit)
Ejemplo n.º 20
0
    def getComponents(self, offset=None, limit=None, q=None):
        '''
        @see: IComponentService.getComponents
        '''
        modules = modulesIn('%s.*' % self.package).asList()
        modules.sort()
        components = (self.componentFor(module) for module in modules)
        length = len(modules)
        if q:
            assert isinstance(q, QComponent), 'Invalid query %s' % q
            components = processQuery(components, q, Component)
            length = len(components)

        return IterPart(trimIter(components, length, offset, limit), length, offset, limit)
Ejemplo n.º 21
0
def __deploy__():
    # Deploy the application
    try:
        import package_extender
        package_extender.PACKAGE_EXTENDER.addFreezedPackage('__deploy__.')
        from ally.container import aop, context
    except ImportError:
        print('Corrupted or missing ally component, make sure that this component is not missing from python path '
              'or components eggs', file=sys.stderr)
        sys.exit(1)

    application = sys.modules['application'] = ModuleType('application')
    try:
        # We create the parser to be prepared.
        application.parser = argparse.ArgumentParser(description='The ally distribution application deployer.')
        application.Options = object  # Prepare the option class

        # In the first stage we prepare the application deployment.
        context.open(aop.modulesIn('__deploy__.*.prepare'))
        try: context.processStart()
        finally: context.deactivate()

        # In the second stage we parse the application arguments.
        application.options = application.parser.parse_args(namespace=application.Options())

        # In the final stage we deploy the application.
        context.open(aop.modulesIn('__deploy__.*.deploy'))
        try: context.processStart()
        finally: context.deactivate()

    except SystemExit: raise
    except:
        print('-' * 150, file=sys.stderr)
        print('A problem occurred while deploying', file=sys.stderr)
        traceback.print_exc()
        print('-' * 150, file=sys.stderr)
        sys.exit(1)
Ejemplo n.º 22
0
    def getPlugins(self, offset=None, limit=None):
        '''
        @see: IPluginService.getPlugins
        '''
        modules = modulesIn('__plugin__.*').asList()
        modules.sort()

        components = {
            cmp.Path: cmp.Id
            for cmp in self.componentService.getComponents()
        }
        plugins = (self.pluginFor(module, components) for module in modules)

        return IterPart(trimIter(plugins, len(modules), offset, limit),
                        len(modules), offset, limit)
Ejemplo n.º 23
0
    def getComponents(self, offset=None, limit=None, q=None):
        '''
        @see: IComponentService.getComponents
        '''
        modules = modulesIn('%s.*' % self.package).asList()
        modules.sort()
        components = (self.componentFor(module) for module in modules)
        length = len(modules)
        if q:
            assert isinstance(q, QComponent), 'Invalid query %s' % q
            components = processQuery(components, q, Component)
            length = len(components)

        return IterPart(trimIter(components, length, offset, limit), length,
                        offset, limit)
Ejemplo n.º 24
0
def deploy(*tests):
    package_extender.PACKAGE_EXTENDER.addFreezedPackage('__setup__.')
    from ally.container import ioc, aop

    try:
        setups = aop.modulesIn('__setup__.**')
        # We need to remove the server configurations
        setups.exclude('**.server_*')
        try: ioc.open(setups, *tests).processStart()
        finally: ioc.deactivate()
    except:
        print('-' * 150, file=sys.stderr)
        print('A problem occurred while deploying', file=sys.stderr)
        traceback.print_exc()
        print('-' * 150, file=sys.stderr)
Ejemplo n.º 25
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)
def deploy(*tests):
    package_extender.PACKAGE_EXTENDER.addFreezedPackage('__setup__.')
    from ally.container import ioc, aop

    try:
        setups = aop.modulesIn('__setup__.**')
        # We need to remove the server configurations
        setups.exclude('**.server_*')
        try:
            ioc.open(setups, *tests).processStart()
        finally:
            ioc.deactivate()
    except:
        print('-' * 150, file=sys.stderr)
        print('A problem occurred while deploying', file=sys.stderr)
        traceback.print_exc()
        print('-' * 150, file=sys.stderr)
Ejemplo n.º 27
0
def dump():
    assert isinstance(
        application.options,
        OptionsCore), 'Invalid application options %s' % application.options
    if not application.options.writeConfigurations: return
    if not __debug__:
        print(
            'Cannot dump configuration file if python is run with "-O" or "-OO" option',
            file=sys.stderr)
        sys.exit(1)
    try:
        context.activate(dumpAssembly())
        try:
            loadPlugins()
            configFile = configurations_file_path()

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

            context.open(aop.modulesIn('__plugin__.**'),
                         config=config,
                         included=True)
            try:
                if os.path.isfile(configFile):
                    os.rename(configFile, configFile + '.bak')
                with open(configFile, 'w') as f:
                    save(context.configurations(force=True), f)
                print('Created "%s" configuration file' % configFile)
            finally:
                context.deactivate()
        finally:
            context.deactivate()

    except SystemExit:
        raise
    except:
        print('-' * 150, file=sys.stderr)
        print('A problem occurred while dumping configurations',
              file=sys.stderr)
        traceback.print_exc(file=sys.stderr)
        print('-' * 150, file=sys.stderr)
Ejemplo n.º 28
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)
Ejemplo n.º 29
0
def config():
    assert isinstance(application.options, OptionsMongrel2), 'Invalid application options %s' % application.options
    if not application.options.configMongrel2: return
    workspace = application.options.configMongrel2
    folders = [path.join('mongrel2', name) for name in ('logs', 'run', 'tmp')]
    folders.append(path.join('shared', 'upload'))

    for name in folders:
        folder = path.join(workspace, name)
        if not path.isdir(folder): makedirs(folder)
    
    configFile = application.options.configurationPath
    if path.isfile(configFile):
        with open(configFile, 'r') as f: config = load(f)
    else:
        print('The configuration file "%s" doesn\'t exist, create one by running the the application '
              'with "-dump" option, also change the application properties "server_type" configuration to "mongrel2" '
              'and also adjust the "recv_spec", "send_spec" and "server_port" accordingly' % configFile, file=sys.stderr)
        sys.exit(1)
        
    try:
        context.open(aop.modulesIn('__setup__.**'), config=config)
    
        updateConfig = False
        if server_type() != 'mongrel2':
            updateConfig = True
            support.persist(server_type, 'mongrel2')
        
        sendIdent = send_ident()
        if sendIdent is None:
            updateConfig = True
            sendIdent = str(uuid4())
            support.persist(send_ident, sendIdent)
        
        replace = {}
        try:
            replace['${send_spec}'] = send_spec()
            replace['${send_ident}'] = sendIdent
            replace['${recv_spec}'] = recv_spec()
            replace['${recv_ident}'] = recv_ident()
            replace['${server_port}'] = str(server_port())
        
            if updateConfig:
                if path.isfile(configFile): renames(configFile, configFile + '.bak')
                with open(configFile, 'w') as f: save(context.configurations(force=True), f)
                print('Updated the "%s" configuration file' % configFile)
        finally: context.deactivate()
    except SystemExit: raise
    except:
        print('-' * 150, file=sys.stderr)
        print('A problem occurred while configuring Mongrel2', file=sys.stderr)
        traceback.print_exc(file=sys.stderr)
        print('-' * 150, file=sys.stderr)
    else:
        conf = openURI(path.join(pythonPath(), 'resources', 'ally.conf'))
        conf = codecs.getreader('utf8')(conf)
        conf = ReplaceInFile(conf, replace)
        with open(path.join(workspace, 'ally.conf'), 'w') as f: pipe(conf, f)
        with open(path.join(workspace, 'README-Mongrel2.txt'), 'wb') as f:
            pipe(openURI(path.join(pythonPath(), 'resources', 'README-Mongrel2.txt')), f)
        
        print('Configured "%s" mongrel2 workspace' % workspace)
Ejemplo n.º 30
0
def config():
    assert isinstance(application.options, OptionsMongrel2), 'Invalid application options %s' % application.options
    if not application.options.configMongrel2: return
    workspace = application.options.configMongrel2
    folders = [path.join('mongrel2', name) for name in ('logs', 'run', 'tmp')]
    folders.append(path.join('shared', 'upload'))

    for name in folders:
        folder = path.join(workspace, name)
        if not path.isdir(folder): makedirs(folder)
    
    configFile = application.options.configurationPath
    if path.isfile(configFile):
        with open(configFile, 'r') as f: config = load(f)
    else:
        print('The configuration file "%s" doesn\'t exist, create one by running the the application '
              'with "-dump" option, also change the application properties "server_type" configuration to "mongrel2" '
              'and also adjust the "recv_spec", "send_spec" and "server_port" accordingly' % configFile, file=sys.stderr)
        sys.exit(1)
        
    try:
        context.open(aop.modulesIn('__setup__.**'), config=config)
    
        updateConfig = False
        if server_type() != 'mongrel2':
            updateConfig = True
            support.persist(server_type, 'mongrel2')
        
        sendIdent = send_ident()
        if sendIdent is None:
            updateConfig = True
            sendIdent = str(uuid4())
            support.persist(send_ident, sendIdent)
        
        replace = {}
        try:
            replace['${send_spec}'] = send_spec()
            replace['${send_ident}'] = sendIdent
            replace['${recv_spec}'] = recv_spec()
            replace['${recv_ident}'] = recv_ident()
            replace['${server_port}'] = str(server_port())
        
            if updateConfig:
                if path.isfile(configFile): renames(configFile, configFile + '.bak')
                with open(configFile, 'w') as f: save(context.configurations(force=True), f)
                print('Updated the "%s" configuration file' % configFile)
        finally: context.deactivate()
    except SystemExit: raise
    except:
        print('-' * 150, file=sys.stderr)
        print('A problem occurred while configuring Mongrel2', file=sys.stderr)
        traceback.print_exc(file=sys.stderr)
        print('-' * 150, file=sys.stderr)
    else:
        conf = openURI(path.join(pythonPath(), 'resources', 'ally.conf'))
        conf = codecs.getreader('utf8')(conf)
        conf = ReplaceInFile(conf, replace)
        with open(path.join(workspace, 'ally.conf'), 'w') as f: pipe(conf, f)
        with open(path.join(workspace, 'README-Mongrel2.txt'), 'wb') as f:
            pipe(openURI(path.join(pythonPath(), 'resources', 'README-Mongrel2.txt')), f)
        
        print('Configured "%s" mongrel2 workspace' % workspace)