def read_report_file_yaml(report_file, date_obj, utag): """ Extract information from a run_log.yaml file, and returns a dictionary """ try: with open(report_file, 'r') as rf: try: data = yaml.load(rf) except yaml.YAMLError as exc: APP_LOGGER.error("YMALError %s received" % exc) return None if not data: APP_LOGGER.debug("YAML file, %s, is empty." % report_file) return None data[DATETIME] = date_obj data[FILE_TYPE] = 'yaml' data[UTAG] = utag if USER in data and isinstance(data[USER], str): data[USER] = [user.strip() for user in data[USER].split(',')] # distinguish reports from Web UI and Client UI if CARTRIDGE_BC not in data: report_obj = RunReportWebUI.from_dict(**data) else: report_obj = RunReportClientUI.from_dict(**data) return report_obj.as_dict() except: APP_LOGGER.error("Error raised for report %s: %s" % (report_file, traceback.format_exc())) return None
def process_request(cls, params_dict): uuid = None if cls.uuid_parameter in params_dict and \ params_dict[cls.uuid_parameter][0]: uuid = params_dict[cls.uuid_parameter][0] # if uuid exists, return a single report with all fields if uuid is not None: report = cls._DB_CONNECTOR.find_one(RUN_REPORT_COLLECTION, UUID, uuid) if report is None: APP_LOGGER.debug("Run report uuid=%s does not exist." % uuid) return ([], [], None) del report[ID] return ([report], report.keys(), None) if cls.refresh_parameter in params_dict and \ params_dict[cls.refresh_parameter][0]: if cls.start_date in params_dict and params_dict[ cls.start_date][0]: start_date = params_dict[cls.start_date][0] if cls.end_date in params_dict and params_dict[ cls.end_date][0]: end_date = params_dict[cls.end_date][0] else: end_date = datetime.now() # Old file location 05_10_17 date_folders = [ d.strftime("%m_%d_%y") for d in daterange(start_date, end_date) ] # New file location 2017_05/10 date_folders.extend( d.strftime("%Y_%m/%d") for d in daterange(start_date, end_date)) else: date_folders = None update_run_reports(date_folders) if cls.cart_sn_parameter in params_dict and \ params_dict[cls.cart_sn_parameter][0]: return get_run_reports(params_dict[cls.cart_sn_parameter][0]) else: return get_run_reports()
def get_variants(exp_def_name): """ Return a list of variants in the experiment definition file. """ APP_LOGGER.info("Retrieving list of variants from %s" % (exp_def_name, )) exp_def_doc = _DB_CONNECTOR.find_one(EXP_DEF_COLLECTION, NAME, exp_def_name) if exp_def_doc is not None: APP_LOGGER.info( "Experiment definition %s found in EXP_DEF_COLLECTION." % (exp_def_name, )) return exp_def_doc[VARIANTS] APP_LOGGER.debug( "Failed to find experiment definition %s from EXP_DEF_COLLECTION." % (exp_def_name, )) return []
def read_report_file(report_file, date_obj, utag): """ Extract information from a run log file in txt or yaml format The path of a sample run_info file is: /mnt/runs/run_reprots/04_05_16/Tue05_1424_beta17/run_info.txt date_obj is based on 04_05_16 utag is 2016_04_05_Tue05_1424_beta17 """ if not report_file: APP_LOGGER.debug("File pathname, %s, is an empty string." % report_file) return None basename = os.path.basename(report_file).lower() if basename.endswith('txt'): return read_report_file_txt(report_file, date_obj, utag) elif basename.endswith('yaml'): return read_report_file_yaml(report_file, date_obj, utag) else: APP_LOGGER.debug("File extension must be txt or yaml.") return None