diff options
author | RaNaN <Mast3rRaNaN@hotmail.de> | 2010-11-27 00:34:33 +0100 |
---|---|---|
committer | RaNaN <Mast3rRaNaN@hotmail.de> | 2010-11-27 00:34:33 +0100 |
commit | a1e180a243896024e2c283f7f61478845de749cf (patch) | |
tree | dfa53cb81dad1a01f32b0308bd0be4c26c58a0d8 /module/web | |
parent | fix (diff) | |
download | pyload-a1e180a243896024e2c283f7f61478845de749cf.tar.xz |
more fixes
Diffstat (limited to 'module/web')
-rw-r--r-- | module/web/pyload/templatetags/quotepath.py | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/module/web/pyload/templatetags/quotepath.py b/module/web/pyload/templatetags/quotepath.py index 3678b9391..8483a1553 100644 --- a/module/web/pyload/templatetags/quotepath.py +++ b/module/web/pyload/templatetags/quotepath.py @@ -3,6 +3,23 @@ import os from django.template.defaultfilters import stringfilter from django import template +try: + from os.path import relpath +except: + from posixpath import curdir, sep, pardir, join + 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) + register = template.Library() quotechar = "::/" @@ -41,7 +58,7 @@ def path_make_absolute(path): register.filter(path_make_absolute) def path_make_relative(path): - p = os.path.relpath(path) + p = relpath(path) if p[-1] == os.path.sep: return p else: |