def print(self): msg = self.name if self.warning: return warningmsg(self.message) if conf.tests_show_time and self.time is not None: msg += " ({0}s)".format(self.time) if self.success and conf.tests_show_trace: msg += "\n" if not self.success: msg += ": " + self.message if conf.tests_show_trace and self.trace: msg += "\n" + self.trace elif conf.tests_show_partial_trace and self.trace: msg += "\n" + "\n".join(self.trace.split("\n")[:5]) if self.success and conf.tests_show_successful: successmsg(msg, "OK!") elif not self.success: errormsg(msg)
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
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