2007-06-18 Don Allingham <don@gramps-project.org>
* src/GrampsDb/_GrampsDBDir.py: support lock file * src/DbManager.py: display locked file message svn: r8584
This commit is contained in:
parent
cf52ebb90d
commit
b5ce4a2c59
@ -1,3 +1,7 @@
|
||||
2007-06-18 Don Allingham <don@gramps-project.org>
|
||||
* src/GrampsDb/_GrampsDBDir.py: support lock file
|
||||
* src/DbManager.py: display locked file message
|
||||
|
||||
2007-06-18 Alex Roitman <shura@gramps-project.org>
|
||||
* src/DateEdit.py (DateEditorDialog.switch_calendar): Only convert
|
||||
non-empty dates to new calendar.
|
||||
|
@ -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, "")
|
||||
|
||||
|
@ -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__":
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user