def LocateFileInParentTree(log: Log, startDirectory: str, findFilename: str) -> str: try: res = IOUtil.TryFindFileInCurrentOrParentDir( startDirectory, findFilename) if res is not None: return res except (Exception) as ex: log.DoPrintError(str(ex)) raise Exception( "Could not find a '{0}' file in the parent tree of '{1}'".format( findFilename, startDirectory))
def RunInAnotherThread(packageQueue: Any, cancellationToken: SimpleCancellationToken, mainLog: Log, toolConfig: ToolConfig, customPackageFileFilter: Optional[CustomPackageFileFilter], clangFormatConfiguration: ClangFormatConfiguration, clangExeInfo: ClangExeInfo, repairEnabled: bool) -> Tuple[int,int]: threadId = threading.get_ident() mainLog.LogPrintVerbose(4, "Starting thread {0}".format(threadId)) examinedCount = 0 processedCount = 0 keepWorking = True package = None # type: Optional[Package] try: while keepWorking and not cancellationToken.IsCancelled(): try: # Since the queue is preloaded this is ok package = packageQueue.get_nowait() except: package = None if package is None: keepWorking = False else: if mainLog.Verbosity >= 4: mainLog.LogPrint("- clang-format on package '{0}' on thread {1}".format(package.Name, threadId)) else: mainLog.LogPrint("- clang-format on package '{0}'".format(package.Name)) captureLog = CaptureLog(mainLog.Title, mainLog.Verbosity) try: filteredFiles = None if customPackageFileFilter is not None: filteredFiles = customPackageFileFilter.TryLocateFilePatternInPackage(captureLog, package, clangFormatConfiguration.FileExtensions) if customPackageFileFilter is None or filteredFiles is not None: processedCount += 1 _RunClangFormat(captureLog, toolConfig, clangFormatConfiguration, clangExeInfo, package, filteredFiles, repairEnabled) examinedCount += 1 finally: try: if len(captureLog.Captured) > 0: capturedLog = "Package: '{0}' result:\n{1}".format(package.Name, "\n".join(captureLog.Captured)) mainLog.DoPrint(capturedLog) except: pass except Exception as ex: cancellationToken.Cancel() mainLog.DoPrintError("Cancelling tasks due to exception: {0}") raise finally: mainLog.LogPrintVerbose(4, "Ending thread {0}".format(threadId)) return (examinedCount, processedCount)