Пример #1
0
def update(course=False):
    """
    Update the data of courses and or exercises from server.
    """
    if course:
        with Spinner.context(msg="Updated course metadata.",
                             waitmsg="Updating course metadata."):
            for course in api.get_courses():
                old = None
                try:
                    old = Course.get(Course.tid == course["id"])
                except peewee.DoesNotExist:
                    old = None
                if old:
                    old.details_url = course["details_url"]
                    old.save()
                    continue
                Course.create(tid=course["id"],
                              name=course["name"],
                              details_url=course["details_url"])
    else:
        selected = Course.get_selected()

        # with Spinner.context(msg="Updated exercise metadata.",
        #                     waitmsg="Updating exercise metadata."):
        print("Updating exercise data.")
        for exercise in api.get_exercises(selected):
            old = None
            try:
                old = Exercise.byid(exercise["id"])
            except peewee.DoesNotExist:
                old = None
            if old is not None:
                old.name = exercise["name"]
                old.course = selected.id
                old.is_attempted = exercise["attempted"]
                old.is_completed = exercise["completed"]
                old.deadline = exercise.get("deadline")
                old.is_downloaded = os.path.isdir(old.path())
                old.return_url = exercise["return_url"]
                old.zip_url = exercise["zip_url"]
                old.submissions_url = exercise["exercise_submissions_url"]
                old.save()
                download_exercise(old, update=True)
            else:
                ex = Exercise.create(tid=exercise["id"],
                                     name=exercise["name"],
                                     course=selected.id,
                                     is_attempted=exercise["attempted"],
                                     is_completed=exercise["completed"],
                                     deadline=exercise.get("deadline"),
                                     return_url=exercise["return_url"],
                                     zip_url=exercise["zip_url"],
                                     submissions_url=exercise[("exercise_"
                                                               "submissions_"
                                                               "url")])
                ex.is_downloaded = os.path.isdir(ex.path())
                ex.save()
Пример #2
0
def update(course=False):
    """
    Update the data of courses and or exercises from server.
    """
    if course:
        with Spinner.context(msg="Updated course metadata.",
                             waitmsg="Updating course metadata."):
            for course in api.get_courses():
                old = None
                try:
                    old = Course.get(Course.tid == course["id"])
                except peewee.DoesNotExist:
                    old = None
                if old:
                    old.details_url = course["details_url"]
                    old.save()
                    continue
                Course.create(tid=course["id"], name=course["name"],
                              details_url=course["details_url"])
    else:
        selected = Course.get_selected()

        # with Spinner.context(msg="Updated exercise metadata.",
        #                     waitmsg="Updating exercise metadata."):
        print("Updating exercise data.")
        for exercise in api.get_exercises(selected):
            old = None
            try:
                old = Exercise.byid(exercise["id"])
            except peewee.DoesNotExist:
                old = None
            if old is not None:
                old.name = exercise["name"]
                old.course = selected.id
                old.is_attempted = exercise["attempted"]
                old.is_completed = exercise["completed"]
                old.deadline = exercise.get("deadline")
                old.is_downloaded = os.path.isdir(old.path())
                old.return_url = exercise["return_url"]
                old.zip_url = exercise["zip_url"]
                old.submissions_url = exercise["exercise_submissions_url"]
                old.save()
                download_exercise(old, update=True)
            else:
                ex = Exercise.create(tid=exercise["id"],
                                     name=exercise["name"],
                                     course=selected.id,
                                     is_attempted=exercise["attempted"],
                                     is_completed=exercise["completed"],
                                     deadline=exercise.get("deadline"),
                                     return_url=exercise["return_url"],
                                     zip_url=exercise["zip_url"],
                                     submissions_url=exercise[("exercise_"
                                                               "submissions_"
                                                               "url")])
                ex.is_downloaded = os.path.isdir(ex.path())
                ex.save()
Пример #3
0
def test(course, tid=None, time=None):
    """
    Run tests on the selected exercise.
    """
    if time is not None:
        conf.tests_show_time = time
    if tid is not None:
        return run_test(Exercise.byid(tid))
    else:
        sel = Exercise.get_selected()
        if not sel:
            raise NoExerciseSelected()
        return run_test(sel)
Пример #4
0
def submit(course, tid=None, pastebin=False, review=False):
    """
    Submit the selected exercise to the server.
    """
    if tid is not None:
        return submit_exercise(Exercise.byid(tid),
                               pastebin=pastebin,
                               request_review=review)
    else:
        sel = Exercise.get_selected()
        if not sel:
            raise NoExerciseSelected()
        return submit_exercise(sel, pastebin=pastebin, request_review=review)
Пример #5
0
def test(course, tid=None, time=None):
    """
    Run tests on the selected exercise.
    """
    if time is not None:
        conf.tests_show_time = time
    if tid is not None:
        return run_test(Exercise.byid(tid))
    else:
        sel = Exercise.get_selected()
        if not sel:
            raise NoExerciseSelected()
        return run_test(sel)
Пример #6
0
def submit(course, tid=None, pastebin=False, review=False):
    """
    Submit the selected exercise to the server.
    """
    if tid is not None:
        return submit_exercise(Exercise.byid(tid),
                               pastebin=pastebin,
                               request_review=review)
    else:
        sel = Exercise.get_selected()
        if not sel:
            raise NoExerciseSelected()
        return submit_exercise(sel, pastebin=pastebin, request_review=review)
Пример #7
0
def select(course=False, tid=None, auto=False):
    """
    Select a course or an exercise.
    """
    if course:
        update(course=True)
        course = None
        try:
            course = Course.get_selected()
        except NoCourseSelected:
            pass

        ret = {}
        if not tid:
            ret = Menu.launch("Select a course",
                              Course.select().execute(),
                              course)
        else:
            ret["item"] = Course.get(Course.tid == tid)
        if "item" in ret:
            ret["item"].set_select()
            update()
            if ret["item"].path == "":
                select_a_path(auto=auto)
            # Selects the first exercise in this course
            skip()
            return
        else:
            print("You can select the course with `tmc select --course`")
            return
    else:
        selected = None
        try:
            selected = Exercise.get_selected()
        except NoExerciseSelected:
            pass

        ret = {}
        if not tid:
            ret = Menu.launch("Select an exercise",
                              Course.get_selected().exercises,
                              selected)
        else:
            ret["item"] = Exercise.byid(tid)
        if "item" in ret:
            ret["item"].set_select()
            print("Selected {}".format(ret["item"]))
Пример #8
0
def select(course=False, tid=None, auto=False):
    """
    Select a course or an exercise.
    """
    if course:
        update(course=True)
        course = None
        try:
            course = Course.get_selected()
        except NoCourseSelected:
            pass

        ret = {}
        if not tid:
            ret = Menu.launch("Select a course",
                              Course.select().execute(), course)
        else:
            ret["item"] = Course.get(Course.tid == tid)
        if "item" in ret:
            ret["item"].set_select()
            update()
            if ret["item"].path == "":
                select_a_path(auto=auto)
            # Selects the first exercise in this course
            skip()
            return
        else:
            print("You can select the course with `tmc select --course`")
            return
    else:
        selected = None
        try:
            selected = Exercise.get_selected()
        except NoExerciseSelected:
            pass

        ret = {}
        if not tid:
            ret = Menu.launch("Select an exercise",
                              Course.get_selected().exercises, selected)
        else:
            ret["item"] = Exercise.byid(tid)
        if "item" in ret:
            ret["item"].set_select()
            print("Selected {}".format(ret["item"]))