# Path: sts/util/console.py
# class color(object):
#   GRAY, RED, GREEN, YELLOW, BLUE, MAGENTA, CYAN, WHITE, CRIMSON = map(lambda num : BEGIN + str(num) + "m", range(30, 39))
#   B_GRAY, B_RED, B_GREEN, B_YELLOW, B_BLUE, B_MAGENTA, B_CYAN, B_WHITE, B_CRIMSON =  map(lambda num: BEGIN + str(num) + "m", range(40, 49))
#   NORMAL = END


import subprocess
import threading
import os
import signal
import sys
import time
import traceback
from functools import partial
from sts.util.console import color
    msg(' OK\n')

printlock = threading.Lock()
def _prefix_thread(f, func):
  def run():
    while not f.closed:
      line = f.readline()
      if not line:
        break
      with printlock:
        print func(line)
    try:
      sys.stderr.write("Closing fd %d\n" % f)
      f.close() # idempotent, in case the f.closed broke out of the while loop
    except:
      # well, we tried
      pass
  t = threading.Thread(target=run)
  t.daemon = True
  t.start()
  return t


def color_normal(out_str, label):
  """Return normal colored text, see _prefix_thread"""
  return "%s%s %s%s\n" % (color.YELLOW, label, out_str.rstrip(), color.NORMAL)


def color_error(out_str, label):
  """Return error colored text, see _prefix_thread"""

# Path: sts/util/console.py
# class color(object):
#   GRAY, RED, GREEN, YELLOW, BLUE, MAGENTA, CYAN, WHITE, CRIMSON = map(lambda num : BEGIN + str(num) + "m", range(30, 39))
#   B_GRAY, B_RED, B_GREEN, B_YELLOW, B_BLUE, B_MAGENTA, B_CYAN, B_WHITE, B_CRIMSON =  map(lambda num: BEGIN + str(num) + "m", range(40, 49))
#   NORMAL = END


# Path: sts/util/procutils.py
import subprocess
import threading
import os
import signal
import sys
import time
import traceback
from functools import partial
from sts.util.console import color

    msg(' OK\n')

printlock = threading.Lock()
def _prefix_thread(f, func):
  def run():
    while not f.closed:
      line = f.readline()
      if not line:
        break
      with printlock:
        print func(line)
    try:
      sys.stderr.write("Closing fd %d\n" % f)
      f.close() # idempotent, in case the f.closed broke out of the while loop
    except:
      # well, we tried
      pass
  t = threading.Thread(target=run)
  t.daemon = True
  t.start()
  return t


def color_normal(out_str, label):
  """Return normal colored text, see _prefix_thread"""
  return "%s%s %s%s\n" % (color.YELLOW, label, out_str.rstrip(), color.NORMAL)


def color_error(out_str, label):
  """Return error colored text, see _prefix_thread"""

  return "%s%s %s%s\n" % (color.B_RED + color.YELLOW, label, out_str.rstrip(),