# 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

    def __init__(self):
        self.createXMLIfNotExist()
        StateMachine.__init__(self, Workflow(CoronStateMachine.XML))

    def createXMLIfNotExist(self):
        if os.path.exists(CoronStateMachine.XML): return

        source = os.path.join(os.path.dirname(os.path.realpath(__file__)), "workflow.xml")
        shutil.copy(source, CoronStateMachine.XML)

    def doAction(self, action):
        print "\n"
        print Paint.blue(">>> In phase %s" % action)

        status = 0

        phase = self.workflow.getPhase(action)
        if phase != None:
            for cmd in phase.cmds:
                status = Shell.run(cmd)
                if status != 0: break
        else:
            print Paint.red('Error: Unknown command "%s"' % action)
            # Set status code to be 255, show the tale
            status = 255

        HelpPresenter.showdetail(status, action)

        if status == 0:

# 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


    def __init__(self):
        self.createXMLIfNotExist()
        StateMachine.__init__(self, Workflow(CoronStateMachine.XML))

    def createXMLIfNotExist(self):
        if os.path.exists(CoronStateMachine.XML): return

        source = os.path.join(os.path.dirname(os.path.realpath(__file__)), "workflow.xml")
        shutil.copy(source, CoronStateMachine.XML)

    def doAction(self, action):
        print "\n"
        print Paint.blue(">>> In phase %s" % action)

        status = 0

        phase = self.workflow.getPhase(action)
        if phase != None:
            for cmd in phase.cmds:
                status = Shell.run(cmd)
                if status != 0: break
        else:
            print Paint.red('Error: Unknown command "%s"' % action)
            # Set status code to be 255, show the tale
            status = 255

        HelpPresenter.showdetail(status, action)

        if status == 0:

            print Paint.blue("<<< phase %s succeed" % action)