summaryrefslogtreecommitdiffstats
path: root/module/webui/filters.py
diff options
context:
space:
mode:
authorGravatar Walter Purcaro <vuolter@gmail.com> 2015-02-16 10:46:28 +0100
committerGravatar Walter Purcaro <vuolter@gmail.com> 2015-02-16 10:46:28 +0100
commitce1c2b6b05c08b669357947e61ae40efce7fc50f (patch)
tree0b5f7996960cf35c4eface53a89eba18a37519b7 /module/webui/filters.py
parentFix filename case (diff)
downloadpyload-ce1c2b6b05c08b669357947e61ae40efce7fc50f.tar.xz
module temp
Diffstat (limited to 'module/webui/filters.py')
-rw-r--r--module/webui/filters.py61
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..527b18446
--- /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 Exception:
+ 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 Exception:
+ return ""
+
+def unquotepath(path):
+ try:
+ return path.replace(quotechar, "../")
+ except AttributeError:
+ return path
+ except Exception:
+ 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