diff options
author | 2014-08-27 15:22:39 +0200 | |
---|---|---|
committer | 2014-08-27 15:22:39 +0200 | |
commit | 4c8a6401abe2ee3752d8a30402e74e882042352f (patch) | |
tree | 64e14f3147bb60ade00aeb21a9fa97a8f862733c /module/webui/filters.py | |
parent | Re-apply 8446e16346ece5a934550f69e81d0cad528f7fba (diff) | |
download | pyload-4c8a6401abe2ee3752d8a30402e74e882042352f.tar.xz |
[webui] Restructure file tree + convert tabs to 2 whitespaces + remove setup.html
Diffstat (limited to 'module/webui/filters.py')
-rw-r--r-- | module/webui/filters.py | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/module/webui/filters.py b/module/webui/filters.py new file mode 100644 index 000000000..c5e9447ee --- /dev/null +++ b/module/webui/filters.py @@ -0,0 +1,61 @@ +# -*- coding: utf-8 -*- +import os +from os.path import abspath, commonprefix, join + +quotechar = "::/" + +try: + from os.path import relpath +except: + 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 = 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) + + +def quotepath(path): + try: + return path.replace("../", quotechar) + except AttributeError: + return path + except: + return "" + +def unquotepath(path): + try: + return path.replace(quotechar, "../") + except AttributeError: + return path + except: + return "" + +def path_make_absolute(path): + p = os.path.abspath(path) + if p[-1] == os.path.sep: + return p + else: + return p + os.path.sep + +def path_make_relative(path): + p = relpath(path) + if p[-1] == os.path.sep: + return p + else: + return p + os.path.sep + +def truncate(value, n): + if (n - len(value)) < 3: + return value[:n]+"..." + return value + +def date(date, format): + return date |