Пример #1
0
def _remove_all_result_files(ctx: click.Context, error: bool) -> None:
    """Remove all report files of the current paper_config."""
    result_folders = _find_result_dir_paths_of_projects(
        ctx.obj["case_studies"])
    for folder in result_folders:
        for res_file in folder.iterdir():
            report_file = ReportFilename(res_file.name)
            if not report_file.is_result_file():
                continue
            if ctx.obj["experiment"] and not ctx.obj[
                    "experiment"].file_belongs_to_experiment(res_file.name):
                continue
            if ctx.obj["report"] and not ctx.obj[
                    "report"].is_correct_report_type(res_file.name):
                continue

            commit_hash = report_file.commit_hash
            if any(
                    list(
                        case_study.has_revision(commit_hash)
                        for case_study in ctx.obj["case_studies"])):
                if error and not (report_file.has_status_compileerror()
                                  or report_file.has_status_failed()):
                    continue
                res_file.unlink()
Пример #2
0
def __get_result_files_dict(
    project_name: str, result_file_type: tp.Type[BaseReport]
) -> tp.Dict[ShortCommitHash, tp.List[Path]]:
    """
    Returns a dict that maps the commit_hash to a list of all result files, of
    type result_file_type, for that commit.

    Args:
        project_name: target project
        result_file_type: the type of the result file
    """
    res_dir = Path(f"{vara_cfg()['result_dir']}/{project_name}/")

    result_files: tp.DefaultDict[ShortCommitHash, tp.List[Path]] = defaultdict(
        list
    )  # maps commit hash -> list of res files (success or fail)
    if not res_dir.exists():
        return result_files

    for res_file in res_dir.iterdir():
        report_file = ReportFilename(res_file)
        if report_file.is_result_file(
        ) and result_file_type.is_correct_report_type(res_file.name):
            commit_hash = report_file.commit_hash
            result_files[commit_hash].append(res_file)

    return result_files
Пример #3
0
def _remove_old_result_files(ctx: click.Context) -> None:
    """Remove result files of wich a newer version exists."""
    result_dir = Path(str(vara_cfg()['result_dir']))
    for case_study in ctx.obj['case_studies']:
        old_files: tp.List[Path] = []
        newer_files: tp.Dict[ShortCommitHash, Path] = {}
        result_dir_cs = result_dir / case_study.project_name
        if not result_dir_cs.exists():
            continue
        for opt_res_file in result_dir_cs.iterdir():
            report_file = ReportFilename(opt_res_file.name)
            if not report_file.is_result_file():
                continue
            if ctx.obj["experiment"] and not ctx.obj[
                    "experiment"].file_belongs_to_experiment(
                        opt_res_file.name):
                continue
            if ctx.obj["report"] and not ctx.obj[
                    "report"].is_correct_report_type(opt_res_file.name):
                continue

            commit_hash = report_file.commit_hash
            if case_study.has_revision(commit_hash):
                current_file = newer_files.get(commit_hash)
                if current_file is None:
                    newer_files[commit_hash] = opt_res_file
                else:
                    if (current_file.stat().st_mtime_ns <
                            opt_res_file.stat().st_mtime_ns):
                        newer_files[commit_hash] = opt_res_file
                        old_files.append(current_file)
                    else:
                        old_files.append(opt_res_file)
        for file in old_files:
            if file.exists():
                file.unlink()