From 98950a89a300040997da7221d526f845f15ad43d Mon Sep 17 00:00:00 2001 From: Nick Hall Date: Tue, 29 Nov 2016 19:34:57 +0000 Subject: [PATCH] Create new module for DbBookmarks --- gramps/gen/db/bookmarks.py | 54 +++++++++++++++++++++++++++++++++ gramps/gen/db/generic.py | 47 ++++++---------------------- gramps/plugins/db/bsddb/read.py | 35 +-------------------- po/POTFILES.skip | 1 + 4 files changed, 66 insertions(+), 71 deletions(-) create mode 100644 gramps/gen/db/bookmarks.py diff --git a/gramps/gen/db/bookmarks.py b/gramps/gen/db/bookmarks.py new file mode 100644 index 000000000..b029691db --- /dev/null +++ b/gramps/gen/db/bookmarks.py @@ -0,0 +1,54 @@ +# +# Gramps - a GTK+/GNOME based genealogy program +# +# Copyright (C) 2000-2007 Donald N. Allingham +# Copyright (C) 2010 Nick Hall +# Copyright (C) 2011 Tim G L Lyons +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +# + +#------------------------------------------------------------------------- +# +# class DbBookmarks +# +#------------------------------------------------------------------------- +class DbBookmarks: + def __init__(self, default=[]): + self.bookmarks = list(default) # want a copy (not an alias) + + def set(self, new_list): + self.bookmarks = list(new_list) + + def get(self): + return self.bookmarks + + def append(self, item): + self.bookmarks.append(item) + + def append_list(self, blist): + self.bookmarks += blist + + def remove(self, item): + self.bookmarks.remove(item) + + def pop(self, item): + return self.bookmarks.pop(item) + + def insert(self, pos, item): + self.bookmarks.insert(pos, item) + + def close(self): + del self.bookmarks diff --git a/gramps/gen/db/generic.py b/gramps/gen/db/generic.py index 9b8ff1a5d..14d44cba6 100644 --- a/gramps/gen/db/generic.py +++ b/gramps/gen/db/generic.py @@ -56,6 +56,7 @@ from gramps.gen.errors import HandleError from gramps.gen.utils.callback import Callback from gramps.gen.updatecallback import UpdateCallback from gramps.gen.db.dbconst import * +from gramps.gen.db.bookmarks import DbBookmarks from gramps.gen.db import exceptions from gramps.gen.utils.id import create_id @@ -302,34 +303,6 @@ class TreeCursor(Cursor): for handle in handles: yield (handle, self.db.get_raw_place_data(handle)) -class Bookmarks: - def __init__(self, default=[]): - self.handles = list(default) - - def set(self, handles): - self.handles = list(handles) - - def get(self): - return self.handles - - def append(self, handle): - self.handles.append(handle) - - def append_list(self, handles): - self.handles += handles - - def remove(self, handle): - self.handles.remove(handle) - - def pop(self, item): - return self.handles.pop(item) - - def insert(self, pos, item): - self.handles.insert(pos, item) - - def close(self): - del self.handles - class DbGeneric(DbWriteBase, DbReadBase, UpdateCallback, Callback): """ A Gramps Database Backend. This replicates the grampsdb functions. @@ -548,15 +521,15 @@ class DbGeneric(DbWriteBase, DbReadBase, UpdateCallback, Callback): self.db_is_open = False self.name_formats = [] # Bookmarks: - self.bookmarks = Bookmarks() - self.family_bookmarks = Bookmarks() - self.event_bookmarks = Bookmarks() - self.place_bookmarks = Bookmarks() - self.citation_bookmarks = Bookmarks() - self.source_bookmarks = Bookmarks() - self.repo_bookmarks = Bookmarks() - self.media_bookmarks = Bookmarks() - self.note_bookmarks = Bookmarks() + self.bookmarks = DbBookmarks() + self.family_bookmarks = DbBookmarks() + self.event_bookmarks = DbBookmarks() + self.place_bookmarks = DbBookmarks() + self.citation_bookmarks = DbBookmarks() + self.source_bookmarks = DbBookmarks() + self.repo_bookmarks = DbBookmarks() + self.media_bookmarks = DbBookmarks() + self.note_bookmarks = DbBookmarks() self.set_person_id_prefix('I%04d') self.set_media_id_prefix('O%04d') self.set_family_id_prefix('F%04d') diff --git a/gramps/plugins/db/bsddb/read.py b/gramps/plugins/db/bsddb/read.py index cfa0e152c..faab024ce 100644 --- a/gramps/plugins/db/bsddb/read.py +++ b/gramps/plugins/db/bsddb/read.py @@ -72,6 +72,7 @@ from gramps.gen.lib.nameorigintype import NameOriginType from gramps.gen.utils.callback import Callback from . import BsddbBaseCursor from gramps.gen.db.base import DbReadBase +from gramps.gen.db.bookmarks import DbBookmarks from gramps.gen.utils.id import create_id from gramps.gen.errors import DbError, HandleError from gramps.gen.constfunc import get_env_var @@ -164,40 +165,6 @@ def __index_surname(surn_list): surn = "" return surn - -#------------------------------------------------------------------------- -# -# class DbBookmarks -# -#------------------------------------------------------------------------- -class DbBookmarks: - def __init__(self, default=[]): - self.bookmarks = list(default) # want a copy (not an alias) - - def set(self, new_list): - self.bookmarks = list(new_list) - - def get(self): - return self.bookmarks - - def append(self, item): - self.bookmarks.append(item) - - def append_list(self, blist): - self.bookmarks += blist - - def remove(self, item): - self.bookmarks.remove(item) - - def pop(self, item): - return self.bookmarks.pop(item) - - def insert(self, pos, item): - self.bookmarks.insert(pos, item) - - def close(self): - del self.bookmarks - #------------------------------------------------------------------------- # # GrampsDBReadCursor diff --git a/po/POTFILES.skip b/po/POTFILES.skip index 927d1b2de..3cd332f29 100644 --- a/po/POTFILES.skip +++ b/po/POTFILES.skip @@ -55,6 +55,7 @@ gramps/gen/datehandler/_grampslocale.py # gramps/gen/db/__init__.py gramps/gen/db/backup.py +gramps/gen/db/bookmarks.py gramps/gen/db/bsddbtxn.py gramps/gen/db/cursor.py gramps/gen/db/dbconst.py