diff options
Diffstat (limited to 'module')
| -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: | 
