<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def _prune(dir_: str, epochs: int) -> None: """ Delete all training dirs with incomplete training artifacts or with less than specified epochs done. :param dir_: dir with training log dirs :param epochs: minimum number of finished epochs to keep the training logs :return: number of log dirs pruned """

    for logdir in [path.join(dir_, f) for f in listdir(dir_) if path.isdir(path.join(dir_, f))]:
        if not is_train_dir(logdir):
            _safe_rmtree(logdir)
        else:
            trace_path = path.join(logdir, CXF_TRACE_FILE)
            try:
                epochs_done = TrainingTrace.from_file(trace_path)[TrainingTraceKeys.EPOCHS_DONE]
            except (KeyError, TypeError):
                epochs_done = 0
            if not epochs_done or epochs_done < epochs:
                _safe_rmtree(logdir)