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 showUserInputHint(self): """ Show user input hint """ for i in range(0, len(self.commitIDs)): commitID = self.commitIDs[i] comment = self.comments[i] print " %s %s" % (Paint.bold(commitID), comment) deviceName = self.baseDevice.name() oneCommit = Paint.bold(self.commitIDs[0]) twoCommits = "%s %s" % (Paint.bold( self.commitIDs[-1]), Paint.bold(self.commitIDs[0])) print " ________________________________________________________________________________________" print " " print " Each 7 bits SHA1 code identify a commit on %s," % Paint.blue( deviceName), print " You could input: " print " - Only one single commit, like: %s" % oneCommit print " will porting changes between the selected and the latest from %s to your device" % Paint.blue( deviceName) print " - Two commits as a range, like: %s" % twoCommits print " will porting changes between the two selected from %s to your device" % Paint.blue( deviceName) print " ________________________________________________________________________________________" print " "
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 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 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 usage(): help_model = __create() print " " print Paint.bold(help_model.get("help_usage").detail.strip()) print " " print help_model.get("help_license").detail.strip() print " " print help_model.get("help_cmds").detail.strip() # help print Paint.bold("* flyme help [ACTION]") print " " print " ", help_model.get("help").detail.strip() print " " # action print Paint.bold("* flyme [ACTION]") print " " actions = ("config", "newproject", "patchall", "fullota", "upgrade", "porting", "clean", "cleanall") for action in actions: print Paint.bold(action).rjust(20), "\t", help_model.get( action).detail.strip() print " " # fire #print Paint.bold("* flyme fire") #print " ", help_model.get("fire").detail.strip() print ""
def report(): if len(Error.FAILED_LIST) == 0: print Paint.green( "\n Ask for advice? Please type 'coron help NO_CONFLICT' \n") else: Error.createAllRejects() Error.printDivide() for failed in Error.FAILED_LIST: print failed Error.printDivide() Error.showStatistic()
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 show(item, attrib=None): """ Show the help item. """ if item == None: return if attrib == "solution": if item.solution != None: print item.solution.replace("\t", "") elif attrib == "detail": if item.detail != None: print item.detail.replace("\t", "") else: print Paint.bold("%s\t%s\n" % (item.code, item.name)) Help.showDetail(item) print " "
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 show(key, category=None): """ Show the help item :param key: name or code of the help item :param category: help category, like config, newproject """ item = __get_item(key, category) if item is None: return if item.detail is not None: print "%s: %s" % (Paint.bold(item.name), item.detail.replace("\t", "").strip()) if item.solution is not None: print Paint.green(item.solution.replace("\t", "").lstrip()) print ""
def showall(): helpEntry = HelpFactory.createHelp() for code in sorted(helpEntry.CODE_TO_NAME.keys()): if code == 255: continue item = helpEntry.get(code) if item.detail != None: print "%s(%d)\n%s" % (Paint.bold(item.name), item.code, item.detail.replace("\t", "").strip()) print " "
def autocom(vendorDir, aospDir, bospDir, mergedDir, outdir, comModuleList): sReplace = Replace.Replace(vendorDir, aospDir, bospDir, mergedDir) for module in comModuleList: print Paint.bold(" Complete missed method in %s") % module needComleteDir = '%s/%s' % (mergedDir, module) sDict = utils.getSmaliDict(needComleteDir) for clsName in sDict.keys(): mSmali = sReplace.mMSLib.getSmali(clsName) if mSmali is None: utils.SLog.d("can not get class: %s" % clsName) continue (canReplaceEntryList, canNotReplaceEntryList) = sReplace.preReplaceCheck(mSmali) for entry in canReplaceEntryList: sReplace.replaceEntryInFile(entry, SAutoCom.getAutocomPartPath(sReplace, entry, outdir)) for entry in canNotReplaceEntryList: sReplace.appendBlankEntry(entry, SAutoCom.getAutocomPartPath(sReplace, entry, outdir))
def readUserInput(self): """ Read user input """ self.showUserInputHint() userInput = raw_input( Paint.bold(">>> Input the 7 bits SHA1 commit ID (q to exit): ")) if userInput in ("q", "Q"): sys.exit() commits = userInput.split() size = len(commits) commit1 = commit2 = None if size > 0: commit1 = commits[0] if size > 1: commit2 = commits[1] return (commit1, commit2)
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 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
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 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 coronUsage(): helpEntry = HelpFactory.createHelp() print Paint.bold("Coron - an open source project for Android ROM porting.") print "Copyright 2014 Baidu Cloud OS <rom.baidu.com> " print "Apache License 2.0 (http://www.apache.org/licenses/LICENSE-2.0) " print " " print "COMMANDs are: " # Coron help print Paint.bold("* coron help [NAME]") print " ", helpEntry.get("help").detail.strip() print " " # Coron action print Paint.bold("* coron ACTION") print " Run the action separately." print " " print Paint.bold("ACTION").rjust(20), "\t", Paint.bold("Description") ACTIONS = ("config", "newproject", "patchall", "autofix", "fullota", "upgrade", "clean", "cleanall") for action in ACTIONS: item = helpEntry.get(action) print Paint.bold(action).rjust(20), "\t", item.detail.strip() print " " # Coron fire print Paint.bold("* coron fire") print " ", helpEntry.get("fire").detail.strip() print " "
def usage(): help_model = __create() print Paint.bold("An open source project for Android ROM porting.") print "Apache License 2.0 (http://www.apache.org/licenses/LICENSE-2.0) " print " " print "COMMANDs are: " # help print Paint.bold("* flyme help [NAME]") print " ", help_model.get("help").detail.strip() print " " # action print Paint.bold("* flyme ACTION") print " Run the action separately." print " " print Paint.bold("ACTION").rjust(20), "\t", Paint.bold("Description") actions = ("config", "newproject", "patchall", "fullota", "upgrade", "porting", "clean", "cleanall") for action in actions: print Paint.bold(action).rjust(20), "\t", help_model.get( action).detail.strip() print " " # fire print Paint.bold("* flyme fire") print " ", help_model.get("fire").detail.strip() print ""