# Path: util/Log.py
# class Log(object):
#     """
#     Log class
#     """
#     class __impl(object):
#         """ Implementation of singleton interface"""
#         def __init__(self):
#             """
#             """
#             self.levMap = {"ERROR":(0, "\033[31m%s%s\033[0m"), "WARNING":(1, "\033[33m%s%s\033[0m"), \
#                             "INFO":(2, "\033[34m%s%s\033[0m"), "MSG":(3, "\033[32m%s%s\033[0m"), \
#                             "UNKNOW":(4, "\033[31m%s%s\033[0m")}
#             self.config_level = 5
# 
#         def setLogLevel(self, lev):
#             """
#             Description : set log file level.The log message lower than this level will not be printed.
#             Args : lev : log level will be set.Value is [0-5],0 will not print any log message, 5 will print all log message
#             Return : NULL 
#             """
#             self.config_level = lev
# 
#         def LevPrint(self, level, msg, prefix=True):
#             """
#             Description :  print log message which has higher level than config level
#             Args: 
#                 level : ["ERROR", "WARNING", "INFO", "MSG", "UNKNOW"]
#                 msg : string, log message
#                 prefix : True , print time information
#                          False , don't print time information
#             Return : None
#             """
#             if level in self.levMap and self.levMap[level][0] > self.config_level:
#                 return 
# 
#             now = ""
#             pmsg = ""
#             if prefix:
#                 now = "[" + time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time())) \
#                     + " " + str(threading.current_thread().ident) + "] "
#             if (level in self.levMap):
#                     pmsg = self.levMap[level][1] % (now, msg)
#             else:
#                     pmsg = "UNKNOW log level(%s)" % level 
#                     pmsg += self.levMap["UNKNOW"][1] % (now, msg)
#                 
#             print(pmsg)
#             sys.stdout.flush()
# 
#     
#     # class Log
#     __instance = None
#     def __init__(self):
#         """ Create singleton instance """
#         # Check whether we already have an instance
#         if Log.__instance is None:
#             # Create and remember instance
#             Log.__instance = Log.__impl()
# 
#         # Store instance reference as the only member in the handle
#         self.__dict__['_Log__instance'] = Log.__instance
# 
#     def __getattr__(self, attr):
#         """ Delegate access to implementation """
#         return getattr(self.__instance, attr)
# 
#     def __setattr__(self, attr, value):
#         """ Delegate access to implementation """
#         return setattr(self.__instance, attr, value)


import os
import sys
import getopt
from util import Log
sys.path.insert(0, broc_dir)

def Help(bin_name, subcommand=None):
    """
    Show help imformation
    Args:
        bin_name : executable file name
        subcommand : executable file subcommand. In broc, it's in [""]
    Return:
        0 : success
    """
    if subcommand is None:
        Log.colorprint("DEFAULT", "Usage: %s <subcommand> [option] [args]" % (bin_name), False)
        Log.colorprint("DEFAULT",
                "Type %s help <subcommand> for help on a specific subcommand" % (bin_name),
                False)
        Log.colorprint("DEFAULT", "Available subcommands:", False)
        Log.colorprint("DEFAULT", "    build      : Build the specified targets", False)
        Log.colorprint("DEFAULT", "    test       : Build and runs the specified targets",
                False)
        Log.colorprint("DEFAULT", "    show-deps  : Print the dependency graph", False)
        Log.colorprint("DEFAULT", "    clean      : Remove output files", False)
        Log.colorprint("DEFAULT", "    scratch    : Create a BROC template", False)
        Log.colorprint("DEFAULT", "    version    : Display the version", False)
        Log.colorprint("DEFAULT", "    config     : Display broc's config items", False)
        Log.colorprint("DEFAULT", "    help       : Print the help commands", False)
        return 0

    if subcommand == "build" or subcommand == "test":
        if subcommand == "build":

# Path: util/Log.py
# class Log(object):
#     """
#     Log class
#     """
#     class __impl(object):
#         """ Implementation of singleton interface"""
#         def __init__(self):
#             """
#             """
#             self.levMap = {"ERROR":(0, "\033[31m%s%s\033[0m"), "WARNING":(1, "\033[33m%s%s\033[0m"), \
#                             "INFO":(2, "\033[34m%s%s\033[0m"), "MSG":(3, "\033[32m%s%s\033[0m"), \
#                             "UNKNOW":(4, "\033[31m%s%s\033[0m")}
#             self.config_level = 5
# 
#         def setLogLevel(self, lev):
#             """
#             Description : set log file level.The log message lower than this level will not be printed.
#             Args : lev : log level will be set.Value is [0-5],0 will not print any log message, 5 will print all log message
#             Return : NULL 
#             """
#             self.config_level = lev
# 
#         def LevPrint(self, level, msg, prefix=True):
#             """
#             Description :  print log message which has higher level than config level
#             Args: 
#                 level : ["ERROR", "WARNING", "INFO", "MSG", "UNKNOW"]
#                 msg : string, log message
#                 prefix : True , print time information
#                          False , don't print time information
#             Return : None
#             """
#             if level in self.levMap and self.levMap[level][0] > self.config_level:
#                 return 
# 
#             now = ""
#             pmsg = ""
#             if prefix:
#                 now = "[" + time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time())) \
#                     + " " + str(threading.current_thread().ident) + "] "
#             if (level in self.levMap):
#                     pmsg = self.levMap[level][1] % (now, msg)
#             else:
#                     pmsg = "UNKNOW log level(%s)" % level 
#                     pmsg += self.levMap["UNKNOW"][1] % (now, msg)
#                 
#             print(pmsg)
#             sys.stdout.flush()
# 
#     
#     # class Log
#     __instance = None
#     def __init__(self):
#         """ Create singleton instance """
#         # Check whether we already have an instance
#         if Log.__instance is None:
#             # Create and remember instance
#             Log.__instance = Log.__impl()
# 
#         # Store instance reference as the only member in the handle
#         self.__dict__['_Log__instance'] = Log.__instance
# 
#     def __getattr__(self, attr):
#         """ Delegate access to implementation """
#         return getattr(self.__instance, attr)
# 
#     def __setattr__(self, attr, value):
#         """ Delegate access to implementation """
#         return setattr(self.__instance, attr, value)


# Path: client/Options.py
import os
import sys
import getopt
from util import Log

sys.path.insert(0, broc_dir)

def Help(bin_name, subcommand=None):
    """
    Show help imformation
    Args:
        bin_name : executable file name
        subcommand : executable file subcommand. In broc, it's in [""]
    Return:
        0 : success
    """
    if subcommand is None:
        Log.colorprint("DEFAULT", "Usage: %s <subcommand> [option] [args]" % (bin_name), False)
        Log.colorprint("DEFAULT",
                "Type %s help <subcommand> for help on a specific subcommand" % (bin_name),
                False)
        Log.colorprint("DEFAULT", "Available subcommands:", False)
        Log.colorprint("DEFAULT", "    build      : Build the specified targets", False)
        Log.colorprint("DEFAULT", "    test       : Build and runs the specified targets",
                False)
        Log.colorprint("DEFAULT", "    show-deps  : Print the dependency graph", False)
        Log.colorprint("DEFAULT", "    clean      : Remove output files", False)
        Log.colorprint("DEFAULT", "    scratch    : Create a BROC template", False)
        Log.colorprint("DEFAULT", "    version    : Display the version", False)
        Log.colorprint("DEFAULT", "    config     : Display broc's config items", False)
        Log.colorprint("DEFAULT", "    help       : Print the help commands", False)
        return 0

    if subcommand == "build" or subcommand == "test":
        if subcommand == "build":

            Log.colorprint("DEFAULT", "build: Builds the specified targets", False)