Browse Source

Fixes problem with colored output

Ask Solem 13 years ago
parent
commit
6d98c4fa51
3 changed files with 21 additions and 13 deletions
  1. 7 7
      Changelog
  2. 4 2
      celery/bin/celeryctl.py
  3. 10 4
      celery/utils/term.py

+ 7 - 7
Changelog

@@ -104,15 +104,15 @@ Important Notes
 * The :setting:`CELERY_TASK_ERROR_WHITELIST` setting has been replaced
   by a more flexible approach (Issue #447).
 
-  The Mail sending logic is now available as ``Task.ErrorMail``.
-  The actual implementation is in :mod:`celery.utils.mail`.
+    The error mail sending logic is now available as ``Task.ErrorMail``,
+    with the implementation (for reference) in :mod:`celery.utils.mail`.
 
-  The error mail class can be sub-classed to gain complete control
-  of when error messages are sent, thus removing the need for a separate
-  white-list setting.
+    The error mail class can be sub-classed to gain complete control
+    of when error messages are sent, thus removing the need for a separate
+    white-list setting.
 
-  The :setting:`CELERY_TASK_ERROR_WHITELIST` setting has been deprecated,
-  and will be removed completely in version 3.0.
+    The :setting:`CELERY_TASK_ERROR_WHITELIST` setting has been deprecated,
+    and will be removed completely in version 3.0.
 
 * Additional Deprecations
 

+ 4 - 2
celery/bin/celeryctl.py

@@ -234,6 +234,7 @@ class inspect(Command):
                     help="Timeout in seconds (float) waiting for reply"),
                 Option("--destination", "-d", dest="destination",
                     help="Comma separated list of destination node names."))
+    show_body = True
 
     def usage(self, command):
         return "%%prog %s [options] %s [%s]" % (
@@ -241,6 +242,7 @@ class inspect(Command):
 
     def run(self, *args, **kwargs):
         self.quiet = kwargs.get("quiet", False)
+        self.show_body = kwargs.get("show_body", False)
         if not args:
             raise Error("Missing inspect command. See --help")
         command = args[0]
@@ -276,7 +278,7 @@ class inspect(Command):
             return
         dirstr = not self.quiet and c.bold(c.white(direction), " ") or ""
         self.out(c.reset(dirstr, title))
-        if body and not self.quiet:
+        if body and self.show_body:
             self.out(body)
 inspect = command(inspect)
 
@@ -292,7 +294,7 @@ class status(Command):
     def run(self, *args, **kwargs):
         replies = inspect(app=self.app,
                           no_color=kwargs.get("no_color", False)) \
-                    .run("ping", **dict(kwargs, quiet=True))
+                    .run("ping", **dict(kwargs, quiet=True, show_body=False))
         if not replies:
             raise Error("No nodes replied within time constraint")
         nodecount = len(replies)

+ 10 - 4
celery/utils/term.py

@@ -54,7 +54,11 @@ class colored(object):
                       "white": self.white}
 
     def _add(self, a, b):
-        return safe_str(a) + safe_str(b)
+        if isinstance(a, unicode):
+            a = safe_str(a)
+        if isinstance(b, unicode):
+            b = safe_str(b)
+        return str(a) + str(b)
 
     def _fold_no_color(self, a, b):
         try:
@@ -68,7 +72,9 @@ class colored(object):
         return A + B
 
     def no_color(self):
-        return reduce(self._fold_no_color, self.s)
+        if self.s:
+            return reduce(self._fold_no_color, self.s)
+        return ""
 
     def embed(self):
         prefix = ""
@@ -80,7 +86,7 @@ class colored(object):
         suffix = ""
         if self.enabled:
             suffix = RESET_SEQ
-        return self.embed() + suffix
+        return safe_str(self.embed()) + suffix
 
     def node(self, s, op):
         return self.__class__(enabled=self.enabled, op=op, *s)
@@ -152,4 +158,4 @@ class colored(object):
         return self.node(s or [""], RESET_SEQ)
 
     def __add__(self, other):
-        return safe_str(self) + safe_str(other)
+        return str(self) + str(other)