def openDBDoc(self, filepath, mode='a', position=0):
        """
        Open an existing hdf5 file and load it into the tree model.

        :Parameters:

        - `filepath`: full path of the database file we wish to open.
        - `mode`: the opening mode of the database file. It can be 'r'ead-only
          'w'rite or 'a'ppend
        """

        is_open = False
        if self.checkOpening(filepath):
            # Open the database and add it to the tracking system
            db_doc = dbdoc.DBDoc(filepath, mode)
            self.mapDB(filepath, db_doc)

            # Populate the model with the dbdoc
            root_node = rootgroupnode.RootGroupNode(self, db_doc, self.root)
            self.fdelta = frozenset([root_node])
            self.gdelta = frozenset([])
            self.ldelta = frozenset([])
            self.links_delta = frozenset([])
            self.insertRows(position, 1)
            is_open = True

        return is_open
Beispiel #2
0
    def createDBDoc(self, filepath, is_tmp_db=False):
        """
        Create a new, empty database (:meth:`vitables.h5db.dbdoc.DBDoc`
        instance).

        :Parameters:

        - `filepath`: the full path of the file being created.
        - `is_tmp_db`: True if the `DBDoc` is tied to the temporary database
        """

        try:
            QtWidgets.qApp.setOverrideCursor(
                QtGui.QCursor(QtCore.Qt.WaitCursor))
            # Create the dbdoc
            try:
                db_doc = dbdoc.DBDoc(filepath, 'w', is_tmp_db)
            except (tables.NodeError, OSError):
                log.error(
                    translate(
                        'DBsTreeModel',
                        """File creation failed due to unknown"""
                        """reasons! Please, have a look to the """
                        """last error displayed in the logger. If you """
                        """think it's a bug, please report it to """
                        """developers.""", 'A file creation error'))
                return None

            # Track the just created dbdoc
            self.mapDB(filepath, db_doc)

            # Populate the model with the dbdoc
            root = rootgroupnode.RootGroupNode(self, db_doc, self.root,
                                               is_tmp_db)
            self.fdelta = frozenset([root])
            self.gdelta = frozenset([])
            self.ldelta = frozenset([])
            self.links_delta = frozenset([])
            self.insertRows(0, 1)
        finally:
            QtWidgets.qApp.restoreOverrideCursor()
        return db_doc