From b5ce4a2c59c903c3365706ff0e41328862c5cc0f Mon Sep 17 00:00:00 2001 From: Don Allingham Date: Mon, 18 Jun 2007 19:33:52 +0000 Subject: [PATCH] 2007-06-18 Don Allingham * src/GrampsDb/_GrampsDBDir.py: support lock file * src/DbManager.py: display locked file message svn: r8584 --- ChangeLog | 4 ++++ src/DbManager.py | 16 ++++++++++++++++ src/GrampsDb/_GrampsDBDir.py | 23 ++++++++++++++++++++++- 3 files changed, 42 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index fc38c7c50..1e1d272b8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2007-06-18 Don Allingham + * src/GrampsDb/_GrampsDBDir.py: support lock file + * src/DbManager.py: display locked file message + 2007-06-18 Alex Roitman * src/DateEdit.py (DateEditorDialog.switch_calendar): Only convert non-empty dates to new calendar. diff --git a/src/DbManager.py b/src/DbManager.py index cfbb9d391..c592b1a2b 100644 --- a/src/DbManager.py +++ b/src/DbManager.py @@ -44,6 +44,11 @@ from gettext import gettext as _ import logging LOG = logging.getLogger(".DbManager") +if os.sys.platform == "win32": + _rcs_found = os.system("rcs -V >nul 2>nul") == 0 +else: + _rcs_found = os.system("rcs -V >/dev/null 2>/dev/null") == 0 + #------------------------------------------------------------------------- # # GTK/Gnome modules @@ -249,6 +254,15 @@ class DbManager: (enable, stock_id) = icon_values(dirpath, self.active, self.dbstate.db.is_open()) + if (stock_id == 'gramps-lock'): + try: + fname = os.path.join(dirpath, "lock") + f = open(fname) + last = f.read().strip() + f.close() + except: + last = _("Unknown") + self.current_names.append( (name, os.path.join(dbdir, dpath), path_name, last, tval, enable, stock_id)) @@ -466,6 +480,8 @@ def icon_values(dirpath, active, open): return (True, gtk.STOCK_DIALOG_ERROR) elif dirpath == active and open: return (True, gtk.STOCK_OPEN) + elif os.path.isfile(os.path.join(dirpath,"lock")): + return (True, 'gramps-lock') else: return (False, "") diff --git a/src/GrampsDb/_GrampsDBDir.py b/src/GrampsDb/_GrampsDBDir.py index 0e1f8631e..eec48a342 100644 --- a/src/GrampsDb/_GrampsDBDir.py +++ b/src/GrampsDb/_GrampsDBDir.py @@ -208,6 +208,10 @@ class GrampsDBDir(GrampsDbBase,UpdateCallback): mypath = os.path.join(self.get_save_path(),"need_recover") ofile = open(mypath, "w") ofile.close() + try: + clear_lock_file(self.get_save_path()) + except: + pass def __get_cursor(self, table): try: @@ -435,9 +439,9 @@ class GrampsDBDir(GrampsDbBase,UpdateCallback): try: if self.__check_readonly(name): mode = "r" + write_lock_file(name) return self.__load(name, callback, mode) except DBERRS, msg: - print name self.__log_error() raise Errors.DbError(msg) @@ -1211,9 +1215,12 @@ class GrampsDBDir(GrampsDbBase,UpdateCallback): def close(self): try: self.__close() + clear_lock_file(self.get_save_path()) except DBERRS, msg: self.__log_error() raise Errors.DbError(msg) + except IOError: + pass def __close(self): if not self.db_is_open: @@ -1721,6 +1728,20 @@ class BdbTransaction(Transaction): def _mkname(path, name): return os.path.join(path, name + ".db") +def clear_lock_file(name): + os.unlink(os.path.join(name, "lock")) + +def write_lock_file(name): + f = open(os.path.join(name, "lock"), "w") + if os.name == 'nt': + text = os.environ['USERNAME'] + else: + import pwd + host = os.uname()[1] + user = os.getlogin() + text = "%s@%s" % (user, host) + f.write(_("Locked by %s") % text) + f.close() if __name__ == "__main__":