Esempio n. 1
0
 def _check_backend(self) -> None:
     """Check that the backend is among the allowed backends."""
     backend = get_dbid_from_path(self.path)
     if backend not in self.ALLOWED_DB_BACKENDS:
         raise ValueError(
             "Database backend '{}' of tree '{}' not supported.".format(
                 backend, self.name))
Esempio n. 2
0
    def _populate_cli(self):
        """
        Get the list of current names in the database dir
        """
        # make the default directory if it does not exist
        dbdir = os.path.expanduser(config.get('database.path'))
        db_ok = make_dbdir(dbdir)

        self.current_names = []
        if db_ok:
            for dpath in os.listdir(dbdir):
                dirpath = os.path.join(dbdir, dpath)
                path_name = os.path.join(dirpath, NAME_FILE)
                backend_type = get_dbid_from_path(dirpath)
                if os.path.isfile(path_name):
                    with open(path_name, 'r', encoding='utf8') as file:
                        name = file.readline().strip()

                    (tval, last) = time_val(dirpath)
                    (enable,
                     stock_id) = self.icon_values(dirpath, self.active,
                                                  self.dbstate.is_open())

                    if stock_id == 'gramps-lock':
                        last = find_locker_name(dirpath)

                    self.current_names.append(
                        (name, os.path.join(dbdir, dpath), path_name, last,
                         tval, enable, stock_id, backend_type))

        self.current_names.sort()
Esempio n. 3
0
    def _populate_cli(self):
        """
        Get the list of current names in the database dir
        """
        # make the default directory if it does not exist
        dbdir = os.path.expanduser(config.get('database.path'))
        db_ok = make_dbdir(dbdir)

        self.current_names = []
        if db_ok:
            for dpath in os.listdir(dbdir):
                dirpath = os.path.join(dbdir, dpath)
                path_name = os.path.join(dirpath, NAME_FILE)
                backend_type = get_dbid_from_path(dirpath)
                if os.path.isfile(path_name):
                    with open(path_name, 'r', encoding='utf8') as file:
                        name = file.readline().strip()

                    (tval, last) = time_val(dirpath)
                    (enable, stock_id) = self.icon_values(
                        dirpath, self.active, self.dbstate.is_open())

                    if stock_id == 'gramps-lock':
                        last = find_locker_name(dirpath)

                    self.current_names.append(
                        (name, os.path.join(dbdir, dpath), path_name,
                         last, tval, enable, stock_id, backend_type))

        self.current_names.sort()
Esempio n. 4
0
    def get_dbdir_summary(self, dirpath, name):
        """
        dirpath: full path to database
        name: proper name of family tree

        Returns dictionary of summary item.
        Should include at least, if possible:

        _("Path")
        _("Family Tree")
        _("Last accessed")
        _("Database")
        _("Locked?")

        and these details:

        _("Number of people")
        _("Version")
        _("Schema version")
        """
        dbid = get_dbid_from_path(dirpath)
        if not self.is_locked(dirpath):
            try:
                database = make_database(dbid)
                database.load(dirpath, None, update=False)
                retval = database.get_summary()
                database.close(update=False)
            except Exception as msg:
                retval = {_("Unavailable"): str(msg)[:74] + "..."}
        else:
            retval = {_("Unavailable"): "locked"}
        retval.update({
            _("Family Tree"): name,
            _("Path"): dirpath,
            _("Database"): self.get_backend_name_from_dbid(dbid),
            _("Last accessed"): time_val(dirpath)[1],
            _("Locked?"): self.is_locked(dirpath),
        })
        return retval
Esempio n. 5
0
    def get_dbdir_summary(self, dirpath, name):
        """
        dirpath: full path to database
        name: proper name of family tree

        Returns dictionary of summary item.
        Should include at least, if possible:

        _("Path")
        _("Family Tree")
        _("Last accessed")
        _("Database")
        _("Locked?")

        and these details:

        _("Number of people")
        _("Version")
        _("Schema version")
        """
        dbid = get_dbid_from_path(dirpath)
        if not self.is_locked(dirpath):
            try:
                database = make_database(dbid)
                database.load(dirpath, None, update=False)
                retval = database.get_summary()
                database.close(update=False)
            except Exception as msg:
                retval = {_("Unavailable"): str(msg)[:74] + "..."}
        else:
            retval = {_("Unavailable"): "locked"}
        retval.update({_("Family Tree"): name,
                       _("Path"): dirpath,
                       _("Database"): self.get_backend_name_from_dbid(dbid),
                       _("Last accessed"): time_val(dirpath)[1],
                       _("Locked?"): self.is_locked(dirpath),
                      })
        return retval
Esempio n. 6
0
 def backend_unavailable(self, dbpath):
     """
     Returns True if the database in dirpath has an unavailable backend
     """
     dbid = get_dbid_from_path(dbpath)
     return self.get_backend_name_from_dbid(dbid) == UNAVAILABLE
Esempio n. 7
0
 def get_dbid(self):
     """Get the database backend."""
     return get_dbid_from_path(self.path)
Esempio n. 8
0
 def backend_unavailable(self, dbpath):
     """
     Returns True if the database in dirpath has an unavailable backend
     """
     dbid = get_dbid_from_path(dbpath)
     return self.get_backend_name_from_dbid(dbid) == UNAVAILABLE