def join(base, *extras): """Join two or more pathname components, inserting '/' as needed. If any component is an absolute path, all previous path components will be discarded. Normalize path (after join parts), eliminating double slashes, etc. """ try: path = _orig_join(base, *extras) except: base = fix_encoding(base) extras = [fix_encoding(extra) for extra in extras] path = _orig_join(base, *extras) return normpath(path)
def shorten_user(filename): """A filename is shortened looking for the (expantion) $HOME in his head and replacing it by '~'. """ home = expanduser("~") if filename.startswith(home): filename = _orig_join("~", filename[len(home) :]) return filename
def normalize_path(base, *extras): """Normalize path by: - expanding '~' and '~user' constructions. - eliminating double slashes - converting to absolute. """ # FIXME: [med] Redundant "path" in name "xoutil.fs.path.normalize_path" try: path = _orig_join(base, *extras) except: path = join(base, *extras) return abspath(expanduser(path))