'Insert self.location in path before its nearest parent directory'

def insert_on(self, path, loc=None):

    loc = (loc or self.location)
    if (not loc):
        return
    nloc = _normalize_cached(loc)
    bdir = os.path.dirname(nloc)
    npath = [((p and _normalize_cached(p)) or p) for p in path]
    for (p, item) in enumerate(npath):
        if (item == nloc):
            break
        elif ((item == bdir) and (self.precedence == EGG_DIST)):
            if (path is sys.path):
                self.check_version_conflict()
            path.insert(p, loc)
            npath.insert(p, nloc)
            break
    else:
        if (path is sys.path):
            self.check_version_conflict()
        path.append(loc)
        return
    while 1:
        try:
            np = npath.index(nloc, (p + 1))
        except ValueError:
            break
        else:
            del npath[np], path[np]
            p = np
    return
