Browse Source

Moved cursesmon.abbr + abbrtask to celery.utils

Ask Solem 14 years ago
parent
commit
495511ad1c
2 changed files with 19 additions and 16 deletions
  1. 1 16
      celery/events/cursesmon.py
  2. 18 0
      celery/utils/__init__.py

+ 1 - 16
celery/events/cursesmon.py

@@ -15,24 +15,9 @@ from celery.events import EventReceiver
 from celery.events.state import State
 from celery.messaging import establish_connection
 from celery.task import control
+from celery.utils import abbr, abbrtask
 
 
-def abbr(S, max, dots=True):
-    if S is None:
-        return "???"
-    if len(S) > max:
-        return dots and S[:max-3] + "..." or S[:max-3]
-    return S
-
-
-def abbrtask(S, max):
-    if S is None:
-        return "???"
-    if len(S) > max:
-        module, _, cls = rpartition(S, ".")
-        module = abbr(module, max - len(cls), False)
-        return module + "[.]" + cls
-    return S
 
 
 class CursesMonitor(object):

+ 18 - 0
celery/utils/__init__.py

@@ -360,3 +360,21 @@ def truncate_text(text, maxlen=128, suffix="..."):
     if len(text) >= maxlen:
         return text[:maxlen].rsplit(" ", 1)[0] + suffix
     return text
+
+
+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 = rpartition(S, ".")
+        module = abbr(module, max - len(cls), False)
+        return module + "[.]" + cls
+    return S