/usr/share/pyshared/freshen/compat.py is in python-freshen 0.2-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | #-*- coding: utf8 -*-
from os.path import abspath, commonprefix, sep, pardir, join
import os
curdir = os.getcwd()
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:]
if not rel_list:
return curdir
return join(*rel_list)
if __name__ == "__main__":
print relpath("/tmp/dir1/file", "/tmp")
print relpath("/tmp/dir1/file", "/usr")
|