Retrieve the baseline directory with cromwell output files.

    Handles Cromwell restarts where there are multiple work directories and
    we traverse symlinks back to the original.

def _get_cromwell_execution_dir(base_dir, target_glob):
    """Retrieve the baseline directory with cromwell output files.

    Handles Cromwell restarts where there are multiple work directories and
    we traverse symlinks back to the original.
    """
    cur_dir = glob.glob(os.path.join(base_dir, target_glob))[0]
    if os.path.exists(os.path.join(cur_dir, "cwl.output.json")):
        return base_dir
    else:
        symlink_dir = os.path.dirname(os.path.realpath(os.path.join(cur_dir, "script")))
        ref_base = os.path.dirname(base_dir)
        new_guid = symlink_dir[symlink_dir.find(ref_base) + len(ref_base) + 1:].split("/")[0]
        return _get_cromwell_execution_dir(os.path.join(ref_base, new_guid), target_glob)