Exemplo n.º 1
0
Arquivo: tui.py Projeto: bc-python/cdt
def choosedir(description, constraint):
    print()
    print(description)

    while True:
        choice = input("\nPath to the directory:\n--> ")
        choice = cleanpath_escapedchars(choice)

        ppath = PPath(choice)

        # An existing file.
        if ppath.is_file():
            print()
            print("The path points to a file !", end=" ")

# An existing directory.
        elif ppath.is_dir():
            if constraint == DIR_MUST_BE_NEW:
                print()
                print("We need a new directory !", end=" ")

            elif constraint == DIR_MUST_BE_EMPTY and not ppath.is_empty():
                print()
                print("We need an empty directory !", end=" ")

            else:
                break

# A new directory.
        else:
            break

        print("Try again.")

    return ppath