ui consistency thing again

Vincent Ladeuil v.ladeuil+lp at free.fr
Fri Nov 30 07:20:45 GMT 2007


>>>>> "Mats" == Wichmann, Mats D <mats.d.wichmann at intel.com> writes:

    Mats> Martin Pool wrote:
    >> On Nov 30, 2007 5:22 AM, Wichmann, Mats D
    >> <mats.d.wichmann at intel.com> wrote:
    >>> 
    >>> Just chatting with Jeff Licquia, we've both been
    >>> bothered by the same gripe in this "ui consistency" area:
    >> 
    >> In the recent 'ui consistency' thread started by Jelmer, I think we
    >> agreed we'd change to always displaying paths relative to the cwd. --
    >> Martin

    Mats> Yeah, I thought I noticed that.

    Mats> Mainly, paths-relative-to-cwd if you asked for them, at least :)


Then you'll be happy to know that python2.6 will provide:

in posixpath.py

def relpath(path, start=curdir):
    """Return a relative version of a path"""

    if not path:
        raise ValueError("no path specified")

    start_list = abspath(start).split(sep)
    path_list = abspath(path).split(sep)

    # Work out how much of the filepath is shared by start and path.
    i = len(commonprefix([start_list, path_list]))

    rel_list = [pardir] * (len(start_list)-i) + path_list[i:]
    return join(*rel_list)

and in ntpath.py

def relpath(path, start=curdir):
    """Return a relative version of a path"""

    if not path:
        raise ValueError("no path specified")
    start_list = abspath(start).split(sep)
    path_list = abspath(path).split(sep)
    if start_list[0].lower() != path_list[0].lower():
        unc_path, rest = splitunc(path)
        unc_start, rest = splitunc(start)
        if bool(unc_path) ^ bool(unc_start):
            raise ValueError("Cannot mix UNC and non-UNC paths (%s and %s)"
                                                                % (path, start))
        else:
            raise ValueError("path is on drive %s, start on drive %s"
                                                % (path_list[0], start_list[0]))
    # Work out how much of the filepath is shared by start and path.
    for i in range(min(len(start_list), len(path_list))):
        if start_list[i].lower() != path_list[i].lower():
            break
    else:
        i += 1

    rel_list = [pardir] * (len(start_list)-i) + path_list[i:]
    return join(*rel_list)


May be worth including in our own osutils.py

    Vincent



More information about the bazaar mailing list