示例#1
0
    def execute(self, config, shell):
        shell.clear_script()

        shell.define_cepcenv()
        shell.newline()

        try:
            info = Info()
            default_version = info.default_version
            if default_version:
                config_version = ConfigVersion(config, default_version)
                config_release = ConfigRelease(config_version)

                obj = CepcenvUse(config, config_version, config_release)
                set_env, unset_env = obj.run()
            else:
                env = Env()
                env.clean()
                set_env, unset_env = env.env_change()

            for e in unset_env:
                shell.unset_env(e)
            for k, v in set_env.items():
                shell.set_env(k, v)
        except Exception as e:
            _logger.warn('Cat not load default version: {0}'.format(e))

        click.echo(shell.script, nl=False)
示例#2
0
文件: executor.py 项目: cepc/cepcenv
    def __init__(self, config, config_version, config_release):
        self.__config = config
        self.__config_version = config_version
        self.__config_release = config_release

        self.__env = Env()
        self.__env.clean()

        self.__pkg_mgr = PackageManager(config_version, config_release)
示例#3
0
    def execute(self, config, config_version, shell):
        env = Env()
        env.clean()
        setenv, unset = env.final_all_env()

        script = ''
        for e in unset:
            script += shell.unset_env(e)
        for k, v in setenv.items():
            script += shell.set_env(k, v)

        click.echo(script, nl=False)
示例#4
0
文件: clean.py 项目: cepc/cepcenv
    def execute(self, config, config_version, shell):
        env = Env()
        env.clean()
        set_env, unset_env = env.env_change()

        shell.clear_script()
        for e in unset_env:
            shell.unset_env(e)
        for k, v in set_env.items():
            shell.set_env(k, v)

        click.echo(shell.script, nl=False)
示例#5
0
    def execute(self, config, shell):
        shell.clear_script()

        env = Env()
        env.clean()
        set_env, unset = env.env_change()

        for e in unset:
            shell.unset_env(e)
        for k, v in set_env.items():
            shell.set_env(k, v)

        shell.undefine_cepcenv()

        click.echo(shell.script, nl=False)
示例#6
0
    def execute(self, config, config_version, shell):
        local_versions = []

        try:
            version_dirs = os.listdir(config_version.cepcenv_dir)
            version_dirs.sort()
            for version_dir in version_dirs:
                try:
                    with open(os.path.join(config_version.cepcenv_dir, version_dir, 'def', 'config', 'version.yml')) as f:
                        version_in_def = f.read().strip()

                    local_versions.append(version_dir)

                    if version_in_def != version_dir:
                        _logger.warn('Version inconsistent for "{0}": Defined as "{1}"'.format(version_dir, version_in_def))
                except:
                    continue
        except:
            pass


        env = Env()
        current_root = env.release_root
        current_version = env.release_version

        info = Info()
        default_version_name = info.default_version
        _logger.debug('Default version name: {0}'.format(default_version_name))

        default_root = None
        default_version = None
        if default_version_name:
            config_version_default = ConfigVersion(config, default_version_name)
            default_root = config_version_default.get('release_root')
            default_version = config_version_default.get('version')

        _logger.debug('Current release: {0} {1}'.format(current_root, current_version))
        _logger.debug('Default release: {0} {1}'.format(default_root, default_version))


        script = ''

        release_root = config_version.get('release_root')
        script += shell.echo('(Release root: "{0}")'.format(release_root))

        for version in local_versions:
            ver_status = []
            if release_root == current_root and version == current_version:
                ver_status.append('current')
            if release_root == default_root and version == default_version:
                ver_status.append('default')

            version_line = version
            if ver_status:
                version_line += '  ({0})'.format(', '.join(ver_status))

            script += shell.echo(version_line)

        click.echo(script, nl=False)
示例#7
0
    def execute(self, config, config_version, shell):
        script = ''

        env = Env()

        for name, info in env.package_info.items():
            script += shell.echo(
                '{name} @ {version} : {category} - {path}'.format(name=name,
                                                                  **info))

        click.echo(script, nl=False)
示例#8
0
    def run(self):
        sorted_pkgs = dag_run(self.__dag)

        env = Env()
        env.clean()
        env.set_release(self.__config_version.config['release_root'], self.__config_version.config['version'])

        for pkg in sorted_pkgs:
            if pkg not in self.__config_release.config['attribute']:
                continue

            path_mode = self.__config_release.config['main'].get('path_mode', {})
            pkg_config = {
                'name': pkg,
                'package': self.__config_release.config['package'].get(pkg, {}),
                'attribute': self.__config_release.config['attribute'].get(pkg, {}),
                'format': self.__exe_config[pkg],
            }
            env.set_package(path_mode, pkg_config)

        return env.final_all_env()
示例#9
0
    def run(self):
        sorted_pkgs = dag_run(self.__dag)

        software_root = self.__config_version.config['software_root']
        release_version = self.__config_version.config['version']

        env = Env()
        env.clean()
        env.set_release(software_root, release_version)

        global_env = self.__config_release.get('setting',
                                               {}).get('global_env', {})
        new_global_env = {}
        for k, v in global_env.items():
            new_global_env[k] = v.format(**self.__config_version.config)
        env.set_global(new_global_env)

        path_usage = self.__config_release.get('setting',
                                               {}).get('path_usage', {})
        for pkg in sorted_pkgs:
            pkg_info = self.__pkg_mgr.package_info(pkg)
            env.set_package(path_usage, pkg_info)

        env_change = env.env_change()

        _logger.info('From software root: {0}'.format(software_root))
        _logger.info('Using version: {0}'.format(release_version))
        _logger.info('Current platform: {0}'.format(
            self.__config_version.config['platform']))

        return env_change
示例#10
0
文件: executor.py 项目: cepc/cepcenv
class Executor(object):
    def __init__(self, config, config_version, config_release):
        self.__config = config
        self.__config_version = config_version
        self.__config_release = config_release

        self.__env = Env()
        self.__env.clean()

        self.__pkg_mgr = PackageManager(config_version, config_release)

    def param(self, vertex):
        pkg, action = vertex

        par = {}

        par['package'] = pkg
        par['action'] = action
        handler = self.__pkg_mgr.package_info(pkg)['install'].get(
            action, {}).get('handler')
        if handler:
            par['action_handler'] = handler
            par['action_param'] = self.__pkg_mgr.package_info(
                pkg)['install'][action].get('param', {})

        par['config'] = self.__config

        par['def_dir'] = self.__config_version.def_dir

        par['pkg_info'] = self.__pkg_mgr.package_info(pkg)

        par['pkg_dir_list'] = self.__pkg_mgr.package_dir_list()

        par['log_file'] = os.path.join(
            self.__pkg_mgr.package_info(pkg)['dir']['log'],
            '{0}_{1}.log'.format(action, pkg))

        par['env'] = self.__env.env_final()

        par['finished'] = self.__pkg_mgr.is_ready(pkg, action)

        return par

    # Do NOT access or modify any variables outside this function (global and member variables)
    def execute(self, param):
        pkg = param['package']
        action = param['action']

        if 'action_handler' not in param:
            _logger.debug('No handler: {0} - {1}'.format(pkg, action))
            return None

        if param['finished']:
            _logger.debug('Skip doing: {0} - {1}'.format(pkg, action))
            return None

        result = {}

        result['start'] = datetime.datetime.utcnow()

        safe_mkdir(param['pkg_info']['dir']['log'])

        module_name = HANDLER_MODULE_NAME + '.install.' + param[
            'action_handler']
        f = load_func(module_name, 'run')
        result_action = f(param)

        if result_action is not None and not result_action:
            _logger.critical(
                '"{0} - {1}" execution error. Find log in "{2}"'.format(
                    pkg, action, param['log_file']))
            raise InstallExecutorError('"{0} - {1}" execution error'.format(
                pkg, action))

        result['log_file'] = param['log_file']
        result['end'] = datetime.datetime.utcnow()

        return result

    def report_start(self, vertice):
        pass

    def report_finish(self, vertice_result):
        for vertex, result in vertice_result:
            pkg, action = vertex

            # TODO: post_compile may be absent, find out a secure way
            if action == 'post_compile':
                path_usage = self.__config_release.config['setting'].get(
                    'path_usage', {})
                pkg_info = self.__pkg_mgr.package_info(pkg)
                self.__env.set_package(path_usage, pkg_info)

            if result:
                _logger.info(' > {0} {1} finished'.format(pkg, action))
                safe_mkdir(self.__pkg_mgr.package_info(pkg)['dir']['status'])
                self.__pkg_mgr.save_action_status(pkg, action, result['start'],
                                                  result['end'])

    def report_running(self, vertice):
        if not vertice:
            return
        running_vertice = ', '.join(['{0}({1})'.format(*v) for v in vertice])
        _logger.info('Running: ' + running_vertice)

    def deliver(self, vertex, result):
        pass

    def abort(self, vertice):
        pass
示例#11
0
    def execute(self, config, config_version):
        env = Env()

        for name, info in env.package_info.items():
            click.echo('{name} @ {version} : {category} - {path}'.format(
                name=name, **info))