# Path: formatters/log.py
# 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 Smali
import utils
import re
import sys
import os
import SmaliEntry
import Replace
import SAutoCom
import tempfile
import LibUtils
from formatters.log import Paint
        if hasReject:
            self.rejSmali = Smali.Smali(self.rejSmali.getPath())
            self.rejSmali.out(self.getOutRejectFilePath())
            
    def getOutRejectFilePath(self):
        start = len(os.path.abspath(utils.REJECT))
        rejPath = self.rejSmali.getPath()
        return "%s/%s" % (utils.OUT_REJECT, rejPath[start:])
    
    def getRealTargetPath(self, tSmali):
        return "%s/smali/%s" % (utils.getJarNameFromPath(tSmali.getPath()), utils.getBaseSmaliPath(tSmali.getPath()))
        
    def replaceEntryToBosp(self, entry):
        if (entry.getFlag() & reject.FLAG_REPLACED_TO_BAIDU) == 0:
            self.mTSLib.replaceEntry(self.mBSLib, entry)
        
            if self.mRejSLib.getSmali(entry.getClassName()) is not None:
                self.rejSmali = self.mRejSLib.replaceEntry(self.mBSLib, entry, False, False, True)
            rejEntry = self.getRejectEntry(entry)
            if rejEntry is not None:
                rejEntry.setFlag(reject.FLAG_ENTRY_NORMAL)
            entry.addFlag(reject.FLAG_REPLACED_TO_BAIDU)
    
    def handleLightFix(self):
        target = os.path.relpath(self.rejSmali.getPath(), utils.REJECT)
        print "  "
        print "  %s %s" % (Paint.bold("FIX CONFLICTS IN"), target)
        for mEntry in self.mBSLib.getEntryList(self.getRejectEntryList()):
            (canReplaceEntry, canNotReplaceEntry) = self.mTSLib.getCanReplaceEntry(self.mBSLib, self.rejSmali.getClassName(), [mEntry], False)
            if utils.has(canReplaceEntry, mEntry):

# Path: formatters/log.py
# 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: smaliparser/reject.py
import Smali
import utils
import re
import sys
import os
import SmaliEntry
import Replace
import SAutoCom
import tempfile
import LibUtils
from formatters.log import Paint

        if hasReject:
            self.rejSmali = Smali.Smali(self.rejSmali.getPath())
            self.rejSmali.out(self.getOutRejectFilePath())
            
    def getOutRejectFilePath(self):
        start = len(os.path.abspath(utils.REJECT))
        rejPath = self.rejSmali.getPath()
        return "%s/%s" % (utils.OUT_REJECT, rejPath[start:])
    
    def getRealTargetPath(self, tSmali):
        return "%s/smali/%s" % (utils.getJarNameFromPath(tSmali.getPath()), utils.getBaseSmaliPath(tSmali.getPath()))
        
    def replaceEntryToBosp(self, entry):
        if (entry.getFlag() & reject.FLAG_REPLACED_TO_BAIDU) == 0:
            self.mTSLib.replaceEntry(self.mBSLib, entry)
        
            if self.mRejSLib.getSmali(entry.getClassName()) is not None:
                self.rejSmali = self.mRejSLib.replaceEntry(self.mBSLib, entry, False, False, True)
            rejEntry = self.getRejectEntry(entry)
            if rejEntry is not None:
                rejEntry.setFlag(reject.FLAG_ENTRY_NORMAL)
            entry.addFlag(reject.FLAG_REPLACED_TO_BAIDU)
    
    def handleLightFix(self):
        target = os.path.relpath(self.rejSmali.getPath(), utils.REJECT)
        print "  "
        print "  %s %s" % (Paint.bold("FIX CONFLICTS IN"), target)
        for mEntry in self.mBSLib.getEntryList(self.getRejectEntryList()):
            (canReplaceEntry, canNotReplaceEntry) = self.mTSLib.getCanReplaceEntry(self.mBSLib, self.rejSmali.getClassName(), [mEntry], False)
            if utils.has(canReplaceEntry, mEntry):

                print "  %s %s" % (Paint.green("[PASS]"), mEntry.getName())