|
@@ -0,0 +1,37 @@
|
|
|
|
+from __future__ import absolute_import
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+def abbr(S, max, ellipsis="..."):
|
|
|
|
+ if S is None:
|
|
|
|
+ return "???"
|
|
|
|
+ if len(S) > max:
|
|
|
|
+ return ellipsis and (S[:max - len(ellipsis)] + ellipsis) or S[:max]
|
|
|
|
+ return S
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+def abbrtask(S, max):
|
|
|
|
+ if S is None:
|
|
|
|
+ return "???"
|
|
|
|
+ if len(S) > max:
|
|
|
|
+ module, _, cls = S.rpartition(".")
|
|
|
|
+ module = abbr(module, max - len(cls) - 3, False)
|
|
|
|
+ return module + "[.]" + cls
|
|
|
|
+ return S
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+def indent(t, indent=0):
|
|
|
|
+ """Indent text."""
|
|
|
|
+ return "\n".join(" " * indent + p for p in t.split("\n"))
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+def truncate(text, maxlen=128, suffix='...'):
|
|
|
|
+ """Truncates text to a maximum number of characters."""
|
|
|
|
+ if len(text) >= maxlen:
|
|
|
|
+ return text[:maxlen].rsplit(" ", 1)[0] + suffix
|
|
|
|
+ return text
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+def pluralize(n, text, suffix='s'):
|
|
|
|
+ if n > 1:
|
|
|
|
+ return text + suffix
|
|
|
|
+ return text
|