from runThroughFiles import runThroughFiles_InDir_WithExtension_WithPredicate_WithAction __author__ = 'raV' workingDir = [ 'd:/Projekty/Market2/Market2_DEV/Core/', 'd:/Projekty/Market2/Market2_DEV/MarketBPL/', 'd:/Projekty/NowaCentrala_HEAD_DEV/NowaCentrala/Centrala/'] def dummyPredicateOnFileContent(args): return True class Static: totalCount = 0 def countLines(fileName, content): Static.totalCount += content.count('\n') runThroughFiles_InDir_WithExtension_WithPredicate_WithAction( workingDir, ['.cpp', '.h'], dummyPredicateOnFileContent, countLines) print("Total line count: %i" % Static.totalCount)
if actionGuid == "": print("ERRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR") fileName = filePathName[filePathName.rfind("/")] newRegistrationToWrite = ( """ void register""" + fileName + """Objects(Core::Registrations& regs) { \tregs.add(REGISTER_ACTION_CREATOR(""" + actionGuid + """, """ + creatorClassName + """)); } //--------------------------------------------------------------------------- """ ) fileContent = fileContent[: oldRegisterLineBegin - 1] + fileContent[oldRegisterLineEnd + 2 :] fileContent = fileContent[: actionMethodBegin - 1] + fileContent[actionMethodEnd + 1 :] fileContent += newRegistrationToWrite with open(filePathName, "w+") as fil: fil.write(fileContent) runThroughFiles_InDir_WithExtension_WithPredicate_WithAction( workingDir, [".cpp", ".h"], fileContainsOldRegisterMethod, fixRegisterMethod )
includeLine = getIncludeLines(fileContent, startPos) leftPart = fileContent[:includeLine[0]] rightPart = fileContent[includeLine[1] + 1:] newFileContent = leftPart + rightPart if startPos == -1 or includeLine[0] == -1 or includeLine[1] == -1: break with open(fileName, 'w+') as fil: fil.write(newFileContent) if isCompilationSuccessful(fileName): fileContent = newFileContent startPos = includeLine[0] else: startPos = includeLine[1] with open(fileName, 'w+') as fil: fil.write(fileContent) print('modified file: ' + fileName + ', result content:') print(fileContent) def dummyPredicateOnFileContent(data): return True runThroughFiles_InDir_WithExtension_WithPredicate_WithAction( workingDir, ['.cpp', '.h'], dummyPredicateOnFileContent, eraseUnnecessaryIncludesAndTryToCompile)