def list_courses(forks_only): """List all courses and runs and info about them. Mainly useful for courses from forks. Shows where they are sourced from and if they return even the most basic information and will therefore be included in list of courses/runs. A practical benefit is that on Travis CI, the docker images are pulled/built by this command, so freezing won't timeout after the 10 minute limit if things are taking particularly long. """ from naucse.views import model def canonical(course, suffix=""): click.echo(f" {course.slug}: {course.title}{suffix}") def fork_invalid(course): click.echo(f" {course.slug}, from {course.repo}@{course.branch}: " f"Fork doesn't return basic info, will be ignored.") def fork_valid(course, suffix=""): click.echo( f" {course.slug}, from {course.repo}@{course.branch}: {course.title}{suffix}" ) click.echo(f"Courses:") for course in model.courses.values(): if forks_only and not course.is_link(): continue if not course.is_link(): canonical(course) elif forks_enabled(): if does_course_return_info(course, force_ignore=True): fork_valid(course) else: fork_invalid(course) click.echo(f"Runs:") for course in model.runs.values(): if forks_only and not course.is_link(): continue if not course.is_link(): canonical(course, suffix=f" ({course.start_date} - {course.end_date})") elif forks_enabled(): if does_course_return_info(course, ["start_date", "end_date"], force_ignore=True): fork_valid( course, suffix=f" ({course.start_date} - {course.end_date})") else: fork_invalid(course)
def courses(): # since even the basic info about the forked courses can be broken, # we need to make sure the required info is provided. # If ``RAISE_FORK_ERRORS`` is set, exceptions are raised here, # otherwise the course is ignored completely. safe_courses = [] for course in model.courses.values(): if not course.is_link(): if not course.is_meta: safe_courses.append(course) elif naucse.utils.views.forks_enabled() and does_course_return_info( course): safe_courses.append(course) return render_template("course_list.html", courses=safe_courses, title="Seznam online kurzů Pythonu", edit_info=get_edit_info(model.courses_edit_path))