def scanDirectoryThreader(self, path: str) -> None: if SearchEngine.First: SearchEngine.First = False prev_result = self.checkPreviousResults() if len(prev_result) != 0: from src.main.com.SearchEngine.IO.OutputGenerator import OutputGenerator OutputGenerator.printer(fileName=self.searchFileName, PreviouslyFoundMatches=prev_result) sys.exit(1) running = True if SearchEngine.searchFileName == "": raise noFileToSearchException if not os.path.exists(path): raise PathNotFoundException(path) threads = [] SearchEngine.threadingSet.add(threading.get_ident()) #print("Scanning path:{}".format(path)) try: for item in os.listdir(path): pathToItem = os.path.join(path, item) from src.main.com.SearchEngine.Threading.ThreadGen import MyThread if os.path.isdir(pathToItem): threads.append(MyThread(pathToItem)) # dirs.append(pathToItem) if item.split('.')[0] == SearchEngine.searchFileName: from src.main.com.SearchEngine.IO.OutputGenerator import OutputGenerator #print("found at location:{}".format(pathToItem)) OutputGenerator.printer(FoundAtLocation=pathToItem) SearchEngine.result_locations.add(pathToItem) if not SearchEngine.isFound: SearchEngine.isFound = True self.lock.acquire() self.incrementFilesScanned(len(os.listdir(path)) - len(threads)) self.lock.release() except PermissionError: # localTime=time.localtime() myLogger("PermissionError opening " + path, Level.WARNING) for t in threads: t.start() for t in threads: t.join() running = False
def __init__(self, path): self.message = "Path not found:{}".format(path) myLogger(self.message, Level.ERROR)
def __str__(self): myLogger(self.message, Level.ERROR) return self.message
def __init__(self, level: str): self.message = "invalid level:{}\tUse myLogger.Level enum to set valid level".format( level) myLogger(self.message, Level.ERROR)
def __init__(self): self.message = "Try to Set File to Search using SearchEngine.setFileName(nameFile)" myLogger(self.message, Level.ERROR)
def __init__(self, fileName): self.message = "File Not found:{}".format(fileName) myLogger(self.message, Level.ERROR)