def _prepare_output_dir(args): """ Prepare the output dir for the current job Returns str : Absolut path to the output directory """ outtag = args.dataset + "_" + datetime.now().strftime("%Y%m%d_%H%M") output_dir = os.path.join(os.path.abspath(os.path.curdir), outtag) if args.suffix: if "-" in args.suffix: raise ValueError('Hyphens ("-") are not allowed in the suffix') output_dir += args.suffix try: print("Output will be in", output_dir) os.mkdir(output_dir) except OSError as e: raise ValueError( f"Cannot create output folder {output_dir} (already exist). Maybe wait a few seconds and try again?" ) try: os.symlink(output_dir, "latest") except OSError as e: if os.path.islink("latest"): os.remove("latest") os.symlink(output_dir, "latest") else: raise e utils.copy_template_files_to(output_dir) if utils.project_uses_ConfigureTrain(): shutil.copy( os.path.join(os.path.dirname(output_dir), "ConfigureTrain.C"), output_dir) elif utils.project_uses_train_cfg(): shutil.copy( os.path.join(os.path.dirname(output_dir), "MLTrainDefinition.cfg"), output_dir, ) else: raise RuntimeError( "Neither ConfigureTrain.C nor MLTrainDefinition.cfg found in current folder!" ) if args.par_files: utils.prepare_par_files(args.par_files, output_dir) # create GetSetting.C in output dir (from template) utils.prepare_get_setting_c_file(output_dir, args) return output_dir
def _prepare_output_dir(args): """ Prepare the output dir for the current job Returns str : Absolut path to the output directory """ output_dir = os.path.join(os.path.abspath(os.path.curdir), datetime.now().strftime("%Y%m%d_%H%M")) if args.suffix: if "-" in args.suffix: raise ValueError('Hyphens ("-") are not allowed in the suffix') output_dir += args.suffix try: os.mkdir(output_dir) except OSError as e: raise ValueError("Cannot create output folder {} (already exist). ".format(output_dir) + "Maybe wait a few seconds and try again?") try: os.symlink(output_dir, "latest") except OSError as e: if os.path.islink("latest"): os.remove("latest") os.symlink(output_dir, "latest") else: raise e utils.copy_template_files_to(output_dir) if utils.project_uses_ConfigureTrain(): shutil.copy(os.path.join(os.path.dirname(output_dir), "ConfigureTrain.C"), output_dir) elif utils.project_uses_train_cfg(): shutil.copy(os.path.join(os.path.dirname(output_dir), "MLTrainDefinition.cfg"), output_dir) else: raise RuntimeError("Neither ConfigureTrain.C nor MLTrainDefinition.cfg found in current folder!") if args.par_files: utils.prepare_par_files(args.par_files, output_dir) # create GetSetting.C in output dir (from template) utils.prepare_get_setting_c_file(output_dir, args) return output_dir
def test_create_getSetting_c(self): import tempfile tmp_dir = tempfile.gettempdir() _parser = parser.create_parser() args = _parser.parse_args(['run', 'lite', 'LHC12a11a']) utils.prepare_get_setting_c_file(tmp_dir, args)