Skip to content

Commit 495511a

Browse files
author
Ask Solem
committed
Moved cursesmon.abbr + abbrtask to celery.utils
1 parent 2762a31 commit 495511a

File tree

2 files changed

+19
-16
lines changed

2 files changed

+19
-16
lines changed

celery/events/cursesmon.py

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,24 +15,9 @@
1515
from celery.events.state import State
1616
from celery.messaging import establish_connection
1717
from celery.task import control
18+
from celery.utils import abbr, abbrtask
1819

1920

20-
def abbr(S, max, dots=True):
21-
if S is None:
22-
return "???"
23-
if len(S) > max:
24-
return dots and S[:max-3] + "..." or S[:max-3]
25-
return S
26-
27-
28-
def abbrtask(S, max):
29-
if S is None:
30-
return "???"
31-
if len(S) > max:
32-
module, _, cls = rpartition(S, ".")
33-
module = abbr(module, max - len(cls), False)
34-
return module + "[.]" + cls
35-
return S
3621

3722

3823
class CursesMonitor(object):

celery/utils/__init__.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,3 +360,21 @@ def truncate_text(text, maxlen=128, suffix="..."):
360360
if len(text) >= maxlen:
361361
return text[:maxlen].rsplit(" ", 1)[0] + suffix
362362
return text
363+
364+
365+
def abbr(S, max, ellipsis="..."):
366+
if S is None:
367+
return "???"
368+
if len(S) > max:
369+
return ellipsis and (S[:max-len(ellipsis)] + ellipsis) or S[:max]
370+
return S
371+
372+
373+
def abbrtask(S, max):
374+
if S is None:
375+
return "???"
376+
if len(S) > max:
377+
module, _, cls = rpartition(S, ".")
378+
module = abbr(module, max - len(cls), False)
379+
return module + "[.]" + cls
380+
return S

0 commit comments

Comments
 (0)