def run(self): if os.path.isfile(self.mNewer) or os.path.isfile(self.mOlder): self.singleAction(self.mTarget, self.mOlder, self.mNewer) elif os.path.isdir(self.mNewer): self.handleDirectory(self.mNewer) elif os.path.isdir(self.mOlder): self.handleDirectory(self.mOlder) elif self.mNewer.endswith("*"): self.handleRegex(self.mNewer) elif self.mOlder.endswith("*"): self.handleRegex(self.mOlder) else: print Paint.red(" Can not handle: %s" % self.mTarget)
def showDetail(item): if item == None: return if item.detail != None: if item.code == 0: print Paint.green(item.detail.replace("\t", "")) else: print Paint.red(item.detail.replace("\t", "")) if item.solution != None: print Paint.green(item.solution.replace("\t", ""))
def upgrade(self): """ Prepare precondition of upgrade """ # Remove last_bosp and bosp Utils.run(["rm", "-rf", OPTIONS.olderRoot], stdout=subprocess.PIPE).communicate() Utils.run(["rm", "-rf", OPTIONS.newerRoot], stdout=subprocess.PIPE).communicate() lastBoardZip = os.path.join(Config.PRJ_ROOT, "board/last_board.zip") boardZip = os.path.join(Config.PRJ_ROOT, "board/board.zip") if os.path.exists(lastBoardZip) and os.path.exists(boardZip): # Phase 1: prepare LAST_BOSP from last_board.zip Utils.decode(lastBoardZip, OPTIONS.olderRoot) # Phase 2: prepare BOSP from board.zip Utils.decode(boardZip, OPTIONS.newerRoot) # Phase 3: prepare patch XML ChangeList(OPTIONS.olderRoot, OPTIONS.newerRoot, OPTIONS.patchXml).make(force=True) else: if OPTIONS.commit1 is not None: self.baseDevice.setLastHead(OPTIONS.commit1) # Phase 1: get last and origin head from base device (lastHead, origHead) = self.baseDevice.getLastAndOrigHead() if lastHead == origHead: Log.w( TAG, Paint.red( "Nothing to upgrade. Did you forget to sync the %s ?" % OPTIONS.baseName)) Log.w( TAG, Paint.red( "In the root directory, try the following command to sync:" )) Log.w(TAG, Paint.red(" $ repo sync devices/%s" % OPTIONS.baseName)) # Phase 2: porting from last to origin head OPTIONS.commit1 = lastHead[0:7] OPTIONS.commit2 = origHead[0:7] self.porting()
def singleMerge(target, older, newer): """ Incorporate changes from older to newer into target """ # Find out the actual target loosely target = ReviseExecutor.TARGET_FINDER.find(target, loosely=True) execute = " MERGE " + target if not os.path.exists(target) : Error.fileNotFound(target) return "%s %s" % (Paint.red(" [FAIL]"), execute) action = Format.REMOVE_LINE | Format.ACCESS_TO_NAME | Format.RESID_TO_NAME formatTarget = Format(AutoPatch.TARGET_ROOT, target).do(action) formatOlder = Format(AutoPatch.OLDER_ROOT, older).do(action) formatNewer = Format(AutoPatch.NEWER_ROOT, newer).do(action) DiffPatch(target, older, newer).run() # Would not change res name back action = Format.REMOVE_LINE | Format.ACCESS_TO_NAME formatTarget.undo(action) formatOlder.undo(action) formatNewer.undo(action) conflictNum = Rejector(target).getConflictNum() if conflictNum > 0 : Error.conflict(conflictNum, target) return "%s %s" % (Paint.yellow(" [CFLT]"), execute) else: return "%s %s" % (Paint.green(" [PASS]"), execute)
def singleReplaceOrAdd(target, source): """ Add a file from source to target. Replace the target if exist. """ # Find out the actual target target = ReviseExecutor.TARGET_FINDER.find(target) if os.path.exists(target): execute = "REPLACE " + target else: execute = " ADD " + target ReviseExecutor.createIfNotExist(os.path.dirname(target)) if not os.path.exists(source): Error.fileNotFound(source) return "%s %s" % (Paint.red(" [FAIL]"), execute) # Only format access method and res id action = Format.ACCESS_TO_NAME | Format.RESID_TO_NAME formatSource = Format(AutoPatch.NEWER_ROOT, source).do(action) formatTarget = Format(AutoPatch.TARGET_ROOT, target).do(action) shutil.copy(source, target) # Would not change res name back action = Format.ACCESS_TO_NAME formatSource.undo(action) formatTarget.undo(action) return "%s %s" % (Paint.green(" [PASS]"), execute)
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()) utils.SLog.ok("\n>>>> Fix reject %s %s in %s: " % (mEntry.getType(), mEntry.getName(), self.rejSmali.getPath())) self.replaceEntryToBosp(mEntry) for entry in canReplaceEntry: if entry != mEntry: self.replaceEntryToBosp(entry) if len(canNotReplaceEntry) > 0: self.mCanNotReplaceEntry.extend(canNotReplaceEntry) if utils.has(canNotReplaceEntry, mEntry): print " %s %s" % (Paint.red("[FAIL]"), mEntry.getName()) utils.SLog.fail(" %s" % target) #utils.SLog.fail(" CONFLICTS: %s %s in %s" % (mEntry.getType(), mEntry.getName(), self.getRealTargetPath(self.mTSLib.getSmali(mEntry.getClassName())))) #utils.SLog.fail(" Can not be replaced by bosp, because of the follows:") for entry in canNotReplaceEntry: #utils.SLog.fail(" %s %s in %s" % (entry.getType(), entry.getName(), self.getRealTargetPath(self.mTSLib.getSmali(entry.getClassName())))) pass
def showStatistic(): for key in Error.FILENOTFOUND_STATISTIC.keys(): print "%3d files not found in %s" % ( Error.FILENOTFOUND_STATISTIC[key], key) if Error.TOTAL_FILENOTFOUND > 0: print Paint.bold( "%3d files not found totally, they might be removed or moved to other place by vendor?" % Error.TOTAL_FILENOTFOUND) print " " for key in Error.CONFLICT_STATISTIC.keys(): print "%3d conflicts in %s " % (Error.CONFLICT_STATISTIC[key], key) if Error.TOTAL_CONFLICTS > 0: print Paint.bold( "%3d conflicts in %d files, go through the reject files in 'autopatch/reject' to find them out" % (Error.TOTAL_CONFLICTS, Error.CONFLICT_FILE_NUM)) print Paint.red( "\n Ask for advice? Please type 'coron help CONFLICTS_HAPPENED' \n" )
def doAction(self, action): action = " ".join(action) print Paint.blue(">>> %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: cmd = "make %s" % action status = Shell.run(cmd) help.show(status, action) if status == 0: print Paint.blue("<<< %s succeed" % action) return True else: print Paint.red("<<< %s failed" % action) return False
def singleDelete(target): """ delete the target """ # Find out the actual target target = ReviseExecutor.TARGET_FINDER.find(target) execute = " DELETE " + target if os.path.exists(target): os.remove(target) return "%s %s" % (Paint.green(" [PASS]"), execute) return "%s %s" % (Paint.red(" [FAIL]"), execute)
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) return True else: print Paint.red("<<< phase %s failed" % action) return False
def conclude(): print Paint.red(" ____________________________________________________________________________________") print " " print Paint.red(" Go through 'autopatch/still-reject' to find out the rest of conflicts after autofix:") print " " if len(SLog.FAILED_LIST) > 0: for failed in set(SLog.FAILED_LIST): print Paint.red(failed) #Log.i(SLog.TAG, SLog.ADVICE) else: #Log.i(SLog.TAG, SLog.SUCCESS) pass