Changes to allow a QML interface:
* a const to launch it * fix an error in obtaining dbname * refractor pieces to allow reuse svn: r16504
This commit is contained in:
parent
9d79439ead
commit
9a2fd50642
@ -63,6 +63,18 @@ DEFAULT_TITLE = _("Family Tree")
|
||||
NAME_FILE = "name.txt"
|
||||
META_NAME = "meta_data.db"
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
# functions
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
def _errordialog(title, errormessage):
|
||||
"""
|
||||
Show the error. A title for the error and an errormessage
|
||||
"""
|
||||
print _('ERROR: %s \n %s') % (title, errormessage)
|
||||
sys.exit()
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
# CLIDbManager
|
||||
@ -73,6 +85,14 @@ class CLIDbManager(object):
|
||||
Database manager without GTK functionality, allows users to create and
|
||||
open databases
|
||||
"""
|
||||
IND_NAME = 0
|
||||
IND_PATH = 1
|
||||
IND_PATH_NAMEFILE = 2
|
||||
IND_TVAL_STR = 3
|
||||
IND_TVAL = 4
|
||||
IND_USE_ICON_BOOL = 5
|
||||
IND_STOCK_ID =6
|
||||
|
||||
ICON_NONE = 0
|
||||
ICON_RECOVERY = 1
|
||||
ICON_LOCK = 2
|
||||
@ -85,6 +105,7 @@ class CLIDbManager(object):
|
||||
ICON_OPEN : None,
|
||||
}
|
||||
|
||||
ERROR = _errordialog
|
||||
def __init__(self, dbstate):
|
||||
self.dbstate = dbstate
|
||||
self.msg = None
|
||||
@ -305,6 +326,24 @@ class CLIDbManager(object):
|
||||
return True
|
||||
return False
|
||||
|
||||
def rename_database(self, filepath, new_text):
|
||||
"""
|
||||
Renames the database by writing the new value to the name.txt file
|
||||
Returns old_name, new_name if success, None, None if no success
|
||||
"""
|
||||
try:
|
||||
name_file = open(filepath, "r")
|
||||
old_text=name_file.read()
|
||||
name_file.close()
|
||||
name_file = open(filepath, "w")
|
||||
name_file.write(new_text)
|
||||
name_file.close()
|
||||
except (OSError, IOError), msg:
|
||||
ERROR(_("Could not rename family tree"),
|
||||
str(msg))
|
||||
return None, None
|
||||
return old_text, new_text
|
||||
|
||||
def break_lock(self, dbpath):
|
||||
"""
|
||||
Breaks the lock on a database
|
||||
|
@ -286,7 +286,8 @@ LONGOPTS = [
|
||||
"sm-disable",
|
||||
"sync",
|
||||
"usage",
|
||||
"version",
|
||||
"version",
|
||||
"qml",
|
||||
]
|
||||
|
||||
SHORTOPTS = "O:i:e:f:a:p:d:lLhuv?c"
|
||||
|
@ -1594,7 +1594,14 @@ class DbBsddbRead(DbReadBase, Callback):
|
||||
|
||||
def get_dbname(self):
|
||||
"""
|
||||
In BSDDB, a database's name is not known until after we open it.
|
||||
In BSDDB, the database is in a text file at the path
|
||||
"""
|
||||
return None
|
||||
|
||||
filepath = os.path.join(self.path, "name.txt")
|
||||
try:
|
||||
name_file = open(filepath, "r")
|
||||
name = name_file.read()
|
||||
name_file.close()
|
||||
except (OSError, IOError), msg:
|
||||
self.__log_error()
|
||||
raise Errors.DbError(msg)
|
||||
return name
|
||||
|
@ -214,7 +214,6 @@ class DbBsddb(DbBsddbRead, DbWriteBase, UpdateCallback):
|
||||
self.secondary_connected = False
|
||||
self.has_changed = False
|
||||
self.brief_name = None
|
||||
self.db_name = None
|
||||
|
||||
def catch_db_error(func):
|
||||
"""
|
||||
@ -1800,12 +1799,6 @@ class DbBsddb(DbBsddbRead, DbWriteBase, UpdateCallback):
|
||||
"""
|
||||
return self.brief_name
|
||||
|
||||
def get_dbname(self):
|
||||
"""
|
||||
In BSDDB, we use the file directory name as the unique ID for
|
||||
this database on this computer.
|
||||
"""
|
||||
return self.db_name
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
|
@ -115,6 +115,8 @@ class DbManager(CLIDbManager):
|
||||
CLIDbManager.ICON_OPEN : gtk.STOCK_OPEN,
|
||||
}
|
||||
|
||||
ERROR = ErrorDialog
|
||||
|
||||
def __init__(self, dbstate, parent=None):
|
||||
"""
|
||||
Create the top level window from the glade description, and extracts
|
||||
@ -447,7 +449,7 @@ class DbManager(CLIDbManager):
|
||||
del proc
|
||||
|
||||
if status != 0:
|
||||
ErrorDialog(
|
||||
ERROR(
|
||||
_("Rename failed"),
|
||||
_("An attempt to rename a version failed "
|
||||
"with the following message:\n\n%s") % message
|
||||
@ -463,23 +465,13 @@ class DbManager(CLIDbManager):
|
||||
node = self.model.get_iter(path)
|
||||
filename = self.model.get_value(node, FILE_COL)
|
||||
if self.existing_name(new_text, skippath=path):
|
||||
ErrorDialog(
|
||||
_("Could not rename the Family Tree."),
|
||||
_("Family Tree already exists, choose a unique name."))
|
||||
ERROR(_("Could not rename the Family Tree."),
|
||||
_("Family Tree already exists, choose a unique name."))
|
||||
return
|
||||
try:
|
||||
name_file = open(filename, "r")
|
||||
old_text=name_file.read()
|
||||
name_file.close()
|
||||
name_file = open(filename, "w")
|
||||
name_file.write(new_text)
|
||||
name_file.close()
|
||||
old_text, new_text = self.rename_database(filename, new_text)
|
||||
if not (old_text is None):
|
||||
RecentFiles.rename_filename(old_text, new_text)
|
||||
self.model.set_value(node, NAME_COL, new_text)
|
||||
except (OSError, IOError), msg:
|
||||
ErrorDialog(
|
||||
_("Could not rename family tree"),
|
||||
str(msg))
|
||||
|
||||
def __rcs(self, obj):
|
||||
"""
|
||||
@ -576,7 +568,7 @@ class DbManager(CLIDbManager):
|
||||
os.unlink(os.path.join(top, filename))
|
||||
os.rmdir(self.data_to_delete[1])
|
||||
except (IOError, OSError), msg:
|
||||
ErrorDialog(_("Could not delete family tree"),
|
||||
ERROR(_("Could not delete family tree"),
|
||||
str(msg))
|
||||
# rebuild the display
|
||||
self.__populate()
|
||||
@ -600,7 +592,7 @@ class DbManager(CLIDbManager):
|
||||
del proc
|
||||
|
||||
if status != 0:
|
||||
ErrorDialog(
|
||||
ERROR(
|
||||
_("Deletion failed"),
|
||||
_("An attempt to delete a version failed "
|
||||
"with the following message:\n\n%s") % message
|
||||
@ -680,7 +672,7 @@ class DbManager(CLIDbManager):
|
||||
try:
|
||||
restore(dbase)
|
||||
except DbException, msg:
|
||||
ErrorDialog(_("Error restoring backup data"), msg)
|
||||
ERROR(_("Error restoring backup data"), msg)
|
||||
|
||||
self.__end_cursor()
|
||||
|
||||
@ -715,7 +707,7 @@ class DbManager(CLIDbManager):
|
||||
try:
|
||||
self._create_new_db()
|
||||
except (OSError, IOError), msg:
|
||||
ErrorDialog(_("Could not create family tree"),
|
||||
ERROR(_("Could not create family tree"),
|
||||
str(msg))
|
||||
self.new.set_sensitive(True)
|
||||
|
||||
|
@ -561,7 +561,7 @@ class ViewManager(CLIManager):
|
||||
self.window)
|
||||
self.update_dialog.destroy()
|
||||
|
||||
def _errordialog(title, errormessage):
|
||||
def _errordialog(self, title, errormessage):
|
||||
"""
|
||||
Show the error.
|
||||
In the GUI, the error is shown, and a return happens
|
||||
|
Loading…
Reference in New Issue
Block a user