def __init__(self, *args, **kwargs): """Setup the pav_cfg object, and do other initialization required by pavilion.""" # Open the default pav config file (found in # test/data/pav_config_dir/pavilion.yaml), modify it, and then # save the modified file to a temp location and read it instead. with self.PAV_CONFIG_PATH.open() as cfg_file: raw_pav_cfg = config.PavilionConfigLoader().load(cfg_file) raw_pav_cfg.config_dirs = [self.TEST_DATA_ROOT/'pav_config_dir', self.PAV_LIB_DIR] raw_pav_cfg.working_dir = self.PAV_ROOT_DIR/'test'/'working_dir' raw_pav_cfg.user_config = False raw_pav_cfg.result_log = raw_pav_cfg.working_dir/'results.log' if not raw_pav_cfg.working_dir.exists(): raw_pav_cfg.working_dir.mkdir() cfg_dir = raw_pav_cfg.working_dir/'pav_cfgs' if not cfg_dir.exists(): cfg_dir.mkdir() cfg_path = Path(tempfile.mktemp( suffix='.yaml', dir=str(cfg_dir))) with cfg_path.open('w') as pav_cfg_file: config.PavilionConfigLoader().dump(pav_cfg_file, raw_pav_cfg) with cfg_path.open() as cfg_file: self.pav_cfg = config.PavilionConfigLoader().load(cfg_file) self.pav_cfg.pav_cfg_file = cfg_path self.pav_cfg.pav_vars = pavilion_variables.PavVars() if not self.pav_cfg.working_dir.exists(): self.pav_cfg.working_dir.mkdir(parents=True) # Create the basic directories in the working directory for path in self.WORKING_DIRS: path = self.pav_cfg.working_dir/path if not path.exists(): path.mkdir() self.tmp_dir = tempfile.TemporaryDirectory() # We have to get this to set up the base argument parser before # plugins can add to it. _ = arguments.get_parser() super().__init__(*args, **kwargs)
def __init__(self, pav_cfg): self.pav_cfg = pav_cfg self.base_var_man = variables.VariableSetManager() try: self.base_var_man.add_var_set( 'sys', system_variables.get_vars(defer=True)) except system_variables.SystemPluginError as err: raise TestConfigError("Error in system variables: {}".format(err)) self.base_var_man.add_var_set('pav', pavilion_variables.PavVars()) self.logger = logging.getLogger(__file__)
def main(): """Setup Pavilion and run a command.""" # Pavilion is compatible with python >= 3.4 if sys.version_info[0] != 3 or sys.version_info[1] < 4: output.fprint("Pavilion requires python 3.4 or higher.", color=output.RED, file=sys.stderr) sys.exit(-1) # Get the config, and try: pav_cfg = config.find() except Exception as err: output.fprint("Error getting config, exiting: {}".format(err), file=sys.stderr, color=output.RED) sys.exit(-1) # Create the basic directories in the working directory and the .pavilion # directory. for path in [ config.USER_HOME_PAV, config.USER_HOME_PAV / 'working_dir', pav_cfg.working_dir / 'builds', pav_cfg.working_dir / 'series', pav_cfg.working_dir / 'test_runs', pav_cfg.working_dir / 'users' ]: try: path = path.expanduser() path.mkdir(exist_ok=True) except OSError as err: output.fprint( "Could not create base directory '{}': {}".format(path, err), color=output.RED, file=sys.stderr, ) sys.exit(1) # Setup all the loggers for Pavilion if not log_setup.setup_loggers(pav_cfg): sys.exit(1) # This has to be done before we initialize plugins parser = arguments.get_parser() # Initialize all the plugins try: plugins.initialize_plugins(pav_cfg) except plugins.PluginError as err: output.fprint("Error initializing plugins: {}".format(err), color=output.RED, file=sys.stderr) sys.exit(-1) pav_cfg.pav_vars = pavilion_variables.PavVars() # Parse the arguments try: args = parser.parse_args() except Exception: # TODO: Handle argument parsing errors correctly. raise if args.command_name is None: parser.print_help() sys.exit(0) try: cmd = commands.get_command(args.command_name) except KeyError: output.fprint("Unknown command '{}'.".format(args.command_name), color=output.RED, file=sys.stderr) sys.exit(-1) try: sys.exit(cmd.run(pav_cfg, args)) except Exception as err: exc_info = { 'traceback': traceback.format_exc(), 'args': vars(args), 'config': pav_cfg, } json_data = output.json_dumps(exc_info) logger = logging.getLogger('exceptions') logger.error(json_data) output.fprint( "Unknown error running command {}: {}.".format( args.command_name, err), color=output.RED, file=sys.stderr, ) traceback.print_exc(file=sys.stderr) output.fprint( "Traceback logged to {}".format(pav_cfg.exception_log), color=output.RED, file=sys.stderr, ) sys.exit(-1)
def main(): """Setup Pavilion and run a command.""" # Pavilion is compatible with python >= 3.4 if sys.version_info[0] != 3 or sys.version_info[1] < 5: output.fprint("Pavilion requires python 3.5 or higher.", color=output.RED, file=sys.stderr) sys.exit(-1) # This has to be done before we initialize plugins parser = arguments.get_parser() # Get the config, and try: pav_cfg = config.find() except Exception as err: output.fprint("Error getting config, exiting: {}".format(err), file=sys.stderr, color=output.RED) sys.exit(-1) # Create the basic directories in the working directory and the .pavilion # directory. for path in [ config.USER_HOME_PAV, config.USER_HOME_PAV / 'working_dir', pav_cfg.working_dir / 'builds', pav_cfg.working_dir / 'series', pav_cfg.working_dir / 'test_runs', pav_cfg.working_dir / 'users' ]: try: path = path.expanduser() path.mkdir(exist_ok=True) except OSError as err: output.fprint( "Could not create base directory '{}': {}".format(path, err), color=output.RED, file=sys.stderr, ) sys.exit(1) # Setup all the loggers for Pavilion if not log_setup.setup_loggers(pav_cfg): sys.exit(1) # Initialize all the plugins try: plugins.initialize_plugins(pav_cfg) except plugins.PluginError as err: output.fprint("Error initializing plugins: {}".format(err), color=output.RED, file=sys.stderr) sys.exit(-1) # Parse the arguments try: args = parser.parse_args() except Exception: raise if args.command_name is None: parser.print_help() sys.exit(0) pav_cfg.pav_vars = pavilion_variables.PavVars() if not args.profile: run_cmd(pav_cfg, args) else: import cProfile import pstats stats_path = '/tmp/{}_pav_pstats'.format(os.getlogin()) cProfile.runctx('run_cmd(pav_cfg, args)', globals(), locals(), stats_path) stats = pstats.Stats(stats_path) print("Profile Table") stats.strip_dirs().sort_stats(args.profile_sort)\ .print_stats(args.profile_count)