コード例 #1
0
ファイル: deploy.py プロジェクト: gizm0bill/Ally-Py
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)
コード例 #2
0
ファイル: deploy.py プロジェクト: adityaathalye/Ally-Py
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)
コード例 #3
0
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)
コード例 #4
0
ファイル: deploy_plugin.py プロジェクト: ahilles107/Superdesk
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)
コード例 #5
0
 def deploy(self, assembly=None):
     '''
     @see: IDistributionManager.deploy
     '''
     if assembly is None: assembly = Assembly.current()
     assert isinstance(assembly, Assembly), 'Invalid assembly %s' % assembly
     distribution = assembly.calls.get(DISTRIBUTION)
     if distribution is None or distribution.assembly != assembly:
         log.info('There is no distribution in the assembly \'%s\' for deployment', assembly)
         return
     assert isinstance(distribution, Distribution), 'Invalid distribution %s' % distribution
     
     self._processDepoy(assembly, distribution)
     if self.application_type == SLAVE: return
     
     if isfile(self.distribution_file_path):
         with open(self.distribution_file_path, 'r') as f:
             data = {self._prefix + key:value for key, value in load(f).items()}
     else: data = {}
     
     if self.application_type == MAIN:
         # TODO: detect distribution changes and clear the data of those
         pass
     self._processOnce(ANALYZER, assembly, distribution, data)
     
     self._processOnce(POPULATOR, assembly, distribution, data)
     
     configs = {}
     for event in (POPULATOR, ANALYZER):
         events = distribution.events.get(event)
         if events:
             group = self.group_names[event]
             for name in events:
                 configs[name[self._prefixLen:]] = Config(name, data.pop(name, False), group)
                 
     group = self.group_names[None]
     for name, value in data.items(): configs[name[self._prefixLen:]] = Config(name, value, group)
     
     with open(self.distribution_file_path, 'w') as f: save(configs, f)
コード例 #6
0
ファイル: deploy.py プロジェクト: gizm0bill/Ally-Py
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)
    assembly, configFile = dumpAssembly(), application.options.configurationPath
    try:
        context.activate(assembly)
        try:
            if os.path.isfile(configFile): os.rename(configFile, configFile + '.bak')
            for config in assembly.configurations:
                try: assembly.processForName(config)
                except ConfigError as e: print('Failed to fetch a value for configuration \'%s\': %s' % (config, e))
            # Forcing the processing of all configurations
            with open(configFile, 'w') as f: save(assembly.trimmedConfigurations(), f)
            print('Created "%s" configuration file' % configFile)
        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)
コード例 #7
0
ファイル: deploy.py プロジェクト: gizm0bill/Ally-Py
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)