# Path: formatters/log.py
# class Log:
# 
#     DEBUG = False
# 
#     @staticmethod
#     def d(tag, message):
#         if Log.DEBUG: print "D/%s: %s" %(tag, message)
# 
#     @staticmethod
#     def i(tag, message):
#         print "I/%s: %s" %(tag, message)
# 
#     @staticmethod
#     def w(tag, message):
#         print "W/%s: %s" %(tag, message)
# 
#     @staticmethod
#     def e(tag, message):
#         print "E/%s: %s" %(tag, message)
# 
# class Paint:
# 
#     @staticmethod
#     def bold(s):
#         return "%s[01m%s%s[0m" % (chr(27), s.rstrip(), chr(27))
# 
#     @staticmethod
#     def red(s):
#         return "%s[33;31m%s%s[0m" % (chr(27), s.rstrip(), chr(27))
# 
#     @staticmethod
#     def green(s):
#         return "%s[31;32m%s%s[0m" % (chr(27), s.rstrip(), chr(27))
# 
#     @staticmethod
#     def blue(s):
#         return "%s[34;01m%s%s[0m" % (chr(27), s.rstrip(), chr(27))
# 
#     @staticmethod
#     def yellow(s):
#         return "%s[31;33m%s%s[0m" % (chr(27), s.rstrip(), chr(27))


import os
import subprocess
import shutil
import re
    import xml.etree.cElementTree as ET
    import xml.etree.ElementTree as ET
from help import HelpPresenter
from formatters.log import Log, Paint
        output = None
        while True:
            buff = subp.stdout.readline().strip('\n')
            print buff
            if buff == '' and subp.poll() != None:
                break

            output = buff

        Log.d(TAG, "Shell.run() %s return %s" %(cmd, subp.returncode))
        status = Shell.parseHelpStatus(subp.returncode, "%s" %output)

        return status


    @staticmethod
    def parseHelpStatus(status, output):
        """ Parse the error number in `make` command output
        """

        # GNU make exits with a status of zero if all makefiles were successfully parsed and no targets that were built failed.
        # A status of one will be returned if the -q flag was used and make  determines that a target needs to be rebuilt.
        # A status of two will be returned if any errors were encountered.
        errRegex = re.compile("^make: .* Error (?P<errNo>(?!.*(ignored)).*)")
        match = errRegex.search(output)
        if match != None:
            Log.d(TAG, "Shell.parseHelpStatus() Target in GNU make")
            status = int(match.group("errNo"))

        Log.d(TAG, "Shell.parseHelpStatus() Output is %s" % output)

# Path: formatters/log.py
# class Log:
# 
#     DEBUG = False
# 
#     @staticmethod
#     def d(tag, message):
#         if Log.DEBUG: print "D/%s: %s" %(tag, message)
# 
#     @staticmethod
#     def i(tag, message):
#         print "I/%s: %s" %(tag, message)
# 
#     @staticmethod
#     def w(tag, message):
#         print "W/%s: %s" %(tag, message)
# 
#     @staticmethod
#     def e(tag, message):
#         print "E/%s: %s" %(tag, message)
# 
# class Paint:
# 
#     @staticmethod
#     def bold(s):
#         return "%s[01m%s%s[0m" % (chr(27), s.rstrip(), chr(27))
# 
#     @staticmethod
#     def red(s):
#         return "%s[33;31m%s%s[0m" % (chr(27), s.rstrip(), chr(27))
# 
#     @staticmethod
#     def green(s):
#         return "%s[31;32m%s%s[0m" % (chr(27), s.rstrip(), chr(27))
# 
#     @staticmethod
#     def blue(s):
#         return "%s[34;01m%s%s[0m" % (chr(27), s.rstrip(), chr(27))
# 
#     @staticmethod
#     def yellow(s):
#         return "%s[31;33m%s%s[0m" % (chr(27), s.rstrip(), chr(27))


# Path: workflow/workflow.py
import os
import subprocess
import shutil
import re
    import xml.etree.cElementTree as ET
    import xml.etree.ElementTree as ET
from help import HelpPresenter
from formatters.log import Log, Paint

        output = None
        while True:
            buff = subp.stdout.readline().strip('\n')
            print buff
            if buff == '' and subp.poll() != None:
                break

            output = buff

        Log.d(TAG, "Shell.run() %s return %s" %(cmd, subp.returncode))
        status = Shell.parseHelpStatus(subp.returncode, "%s" %output)

        return status


    @staticmethod
    def parseHelpStatus(status, output):
        """ Parse the error number in `make` command output
        """

        # GNU make exits with a status of zero if all makefiles were successfully parsed and no targets that were built failed.
        # A status of one will be returned if the -q flag was used and make  determines that a target needs to be rebuilt.
        # A status of two will be returned if any errors were encountered.
        errRegex = re.compile("^make: .* Error (?P<errNo>(?!.*(ignored)).*)")
        match = errRegex.search(output)
        if match != None:
            Log.d(TAG, "Shell.parseHelpStatus() Target in GNU make")
            status = int(match.group("errNo"))

        Log.d(TAG, "Shell.parseHelpStatus() Output is %s" % output)

        Log.d(TAG, "Shell.parseHelpStatus() Status is %d" % status)