def run(self): install_definition(self.__config_version) install_handler(self.__config_version) self.__config_release = ConfigRelease(self.__config_version) self.__build_dag() sys.path.insert(0, self.__config_version.handler_dir) self.__dag_run()
def __init__(self, config, config_version, config_release=None, transformers=[]): self.__config = config self.__config_version = config_version self.__config_release = config_release if self.__config_release is None: install_definition(self.__config_version) install_handler(self.__config_version) # Must initialize ConfigRelease after install_definition self.__config_release = ConfigRelease(self.__config_version) for transformer in transformers: self.__config_release.transform(transformer) self.__pkg_mgr = PackageManager(self.__config_version, self.__config_release)
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)
def __execute_main(self, version_config_cmd, cmd_kwargs): if self.__cmd_config_version or self.__cmd_config_release: self.__config_version = ConfigVersion(self.__config, cmd_kwargs.get('version_name'), version_config_cmd) if self.__cmd_config_release: self.__config_release = ConfigRelease(self.__config_version) extra_config = self.__config_release.get('setting', {}).get('category', {}).get('extra_config', []) if extra_config: self.__config_version = ConfigVersion(self.__config, cmd_kwargs.get('version_name'), version_config_cmd, extra_config) if 'version_name' in cmd_kwargs: del cmd_kwargs['version_name'] self.__load_shell(version_config_cmd['shell_name']) if self.__cmd_output_shell: cmd_kwargs['shell'] = self.__shell if self.__cmd_config_version: cmd_kwargs['config_version'] = self.__config_version if self.__cmd_config_release: cmd_kwargs['config_release'] = self.__config_release self.__cmd.execute(config=self.__config, **cmd_kwargs)
def execute(self, config, config_version, destination): release_version = config_version.get('version') try: config_release = ConfigRelease(config_version) except ConfigReleaseError: _logger.debug('Install release definition: {0}'.format(release_version)) install = Install(config, config_version) config_release = install.config_release() self.__pkg_mgr = PackageManager(config_version, config_release) if not destination: destination = os.getcwd() destination = expand_path(destination) pack_dir = os.path.join(destination, 'pack_'+release_version) for pkg, pkg_info in self.__pkg_mgr.package_all().items(): version = pkg_info.get('package', {}).get('version') if not version: continue download = pkg_info.get('install', {}).get('download') if not download: continue url = download.get('param', {}).get('url') if not url: continue url = url.format(version=version) pkg_dir = os.path.join(pack_dir, pkg, version) safe_mkdir(pkg_dir) _logger.info('Packing {0}...'.format(pkg)) if download.get('handler') == 'http': pkg_file = _download_http(url, pkg_dir) elif download.get('handler') == 'svn': pkg_file = _download_svn(url, pkg_dir, pkg, version) with open(os.path.join(pkg_dir, 'md5sum.txt'), 'w') as f: call(['md5sum', pkg_file], cwd=pkg_dir, stdout=f) with open(os.path.join(pkg_dir, 'sha1sum.txt'), 'w') as f: call(['sha1sum', pkg_file], cwd=pkg_dir, stdout=f) with open(os.path.join(pkg_dir, 'url.txt'), 'w') as f: f.write(url+'\n') _logger.info('Package {0} packed'.format(pkg)) _logger.info('All packages in version {0} packed in {1}'.format(release_version, pack_dir))
def execute(self, config, shell): script = '' script += shell.define_cepcenv() script += '\n' 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) setenv, unset = obj.run() 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)
class Install(object): def __init__(self, config, config_version, config_release=None, transformers=[]): self.__config = config self.__config_version = config_version self.__config_release = config_release if self.__config_release is None: install_definition(self.__config_version) install_handler(self.__config_version) # Must initialize ConfigRelease after install_definition self.__config_release = ConfigRelease(self.__config_version) for transformer in transformers: self.__config_release.transform(transformer) self.__pkg_mgr = PackageManager(self.__config_version, self.__config_release) def config_release(self): return self.__config_release def check(self): check = Check(self.__config_release, 'install') missing_pkg, pkg_install_name = check.check() return missing_pkg, check.install_cmd, pkg_install_name def package_list(self): pkg_list = [] for pkg, pkg_info in self.__pkg_mgr.package_all().items(): if not pkg_info.get('category', {}).get('install'): continue pkg_version = pkg_info['package'].get('version', 'unknown') pkg_list.append((pkg, pkg_version, pkg_info['dir']['root'])) return pkg_list def install_packages(self): self.__build_dag() sys.path.insert(0, self.__config_version.handler_dir) self.__dag_run() sys.path.remove(self.__config_version.handler_dir) def __build_dag(self): self.__dag = Dag() for pkg, pkg_info in self.__pkg_mgr.package_all().items(): if not pkg_info.get('category', {}).get('install'): continue self.__dag.add_vertex((pkg, 'download')) self.__dag.add_vertex((pkg, 'extract')) self.__dag.add_vertex((pkg, 'pre_compile')) self.__dag.add_vertex((pkg, 'compile')) self.__dag.add_vertex((pkg, 'post_compile')) self.__dag.add_vertex((pkg, 'clean')) self.__dag.add_edge((pkg, 'download'), (pkg, 'extract')) self.__dag.add_edge((pkg, 'extract'), (pkg, 'pre_compile')) self.__dag.add_edge((pkg, 'pre_compile'), (pkg, 'compile')) self.__dag.add_edge((pkg, 'compile'), (pkg, 'post_compile')) self.__dag.add_edge((pkg, 'post_compile'), (pkg, 'clean')) for pkg, pkg_info in self.__pkg_mgr.package_all().items(): if not pkg_info.get('category', {}).get('install'): continue pkgs_dep = ensure_list(pkg_info.get('attribute', {}).get('dep', [])) for pkg_dep in pkgs_dep: if not self.__pkg_mgr.package_info(pkg_dep).get('category', {}).get('install'): continue self.__dag.add_edge((pkg_dep, 'post_compile'), (pkg, 'pre_compile')) def __dag_run(self): selector = InstallSelector(self.__config, self.__config_release) processor = MultiThreadProcessor() # processor = SequentialProcessor() executor = InstallExecutor(self.__config, self.__config_version, self.__config_release) dag_run(self.__dag, selector=selector, processor=processor, executor=executor)
class Install(object): def __init__(self, config, config_version): self.__config = config self.__config_version = config_version def run(self): install_definition(self.__config_version) install_handler(self.__config_version) self.__config_release = ConfigRelease(self.__config_version) self.__build_dag() sys.path.insert(0, self.__config_version.handler_dir) self.__dag_run() def __build_dag(self): self.__dag = Dag() package_config = self.__config_release.get('package', {}) attribute_config = self.__config_release.get('attribute', {}) for pkg, cfg in package_config.items(): self.__dag.add_vertex((pkg, 'download')) self.__dag.add_vertex((pkg, 'extract')) self.__dag.add_vertex((pkg, 'pre_check')) self.__dag.add_vertex((pkg, 'compile')) self.__dag.add_vertex((pkg, 'post_check')) self.__dag.add_edge((pkg, 'download'), (pkg, 'extract')) self.__dag.add_edge((pkg, 'extract'), (pkg, 'pre_check')) self.__dag.add_edge((pkg, 'pre_check'), (pkg, 'compile')) self.__dag.add_edge((pkg, 'compile'), (pkg, 'post_check')) basic_pkgs = [] for pkg, cfg in attribute_config.items(): if pkg in package_config: if 'basic' in cfg and cfg['basic']: basic_pkgs.append(pkg) for pkg, cfg in package_config.items(): # category = cfg['category'] # should_install = False # if category in self.__config_release.config['main']['category']['categories']: # should_install = self.__config_release.config['main']['category']['categories'][category].get('install', False) if pkg not in basic_pkgs: # if not should_install: # continue for bp in basic_pkgs: self.__dag.add_edge((bp, 'post_check'), (pkg, 'download')) if pkg in attribute_config and 'dep' in attribute_config[pkg]: # if not should_install: # continue pkgs_dep = ensure_list(attribute_config[pkg]['dep']) for pkg_dep in pkgs_dep: self.__dag.add_edge((pkg_dep, 'post_check'), (pkg, 'pre_check')) def __dag_run(self): selector = InstallSelector(self.__config, self.__config_release) processor = MultiThreadProcessor() # processor = SequentialProcessor() executor = InstallExecutor(self.__config, self.__config_release) dag_run(self.__dag, selector=selector, processor=processor, executor=executor)
class Cmd(object): def __init__(self, cmd_name): self.__config = {} self.__config_version = {} self.__config_release = {} self.__shell = None self.__load_cmd(cmd_name) def execute(self, options_common, **kwargs): if 'check_shell' in options_common and options_common['check_shell']: if self.__cmd_output_shell: click.echo('CEPCENV:OUTPUT_IS_SHELL') else: click.echo('CEPCENV:OUTPUT_IS_NOT_SHELL') return self.__load_config(options_common) add_stream_logger(self.__config['verbose']) version_config_cmd = options_common.copy() cmd_kwargs = kwargs.copy() try: self.__execute_main(version_config_cmd, cmd_kwargs) except ConfigReleaseError as e: _logger.error(str(e)) _logger.critical('Can not load release version: {0}'.format(cmd_kwargs.get('version_name'))) sys.exit(2) except Exception as e: _logger.critical('Fatal error ({0}): {1}'.format(type(e).__name__, e)) if self.__config['verbose']: _logger.critical('\n{0}'.format(traceback.format_exc())) sys.exit(1) def __execute_main(self, version_config_cmd, cmd_kwargs): if self.__cmd_config_version or self.__cmd_config_release: self.__config_version = ConfigVersion(self.__config, cmd_kwargs.get('version_name'), version_config_cmd) if self.__cmd_config_release: self.__config_release = ConfigRelease(self.__config_version) extra_config = self.__config_release.get('setting', {}).get('category', {}).get('extra_config', []) if extra_config: self.__config_version = ConfigVersion(self.__config, cmd_kwargs.get('version_name'), version_config_cmd, extra_config) if 'version_name' in cmd_kwargs: del cmd_kwargs['version_name'] self.__load_shell(version_config_cmd['shell_name']) if self.__cmd_output_shell: cmd_kwargs['shell'] = self.__shell if self.__cmd_config_version: cmd_kwargs['config_version'] = self.__config_version if self.__cmd_config_release: cmd_kwargs['config_release'] = self.__config_release self.__cmd.execute(config=self.__config, **cmd_kwargs) def __load_cmd(self, cmd_name): self.__cmd = None try: self.__cmd = load_common(cmd_name, 'cepcenv.cmd')() except Exception as e: raise CmdError('Can not load command "{0}": {1}'.format(cmd_name, e)) self.__cmd_output_shell = 'shell' in inspect.getargspec(self.__cmd.execute)[0] self.__cmd_config_version = 'config_version' in inspect.getargspec(self.__cmd.execute)[0] self.__cmd_config_release = 'config_release' in inspect.getargspec(self.__cmd.execute)[0] def __load_config(self, options_common): self.__config = load_main(options_common) def __load_shell(self, shell_name): self.__shell = None if self.__cmd_output_shell: try: self.__shell = Shell(shell_name) except Exception as e: raise CmdError('Can not load shell: {0}'.format(e))
def _clean_only(config, config_version): transformer = ['clean_only'] config_release = ConfigRelease(config_version) install = CepcenvInstall(config, config_version, config_release, transformer) install.install_packages()