summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard Purdie <richard.purdie@linuxfoundation.org>2012-11-25 21:17:41 +0000
committerRichard Purdie <richard.purdie@linuxfoundation.org>2012-11-25 21:36:44 +0000
commit9be83df144a1675c8e7c9f0962e7e9e61ff767fd (patch)
treed19043f8a9241b3d70a66068a43e8540589e0bea
parent8a3dd9e9081d09f9c38c98b34f14bbd2a9b824a5 (diff)
downloadpoky-9be83df144a1675c8e7c9f0962e7e9e61ff767fd.tar.gz
bitbake: knotty/msg: Avoid usage of curses initscr/endwin to avoid terminal corruption
Using curses initscr/endwin causes screen corruption if for example you suspend bitbake and resume it. This changes the code to use a less invasive approach to determining colour availability on the terminal. (Bitbake rev: 4548a8f037eaf8d47a77052acc3e9ec264ac41e0) Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
-rw-r--r--bitbake/lib/bb/msg.py12
-rw-r--r--bitbake/lib/bb/ui/knotty.py8
2 files changed, 5 insertions, 15 deletions
diff --git a/bitbake/lib/bb/msg.py b/bitbake/lib/bb/msg.py
index 007c95a4ea..e70daee92f 100644
--- a/bitbake/lib/bb/msg.py
+++ b/bitbake/lib/bb/msg.py
@@ -106,17 +106,7 @@ class BBLogFormatter(logging.Formatter):
106 return record 106 return record
107 107
108 def enable_color(self): 108 def enable_color(self):
109 import curses 109 self.color_enabled = True
110 try:
111 win = None
112 win = curses.initscr()
113 if curses.has_colors():
114 self.color_enabled = True
115 except:
116 pass
117 finally:
118 if win is not None:
119 curses.endwin()
120 110
121class BBLogFilter(object): 111class BBLogFilter(object):
122 def __init__(self, handler, level, debug_domains): 112 def __init__(self, handler, level, debug_domains):
diff --git a/bitbake/lib/bb/ui/knotty.py b/bitbake/lib/bb/ui/knotty.py
index a63d8b120e..be63e730f0 100644
--- a/bitbake/lib/bb/ui/knotty.py
+++ b/bitbake/lib/bb/ui/knotty.py
@@ -157,6 +157,8 @@ class TerminalFilter(object):
157 new[3] = new[3] & ~termios.ECHO 157 new[3] = new[3] & ~termios.ECHO
158 termios.tcsetattr(fd, termios.TCSADRAIN, new) 158 termios.tcsetattr(fd, termios.TCSADRAIN, new)
159 curses.setupterm() 159 curses.setupterm()
160 if curses.tigetnum("colors") > 2:
161 format.enable_color()
160 self.ed = curses.tigetstr("ed") 162 self.ed = curses.tigetstr("ed")
161 if self.ed: 163 if self.ed:
162 self.cuu = curses.tigetstr("cuu") 164 self.cuu = curses.tigetstr("cuu")
@@ -240,17 +242,15 @@ def main(server, eventHandler, tf = TerminalFilter):
240 console = logging.StreamHandler(sys.stdout) 242 console = logging.StreamHandler(sys.stdout)
241 format_str = "%(levelname)s: %(message)s" 243 format_str = "%(levelname)s: %(message)s"
242 format = bb.msg.BBLogFormatter(format_str) 244 format = bb.msg.BBLogFormatter(format_str)
243 if interactive:
244 format.enable_color()
245 bb.msg.addDefaultlogFilter(console) 245 bb.msg.addDefaultlogFilter(console)
246 console.setFormatter(format) 246 console.setFormatter(format)
247 logger.addHandler(console) 247 logger.addHandler(console)
248 if consolelogfile: 248 if consolelogfile:
249 bb.utils.mkdirhier(os.path.dirname(consolelogfile)) 249 bb.utils.mkdirhier(os.path.dirname(consolelogfile))
250 format = bb.msg.BBLogFormatter(format_str) 250 conlogformat = bb.msg.BBLogFormatter(format_str)
251 consolelog = logging.FileHandler(consolelogfile) 251 consolelog = logging.FileHandler(consolelogfile)
252 bb.msg.addDefaultlogFilter(consolelog) 252 bb.msg.addDefaultlogFilter(consolelog)
253 consolelog.setFormatter(format) 253 consolelog.setFormatter(conlogformat)
254 logger.addHandler(consolelog) 254 logger.addHandler(consolelog)
255 255
256 try: 256 try: