Пример #1
0
    def __init__(self, owner=None):
        super(Widget, self).__init__(owner)

        # make up a doc
        self.t = DirectoryScanner()
        if Platform.isMac:
            self.t.addPathsForScanning(['/Applications'])
        else:
            self.t.addPathsForScanning(['C:\\Program Files'])

        self.p = PersistentScanningState("demo.sqlite", echo_sql=False)

        self.initialScan()
        self.mergeScan()

        print "Info Is:", self.p.scanInfo()

        self.mapper = MergeScanMapper(self.p)

        self.ui = Ui_CustomTreeWidget()
        self.ui.setupUi(self)
        self.ui.treeView.setModel(
            MergeScanTreeModel(self.p, self.mapper, self.p.roots(), self))
        self.ui.treeView.expandToDepth(1)

        model = self.ui.treeView.model()
        header = self.ui.treeView.header()
        header.setResizeMode(MergeScanTreeModel.COL_CHECKED,
                             QHeaderView.ResizeToContents)
        header.setResizeMode(MergeScanTreeModel.COL_PERMISSIONS,
                             QHeaderView.ResizeToContents)

        self.ui.treeView.setAttribute(Qt.WA_MacShowFocusRect, False)
Пример #2
0
 def beginChangesScan(self, doc_name):
     """
     Find the selected item, and use the directories inside to perform a scan, the merge the results of that
     with the existing document - forming a set of objects that have been added/changed/removed
     """
     # now fetch the data model for that one to get the paths that need to be scanned
     self.storage = PersistentScanningState(
         DocumentStorage.documentFullPath(doc_name))
     #return self.__beginChangesScanWithDocument()
     self.__beginChangesScanWithDocument()
Пример #3
0
    def initializePage(self):
        name_of_file = self.wizard().documentName()
        self.__refreshResultsUsingDocument(
            PersistentScanningState(
                DocumentStorage.documentFullPath(name_of_file)))

        self.wizard().removePage(WizardPage.CREATE_NEW)
        self.wizard().removePage(WizardPage.FIRST_SCAN_PROGRESS)
        self.wizard().removePage(WizardPage.SECOND_SCAN_PROGRESS)
        self.wizard().removePage(WizardPage.SCANNING_COMPLETE_INSTALL_NOW)

        self.wizard().reinsertCreateScanPage()
    def initializePage(self):
        model = QStandardItemModel()

        # using a document model, we can obtain all the documents to list inside this view...
        all_docs = DocumentStorage.documents()
        for doc_filename in all_docs:
            # find out the last scan date, number of files, etc
            document = PersistentScanningState(doc_filename)
            logger.debug("found info: {0}".format(document.info))
            creation_date_str = str(document.info.date_created)
            last_date = str(document.info.date_last_scanned)
            num_scanned = "{0:,}".format(document.info.files_scanned)
            num_merged = "{0:,}".format(document.info.files_merged)
            is_merged = document.info.merge_complete
            if not is_merged:
                last_date_str = ""
            else:
                last_date_str = last_date

            doc = os.path.split(doc_filename)[1][:-len('.sqlite')]
            items = [
                QStandardItem(doc),
                QStandardItem(str(num_scanned)),
                QStandardItem(creation_date_str),
                QStandardItem(str(num_merged)),
                QStandardItem(last_date_str),
            ]

            items[1].setData(Qt.AlignRight, Qt.TextAlignmentRole)
            items[3].setData(Qt.AlignRight, Qt.TextAlignmentRole)

            model.invisibleRootItem().appendRow(items)

        self.ui.treeView.setModel(model)

        header = self.ui.treeView.header()

        model.setHeaderData(0, Qt.Horizontal, "Name")
        model.setHeaderData(1, Qt.Horizontal, "# First Scan")
        model.setHeaderData(2, Qt.Horizontal, "Date Created")
        model.setHeaderData(3, Qt.Horizontal, "# Second Scan")
        model.setHeaderData(4, Qt.Horizontal, "Date Scanned")

        header.setResizeMode(0, QHeaderView.ResizeToContents)
        header.setResizeMode(1, QHeaderView.ResizeToContents)
        header.setResizeMode(2, QHeaderView.ResizeToContents)
        header.setResizeMode(3, QHeaderView.ResizeToContents)
        header.setResizeMode(4, QHeaderView.ResizeToContents)

        self.ui.treeView.selectionModel().currentRowChanged.connect(
            self.__onSelectionChanged)
 def isComplete(self):
     done = self.document_name is not None
     if done:
         # if the second scan completed OK, we can skip the second scan
         fullpath_doc_name = DocumentStorage.documentFullPath(
             self.document_name)
         logger.debug("going with full path of document: {0}".format(
             fullpath_doc_name))
         persist_doc = PersistentScanningState(fullpath_doc_name)
         self.setField("secondScanComplete",
                       persist_doc.info.merge_complete)
         self.wizard().setDocumentName(self.document_name)
         self.wizard().setWindowFilePath(fullpath_doc_name)
     return done
Пример #6
0
	def setUp(self):
		self.t = DirectoryScanner()
		self.builder = DirectoryTreeBuilder()

		# construct a known directory structure, suitable for testing - it includes files, directories, ACL's, etc

		self.contents_path = self.builder.make_dir("BB/TextEdit.app/Contents", 0755)
		self.builder.make_dir("BB/TextEdit.app/Contents/Resources", 0755)
		self.builder.make_dir("BB/TextEdit.app/Contents/Frameworks", 0755)
		self.builder.create_file("BB/TextEdit.app/Contents/Stupid.txt", 0755, 425)

		# produce a single scan of the fake file-system entries
		self.p = PersistentScanningState("tree-tests.sqlite")

		self.t.addPathsForScanning([self.builder.rootDir])
		self.initialScan()
		self.mergeScan()
Пример #7
0
    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
Пример #8
0
    def setUp(self):
        self.t = DirectoryScanner()
        self.builder = DirectoryTreeBuilder()

        # construct a known directory structure, suitable for testing - it includes files, directories, ACL's, etc

        self.contents_path = self.builder.make_dir("AA/TextEdit.app/Contents",
                                                   0755)
        self.builder.make_dir("AA/TextEdit.app/Contents/Resources", 0755)
        self.builder.make_dir("AA/TextEdit.app/Contents/Frameworks", 0755)

        self.dbName = "find-diffs.sqlite"
        self.removeDB()

        # produce a single scan of the fake file-system entries
        self.p = PersistentScanningState(self.dbName)

        self.t.addPathsForScanning([self.builder.rootDir])
        self.initialScan()
Пример #9
0
    def initializePage(self):
        """
		Find and load the persistent document, create the export UI and insert it into the 'container'.  This
		method assumes that the wizard has a documentName set.
		"""

        self.container = QWidget(self)

        if self.plugin is not None:
            self.plugin.ui.setParent(None)
            self.gridLayout.removeWidget(self.plugin.ui)
            self.plugin.ui = None
            self.plugin = None

        name_of_file = self.wizard().documentName()
        document = PersistentScanningState(
            DocumentStorage.documentFullPath(name_of_file))

        self.plugin = self.__createPluginNamed(
            self.field("exportType").toString())
        ui = self.__createExportUI(document, self.container)
        self.gridLayout.addWidget(ui)

        self.changed()
Пример #10
0
 def setUp(self):
     self.p = PersistentScanningState("test.sqlite", echo_sql=False)