Example #1
0
def check_for_updates():
    from xmlrpc.client import ServerProxy
    from distutils.version import StrictVersion
    pypi = ServerProxy("http://pypi.python.org/pypi")
    version = StrictVersion(__version__)
    pypiversion = StrictVersion(pypi.package_releases("tmc")[0])
    if pypiversion > version:
        infomsg("There is a new version available. ({})".format(pypiversion))
        print("You can upgrade tmc.py with either of these ways, depending",
              "on the way you installed tmc.py in the first place.",
              "\nIf you installed it with pip:",
              "\n    sudo pip install --upgrade tmc",
              "\nIf you installed it with the installation script:",
              "\n    Run the script again and select upgrade.")
    elif pypiversion < version:
        print("You are running a newer version than available.")
    else:
        print("You are running the most current version.")
Example #2
0
def check_for_updates():
    from xmlrpc.client import ServerProxy
    from distutils.version import StrictVersion
    pypi = ServerProxy("http://pypi.python.org/pypi")
    version = StrictVersion(__version__)
    pypiversion = StrictVersion(pypi.package_releases("tmc")[0])
    if pypiversion > version:
        infomsg("There is a new version available. ({})".format(pypiversion))
        print("You can upgrade tmc.py with either of these ways, depending",
              "on the way you installed tmc.py in the first place.",
              "\nIf you installed it with pip:",
              "\n    sudo pip install --upgrade tmc",
              "\nIf you installed it with the installation script:",
              "\n    Run the script again and select upgrade.")
    elif pypiversion < version:
        print("You are running a newer version than available.")
    else:
        print("You are running the most current version.")
Example #3
0
def main():
    parser = argh.ArghParser()
    parser.add_commands(commands)

    needs_update = should_update()
    Config.set("needs_update", "1" if needs_update else "0")
    if needs_update:
        infomsg("Update available to tmc.py. See tmc check-for-updates",
                "for more info.")

    # By default Argh only shows shortened help when no command is given.
    # This makes it print out the full help instead.
    if len(sys.argv) == 1:
        return parser.dispatch(argv=["help"])

    try:
        parser.dispatch()
    except TMCError as e:
        print(e)
        exit(-1)
Example #4
0
def main():
    parser = argh.ArghParser()
    parser.add_commands(commands)

    needs_update = should_update()
    Config.set("needs_update", "1" if needs_update else "0")
    if needs_update:
        infomsg("Update available to tmc.py. See tmc check-for-updates",
                "for more info.")

    # By default Argh only shows shortened help when no command is given.
    # This makes it print out the full help instead.
    if len(sys.argv) == 1:
        return parser.dispatch(argv=["help"])

    try:
        parser.dispatch()
    except TMCError as e:
        print(e)
        exit(-1)
Example #5
0
def submit_exercise(exercise, request_review=False, pastebin=False):
    outpath = exercise.path()
    infomsg("Submitting from:", outpath)
    print("{} -> {}".format(exercise.menuname(), "TMC Server"))
    outpath = os.path.join(outpath, "src")
    if not os.path.isdir(outpath):
        raise NotDownloaded()
    exercise.is_downloaded = True
    exercise.save()

    params = {}
    if request_review:
        params["request_review"] = "wolololo"
    if pastebin:
        params["paste"] = "wolololo"

    resp = None

    with Spinner.context(msg="Submission has been sent.",
                         waitmsg="Sending submission."):
        tmpfile = BytesIO()
        with zipfile.ZipFile(tmpfile, "w") as zipfp:
            for root, _, files in os.walk(outpath):
                for file in files:
                    filename = os.path.join(root, file)
                    archname = os.path.relpath(os.path.join(root, file),
                                               os.path.join(outpath, '..'))
                    compress_type = zipfile.ZIP_DEFLATED
                    zipfp.write(filename, archname, compress_type)

        resp = api.send_zip(exercise, tmpfile.getvalue(), params)

    if "submission_url" not in resp:
        return

    url = resp["submission_url"]

    @Spinner.decorate(msg="Results:", waitmsg="Waiting for results.")
    def inner():
        while True:
            data = api.get_submission(url)
            if data:
                return data
            time.sleep(1)

    data = inner()

    success = True

    status = data["status"]

    if status == "fail":
        warningmsg("Some tests failed:")
        warningmsg("------------------")
        for test in data["test_cases"]:
            if test["successful"]:
                if conf.tests_show_successful:
                    successmsg("{name}: {message}".format(**test))
            else:
                errormsg("{name}:\n  {message}".format(**test))

        helper = "For better details run 'tmc test --id {0}'\n"
        warningmsg(helper.format(repr(exercise.tid)))
        success = False

    elif status == "ok":
        successmsg("All tests successful!")
        successmsg("---------------------")
        points = ", ".join(data["points"])
        successmsg("Points [{0}]".format(points))
        exercise.is_completed = exercise.is_attempted = True
        exercise.save()

    elif status == "error":
        warningmsg("Something went wrong :(")
        warningmsg("-----------------------")
        errormsg(data["error"])

    else:
        raise TMCError("Submission status unknown: {0}".format(status))

    if data.get("paste_url"):
        infomsg("Pastebin URL: " + data["paste_url"])

    if data.get("requests_review", False):
        if data.get("reviewed", False):
            infomsg("This submission has been reviewed")
        else:
            infomsg("Requested a review")

    infomsg("Submission URL: " + url.split(".json")[0])

    if not success:
        return False
Example #6
0
File: files.py Project: jgke/tmc.py
def submit_exercise(exercise, request_review=False, pastebin=False):
    outpath = exercise.path()
    infomsg("Submitting from:", outpath)
    print("{} -> {}".format(exercise.menuname(), "TMC Server"))
    outpath = os.path.join(outpath, "src")
    if not os.path.isdir(outpath):
        raise NotDownloaded()
    exercise.is_downloaded = True
    exercise.save()

    params = {}
    if request_review:
        params["request_review"] = "wolololo"
    if pastebin:
        params["paste"] = "wolololo"

    resp = None

    with Spinner.context(msg="Submission has been sent.",
                         waitmsg="Sending submission."):
        tmpfile = BytesIO()
        with zipfile.ZipFile(tmpfile, "w") as zipfp:
            for root, _, files in os.walk(outpath):
                for file in files:
                    filename = os.path.join(root, file)
                    archname = os.path.relpath(os.path.join(root, file),
                                               os.path.join(outpath, '..'))
                    compress_type = zipfile.ZIP_DEFLATED
                    zipfp.write(filename, archname, compress_type)

        resp = api.send_zip(exercise.tid, tmpfile.getvalue(), params)

    if "submission_url" not in resp:
        return

    url = resp["submission_url"]
    submission_id = int(url.split(".json")[0].split("submissions/")[1])

    @Spinner.decorate(msg="Results:", waitmsg="Waiting for results.")
    def inner():
        while True:
            data = api.get_submission(submission_id)
            if data:
                return data
            time.sleep(1)
    data = inner()

    success = True

    status = data["status"]

    if status == "fail":
        warningmsg("Some tests failed:")
        warningmsg("------------------")
        for test in data["test_cases"]:
            if test["successful"]:
                if conf.tests_show_successful:
                    successmsg("{name}: {message}".format(**test))
            else:
                errormsg("{name}:\n  {message}".format(**test))

        helper = "For better details run 'tmc test --id {0}'\n"
        warningmsg(helper.format(repr(exercise.tid)))
        success = False

    elif status == "ok":
        successmsg("All tests successful!")
        successmsg("---------------------")
        points = ", ".join(data["points"])
        successmsg("Points [{0}]".format(points))
        exercise.is_completed = exercise.is_attempted = True
        exercise.save()

    elif status == "error":
        warningmsg("Something went wrong :(")
        warningmsg("-----------------------")
        errormsg(data["error"])

    else:
        raise TMCError("Submission status unknown: {0}".format(status))

    if "paste_url" in data:
        infomsg("Pastebin URL: " + data["paste_url"])

    if data.get("requests_review", False):
        if data.get("reviewed", False):
            infomsg("This submission has been reviewed")
        else:
            infomsg("Requested a review")

    infomsg("Submission URL: " + url.split(".json")[0])

    if not success:
        return False