# HG changeset patch # User David Anderson # Date 1236968084 0 # Node ID 9df2e9a6708125628d5bd610db30750043a9243d # Parent 5ded837037e7a5c45edcbd568d7a45f26fc06371 Add a decolorize() helper to undo the effects of colorize(). diff -r 5ded837037e7 -r 9df2e9a67081 scripts/release/util.py --- a/scripts/release/util.py Fri Mar 13 16:56:56 2009 +0000 +++ b/scripts/release/util.py Fri Mar 13 18:14:44 2009 +0000 @@ -26,6 +26,7 @@ ] import os.path +import re import subprocess import error @@ -43,6 +44,7 @@ # configure fore/background colors and other basic text display # settings. _ANSI_ESCAPE = '\x1b[%dm' +_ANSI_ESCAPE_RE = re.compile(r'\x1b\[\d+m') # Some internal non-color settings that we use. @@ -82,6 +84,11 @@ text, _ansi_escape(_RESET)) +def decolorize(text): + """Remove ANSI color codes from text.""" + return _ANSI_ESCAPE_RE.sub('', text) + + class Paths(object): """A helper to construct and check paths under a given root."""