示例#1
0
def find_msys_version_subdir(msys_dir):
    """Return the full MSYS root directory path

    If msys_dir path lacks the version subdirectory, e.g. 1.0, then the
    path is searched for one. The user will be prompted to choose if more
    than one version is found.
    """

    regex = r'[\\/][1-9][.][0-9]$'
    if re.search(regex, msys_dir) is not None:
        return msys_dir
    
    roots = glob.glob(os.path.join(msys_dir, '[1-9].[0-9]'))
    roots.sort()
    roots.reverse()
    if not roots:
        raise MsysException("No msys versions found.\n")
    else:
        if len(roots) == 1:
            root = roots[0]
        else:
            msys_print("Select an Msys version:")
            for i, path in enumerate(roots):
                msys_print("  %d = %s" % (i+1, os.path.split(path)[1]))
            choice = msys_raw_input("Select 1-%d (1 = default):")
            if not choice:
                root = roots[0]
            else:
                root = roots[int(choice)-1]
        return root
示例#2
0
def input_msys_dir():
    """Return user entered MSYS directory path

    May raise MsysException."""

    while 1:
        dir_path = msys_raw_input("Enter the MSYS directory path,\n"
                              "(or press [Enter] to quit):")
        dir_path = dir_path.strip()
        if not dir_path:
            raise MsysException("Input aborted by user")
        dir_path = os.path.abspath(dir_path)
        try:
            return find_msys_version_subdir(dir_path)
        except MsysException:
            msys_print(helpers.geterror ())
示例#3
0
def find_msys_shell(msys_directory=None):
    """Retrun the MSYS shell program path

    MsysException is raised if the shell program is not found. The user
    is prompt is prompted as a last resort if no directory is found or
    there are multiple choices.
    """

    shell = check_for_shell(msys_directory)
    while 1:
    
        shell = os.path.abspath(shell.replace('/', os.sep))
        if os.path.isfile(shell):
            break
        msys_print("Directory %s has no MSYS shell." % shell)
        shell = as_shell(input_msys_dir())
    return shell