Example #1
0
def select_a_path(course, auto=False):
    defpath = os.path.join(os.path.expanduser("~"), "tmc", course.name)
    if auto:
        path = defpath
    else:
        path = input("File download path [{0}]: ".format(defpath)).strip()
    if len(path) == 0:
        path = defpath
    path = os.path.expanduser(path)
    # I guess we are looking at a relative path
    if not path.startswith("/"):
        path = os.path.join(os.getcwd(), path)
    print("Using path: '{}'".format(path))
    course.path = path
    course.save()
    if auto:
        return
    ret = custom_prompt("Download exercises R: Remaining A: All N: None",
                        ["r", "a", "n"], "r")
    if ret == "a":
        download(dl_all=True)
    elif ret == "r":
        download()
    else:
        print("You can download the exercises with `tmc download --all`")
Example #2
0
def select_a_path(course, auto=False):
    defpath = os.path.join(os.path.expanduser("~"),
                           "tmc",
                           course.name)
    if auto:
        path = defpath
    else:
        path = input("File download path [{0}]: ".format(defpath)).strip()
    if len(path) == 0:
        path = defpath
    path = os.path.expanduser(path)
    # I guess we are looking at a relative path
    if not path.startswith("/"):
        path = os.path.join(os.getcwd(), path)
    print("Using path: '{}'".format(path))
    course.path = path
    course.save()
    if auto:
        return
    ret = custom_prompt("Download exercises R: Remaining A: All N: None",
                        ["r", "a", "n"],
                        "r")
    if ret == "a":
        download(dl_all=True)
    elif ret == "r":
        download()
    else:
        print("You can download the exercises with `tmc download --all`")
Example #3
0
def configure(server=None, username=None, password=None, tid=None, auto=False):
    """
    Configure tmc.py to use your account.
    """
    if not server and not username and not password and not tid:
        if Config.has():
            if not yn_prompt("Override old configuration", False):
                return False
    reset_db()
    if not server:
        while True:
            defaulturl = "https://src.aalto.fi/tmc/org/aalto/"
            server = input("Server url [" + defaulturl + "]: ").strip()
            if len(server) == 0:
                server = defaulturl
            if not server.endswith('/'):
                server += '/'
            if not (server.startswith("http://")
                    or server.startswith("https://")):
                ret = custom_prompt(
                    "Server should start with http:// or https://\n" +
                    "R: Retry, H: Assume http://, S: Assume https://",
                    ["r", "h", "s"], "r")
                if ret == "r":
                    continue
                # Strip previous schema
                if "://" in server:
                    server = server.split("://")[1]
                if ret == "h":
                    server = "http://" + server
                elif ret == "s":
                    server = "https://" + server
            break

        print("Using URL: '{0}'".format(server))
    while True:
        if not username:
            username = input("Username: "******"Password: "******"{0}:{1}".format(username, password), encoding='utf-8')
        ).decode("utf-8")

        try:
            api.configure(url=server, token=token, test=True)
        except APIError as e:
            print(e)
            if auto is False and yn_prompt("Retry authentication"):
                username = password = None
                continue
            return False
        break
    if tid:
        select(course=True, tid=tid, auto=auto)
    else:
        select(course=True)
Example #4
0
def configure(server=None, username=None, password=None, tid=None, auto=False):
    """
    Configure tmc.py to use your account.
    """
    if not server and not username and not password and not tid:
        if Config.has():
            if not yn_prompt("Override old configuration", False):
                return False
    reset_db()
    if not server:
        while True:
            defaulturl = "https://src.aalto.fi/tmc/org/aalto/"
            server = input("Server url [" + defaulturl + "]: ").strip()
            if len(server) == 0:
                server = defaulturl
            if not server.endswith('/'):
                server += '/'
            if not (server.startswith("http://")
                    or server.startswith("https://")):
                ret = custom_prompt(
                    "Server should start with http:// or https://\n" +
                    "R: Retry, H: Assume http://, S: Assume https://",
                    ["r", "h", "s"], "r")
                if ret == "r":
                    continue
                # Strip previous schema
                if "://" in server:
                    server = server.split("://")[1]
                if ret == "h":
                    server = "http://" + server
                elif ret == "s":
                    server = "https://" + server
            break

        print("Using URL: '{0}'".format(server))
    while True:
        if not username:
            username = input("Username: "******"Password: "******"{0}:{1}".format(username, password),
                  encoding='utf-8')).decode("utf-8")

        try:
            api.configure(url=server, token=token, test=True)
        except APIError as e:
            print(e)
            if auto is False and yn_prompt("Retry authentication"):
                username = password = None
                continue
            return False
        break
    if tid:
        select(course=True, tid=tid, auto=auto)
    else:
        select(course=True)