From ae11d8b48440270fc8eaf93ed1c3394c0dfaf1f1 Mon Sep 17 00:00:00 2001 From: Doug Blank Date: Fri, 15 May 2015 06:42:13 -0400 Subject: [PATCH] Alternative DBs: touch meta_data.db to record last access time --- gramps/plugins/database/dictionarydb.py | 9 +++++++++ gramps/plugins/database/djangodb.py | 11 ++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/gramps/plugins/database/dictionarydb.py b/gramps/plugins/database/dictionarydb.py index 2a15c28b1..ff1b8f745 100644 --- a/gramps/plugins/database/dictionarydb.py +++ b/gramps/plugins/database/dictionarydb.py @@ -67,6 +67,13 @@ from gramps.gen.lib.tag import Tag _LOG = logging.getLogger(DBLOGNAME) +def touch(fname, mode=0o666, dir_fd=None, **kwargs): + ## After http://stackoverflow.com/questions/1158076/implement-touch-using-python + flags = os.O_CREAT | os.O_APPEND + with os.fdopen(os.open(fname, flags=flags, mode=mode, dir_fd=dir_fd)) as f: + os.utime(f.fileno() if os.utime in os.supports_fd else fname, + dir_fd=None if os.supports_fd else dir_fd, **kwargs) + class Environment(object): """ Implements the Environment API. @@ -1483,6 +1490,8 @@ class DictionaryDb(DbWriteBase, DbReadBase, UpdateCallback, Callback): writer = XmlWriter(self, User(), strip_photos=0, compress=1) filename = os.path.join(self._directory, "data.gramps") writer.write(filename) + filename = os.path.join(self._directory, "meta_data.db") + touch(filename) def find_backlink_handles(self, handle, include_classes=None): return [] diff --git a/gramps/plugins/database/djangodb.py b/gramps/plugins/database/djangodb.py index 543243c99..759d366b8 100644 --- a/gramps/plugins/database/djangodb.py +++ b/gramps/plugins/database/djangodb.py @@ -64,6 +64,13 @@ sys.path.append(os.path.dirname(os.path.abspath(__file__))) _LOG = logging.getLogger(DBLOGNAME) +def touch(fname, mode=0o666, dir_fd=None, **kwargs): + ## After http://stackoverflow.com/questions/1158076/implement-touch-using-python + flags = os.O_CREAT | os.O_APPEND + with os.fdopen(os.open(fname, flags=flags, mode=mode, dir_fd=dir_fd)) as f: + os.utime(f.fileno() if os.utime in os.supports_fd else fname, + dir_fd=None if os.supports_fd else dir_fd, **kwargs) + class Environment(object): """ Implements the Environment API. @@ -1959,7 +1966,9 @@ class DbDjango(DbWriteBase, DbReadBase, UpdateCallback, Callback): return None def close(self): - pass + if self._directory: + filename = os.path.join(self._directory, "meta_data.db") + touch(filename) def get_surname_list(self): return []