How to use submit50 - 10 common examples

To help you get started, we’ve selected a few submit50 examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github cs50 / submit50 / submit50 / __main__.py View on Github external
def excepthook(type, value, tb):
    """Report an exception."""
    if (issubclass(type, Error) or issubclass(type, lib50.Error)) and str(value):
        for line in str(value).split("\n"):
            cprint(str(line), "yellow")
    elif not isinstance(value, KeyboardInterrupt):
        cprint(_("Sorry, something's wrong! Let sysadmins@cs50.harvard.edu know!"), "yellow")

    if excepthook.verbose:
        traceback.print_exception(type, value, tb)

    cprint(_("Submission cancelled."), "red")
github cs50 / submit50 / submit50 / __main__.py View on Github external
def __call__(self, parser, namespace, values, option_string=None):
        try:
            lib50.logout()
        except lib50.Error:
            raise Error(_("failed to logout"))
        else:
            cprint(_("logged out successfully"), "green")
        parser.exit()
github cs50 / check50 / check50.py View on Github external
config.args.local = True

    if not config.args.local:
        try:

            # Submit to check50 repo.
            import submit50
        except ImportError:
            raise InternalError(
                "submit50 is not installed. Install submit50 and run check50 again.")
        else:
            submit50.handler.type = "check"
            signal.signal(signal.SIGINT, submit50.handler)

            submit50.run.verbose = config.args.verbose
            username, commit_hash = submit50.submit("check50", identifier)

            # Wait until payload comes back with check data.
            print("Checking...", end="")
            sys.stdout.flush()
            pings = 0
            while True:

                # Terminate if no response.
                if pings > 45:
                    print()
                    cprint("check50 is taking longer than normal!", "red", file=sys.stderr)
                    cprint("See https://legacy.cs50.me/checks/{} for more detail.".format(commit_hash),
                           "red", file=sys.stderr)
                    sys.exit(1)
                pings += 1
github cs50 / check50 / check50.py View on Github external
files = config.args.files

    if config.args.offline:
        config.args.local = True

    if not config.args.local:
        try:

            # Submit to check50 repo.
            import submit50
        except ImportError:
            raise InternalError(
                "submit50 is not installed. Install submit50 and run check50 again.")
        else:
            submit50.handler.type = "check"
            signal.signal(signal.SIGINT, submit50.handler)

            submit50.run.verbose = config.args.verbose
            username, commit_hash = submit50.submit("check50", identifier)

            # Wait until payload comes back with check data.
            print("Checking...", end="")
            sys.stdout.flush()
            pings = 0
            while True:

                # Terminate if no response.
                if pings > 45:
                    print()
                    cprint("check50 is taking longer than normal!", "red", file=sys.stderr)
                    cprint("See https://legacy.cs50.me/checks/{} for more detail.".format(commit_hash),
                           "red", file=sys.stderr)
github cs50 / check50 / check50.py View on Github external
identifier = config.args.identifier[0]
    files = config.args.files

    if config.args.offline:
        config.args.local = True

    if not config.args.local:
        try:

            # Submit to check50 repo.
            import submit50
        except ImportError:
            raise InternalError(
                "submit50 is not installed. Install submit50 and run check50 again.")
        else:
            submit50.handler.type = "check"
            signal.signal(signal.SIGINT, submit50.handler)

            submit50.run.verbose = config.args.verbose
            username, commit_hash = submit50.submit("check50", identifier)

            # Wait until payload comes back with check data.
            print("Checking...", end="")
            sys.stdout.flush()
            pings = 0
            while True:

                # Terminate if no response.
                if pings > 45:
                    print()
                    cprint("check50 is taking longer than normal!", "red", file=sys.stderr)
                    cprint("See https://legacy.cs50.me/checks/{} for more detail.".format(commit_hash),
github cs50 / check50 / check50.py View on Github external
if config.args.offline:
        config.args.local = True

    if not config.args.local:
        try:

            # Submit to check50 repo.
            import submit50
        except ImportError:
            raise InternalError(
                "submit50 is not installed. Install submit50 and run check50 again.")
        else:
            submit50.handler.type = "check"
            signal.signal(signal.SIGINT, submit50.handler)

            submit50.run.verbose = config.args.verbose
            username, commit_hash = submit50.submit("check50", identifier)

            # Wait until payload comes back with check data.
            print("Checking...", end="")
            sys.stdout.flush()
            pings = 0
            while True:

                # Terminate if no response.
                if pings > 45:
                    print()
                    cprint("check50 is taking longer than normal!", "red", file=sys.stderr)
                    cprint("See https://legacy.cs50.me/checks/{} for more detail.".format(commit_hash),
                           "red", file=sys.stderr)
                    sys.exit(1)
                pings += 1
github cs50 / submit50 / submit50 / __main__.py View on Github external
def check_version():
    """Check that submit50 is the latest version according to submit50.io."""
    # Retrieve version info
    res = requests.get(f"{SUBMIT_URL}/versions/submit50")
    if res.status_code != 200:
        raise Error(_("You have an unknown version of submit50. "
                      "Email sysadmins@cs50.harvard.edu!"))

    # Check that latest version == version installed
    required_version = pkg_resources.parse_version(res.text.strip())
    local_version = pkg_resources.parse_version(__version__)

    if required_version > local_version:
       raise Error(_("You have an outdated version of submit50. "
                     "Please upgrade."))
github cs50 / submit50 / submit50 / __main__.py View on Github external
def check_announcements():
    """Check for any announcements from submit.cs50.io, raise Error if so."""
    res = requests.get(f"{SUBMIT_URL}/status/submit50")
    if res.status_code == 200 and res.text.strip():
        raise Error(res.text.strip())
github cs50 / submit50 / submit50 / __main__.py View on Github external
def prompt(included, excluded):
    if included:
        cprint(_("Files that will be submitted:"), "green")
        for file in included:
            cprint("./{}".format(file), "green")
    else:
        raise Error(_("No files in this directory are expected for submission."))

    # Files that won't be submitted
    if excluded:
        cprint(_("Files that won't be submitted:"), "yellow")
        for other in excluded:
            cprint("./{}".format(other), "yellow")

    # Prompt for honesty
    readline.clear_history()
    try:
        answer = input(_("Keeping in mind the course's policy on academic honesty, "
                         "are you sure you want to submit these files (yes/no)? "))
    except EOFError:
        answer = None
        print()
    if not answer or not re.match(f"^\s*(?:{_('y|yes')})\s*$", answer, re.I):
github cs50 / submit50 / submit50 / __main__.py View on Github external
def main():
    sys.excepthook = excepthook

    parser = argparse.ArgumentParser(prog="submit50")
    parser.add_argument("--logout", action=LogoutAction)
    parser.add_argument("-v", "--verbose",
                        action="store_true",
                        help=_("show commands being executed"))
    parser.add_argument("-V", "--version", action="version", version=f"%(prog)s {__version__}")
    parser.add_argument("slug", help=_(
        "prescribed identifier of work to submit"))

    args = parser.parse_args()

    excepthook.verbose = args.verbose
    if args.verbose:
        logging.basicConfig(level=os.environ.get("SUBMIT50_LOGLEVEL", "INFO"))
        # Disable progress bar so it doesn't interfere with log
        lib50.ProgressBar.DISABLED = True

    check_announcements()
    check_version()

    user_name, commit_hash, message = lib50.push("submit50", args.slug, CONFIG_LOADER, prompt=prompt)
    print(message)

submit50

This is submit50, with which you can submit solutions to problems for CS50.

GPL-3.0
Latest version published 4 months ago

Package Health Score

60 / 100
Full package analysis

Similar packages