diff options
Diffstat (limited to 'module/web/pyload/views.py')
-rw-r--r-- | module/web/pyload/views.py | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/module/web/pyload/views.py b/module/web/pyload/views.py index 62c405339..0da21f556 100644 --- a/module/web/pyload/views.py +++ b/module/web/pyload/views.py @@ -20,7 +20,19 @@ from pyload.templatetags import quotepath try: from os.path import relpath except: - from pyload.templatetags import relpath + from posixpath import curdir, sep, pardir + def relpath(path, start=curdir): + """Return a relative version of a path""" + if not path: + raise ValueError("no path specified") + start_list = os.path.abspath(start).split(sep) + path_list = os.path.abspath(path).split(sep) + # Work out how much of the filepath is shared by start and path. + i = len(os.path.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) from django.conf import settings from django.contrib.auth.decorators import login_required |