def beginInitialScan(self, scan_paths, doc_name=None): # construct an initial scan, based on the selected items within the model... # workflow: scan to produce a persistent model, monitor/rescan, re-integrate changes into initial model (changed, deleted, added etc) scanner = DirectoryScanner() scanner.addPathsForScanning(scan_paths) # we want to store the results too - so build a storage device, its all being run via iterables # so its easy to chain these together. doc_path = DocumentStorage.getDocumentPathForName(doc_name, scan_paths) self.storage = PersistentScanningState(doc_path) self.storage.storePathsBeingScanned(scanner.paths_to_scan) self.storage.scanningStateChanged.connect( lambda x: self.scanStateChanged.emit(x)) self.isScanning = True self.scanStarted.emit(doc_path) # this one line performs a recursive disk scan on multiple folders, obtains file/dir info, persists # this to the DB and then finally exposes [idx, f] so the UI can display progress. Long live iterables... (and C++, you can die in a fire) total_found = 0 for idx, f in enumerate(self.storage.storeFilesystemSnapshot(scanner)): total_found = idx if not (idx % 100): self.scanProgress.emit(idx, f.abs_path) if not self.isScanning: break registryScanner = RegistryScanner() totalRegistry = 0 for idx, r in enumerate( self.storage.storeRegistryEntrySnapshot(registryScanner)): totalRegistry = idx if not (idx % 100): self.scanProgress.emit(idx, r.key_name) if not self.isScanning: break self.stopScanning() # complete the scan... self.scanFinished.emit(total_found) self.storage = None
def beginInitialScan(self, scan_paths, doc_name = None): # construct an initial scan, based on the selected items within the model... # workflow: scan to produce a persistent model, monitor/rescan, re-integrate changes into initial model (changed, deleted, added etc) scanner = DirectoryScanner() scanner.addPathsForScanning(scan_paths) # we want to store the results too - so build a storage device, its all being run via iterables # so its easy to chain these together. doc_path = DocumentStorage.getDocumentPathForName(doc_name, scan_paths) self.storage = PersistentScanningState(doc_path) self.storage.storePathsBeingScanned(scanner.paths_to_scan) self.storage.scanningStateChanged.connect(lambda x: self.scanStateChanged.emit(x)) self.isScanning = True self.scanStarted.emit(doc_path) # this one line performs a recursive disk scan on multiple folders, obtains file/dir info, persists # this to the DB and then finally exposes [idx, f] so the UI can display progress. Long live iterables... (and C++, you can die in a fire) total_found = 0 for idx, f in enumerate(self.storage.storeFilesystemSnapshot(scanner)): total_found = idx if not (idx % 100): self.scanProgress.emit(idx, f.abs_path) if not self.isScanning: break registryScanner = RegistryScanner() totalRegistry = 0 for idx ,r in enumerate(self.storage.storeRegistryEntrySnapshot(registryScanner)): totalRegistry = idx if not (idx % 100): self.scanProgress.emit(idx, r.key_name) if not self.isScanning: break self.stopScanning() # complete the scan... self.scanFinished.emit(total_found) self.storage = None
def test_document_gives_specific_filename(self): new_name = DocumentStorage.getDocumentPathForName("something", None) self.assertNotEqual(None, new_name) self.assertTrue(new_name.endswith("something.sqlite"))
def test_creating_name_by_using_scanpaths(self): name = DocumentStorage.getDocumentPathForName(None, ['/Something']) base, filename = os.path.split(name) self.assertTrue(filename.startswith("Something -")) self.assertTrue(filename.endswith(".sqlite"))