2007-03-27 08:48:49 +05:30
|
|
|
#
|
|
|
|
# Gramps - a GTK+/GNOME based genealogy program
|
|
|
|
#
|
|
|
|
# Copyright (C) 2000-2006 Donald N. Allingham
|
|
|
|
#
|
|
|
|
# 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
#
|
|
|
|
|
2007-04-02 09:26:30 +05:30
|
|
|
"""
|
|
|
|
Provides the management of databases. This includes opening, renaming,
|
|
|
|
creating, and deleting of databases.
|
|
|
|
"""
|
2007-03-27 08:48:49 +05:30
|
|
|
|
2007-04-02 09:26:30 +05:30
|
|
|
__author__ = "Donald N. Allingham"
|
|
|
|
__revision__ = "$Revision: 8197 $"
|
2007-03-27 08:48:49 +05:30
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# Standard python modules
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
import const
|
|
|
|
import os
|
|
|
|
import time
|
|
|
|
from gettext import gettext as _
|
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# set up logging
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
import logging
|
2007-04-02 09:26:30 +05:30
|
|
|
LOG = logging.getLogger(".DbManager")
|
2007-03-27 08:48:49 +05:30
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# GTK/Gnome modules
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
import gtk
|
|
|
|
import gtk.glade
|
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# gramps modules
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
import QuestionDialog
|
2007-06-12 09:59:15 +05:30
|
|
|
import GrampsDb
|
|
|
|
import GrampsDbUtils
|
|
|
|
import Config
|
2007-03-27 08:48:49 +05:30
|
|
|
|
2007-04-02 04:07:10 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# constants
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2007-04-21 10:24:28 +05:30
|
|
|
DEFAULT_DIR = os.path.join(const.home_dir, "grampsdb")
|
2007-03-29 07:12:21 +05:30
|
|
|
DEFAULT_TITLE = _("Family Tree")
|
2007-03-27 08:48:49 +05:30
|
|
|
NAME_FILE = "name.txt"
|
|
|
|
META_NAME = "meta_data.db"
|
|
|
|
|
|
|
|
NAME_COL = 0
|
|
|
|
PATH_COL = 1
|
|
|
|
FILE_COL = 2
|
|
|
|
DATE_COL = 3
|
2007-03-28 09:03:11 +05:30
|
|
|
OPEN_COL = 5
|
2007-04-02 09:26:30 +05:30
|
|
|
STOCK_COL = 6
|
2007-03-27 08:48:49 +05:30
|
|
|
|
|
|
|
class DbManager:
|
2007-04-02 04:07:10 +05:30
|
|
|
"""
|
|
|
|
Database Manager. Opens a database manager window that allows users to
|
|
|
|
create, rename, delete and open databases.
|
|
|
|
"""
|
|
|
|
|
2007-03-29 07:12:21 +05:30
|
|
|
def __init__(self, dbstate, parent=None):
|
2007-04-02 04:07:10 +05:30
|
|
|
"""
|
|
|
|
Creates the top level window from the glade description, and extracts
|
|
|
|
the GTK widgets that are needed.
|
|
|
|
"""
|
2007-03-27 08:48:49 +05:30
|
|
|
self.glade = gtk.glade.XML(const.gladeFile, "dbmanager", "gramps")
|
|
|
|
self.top = self.glade.get_widget('dbmanager')
|
2007-03-29 07:12:21 +05:30
|
|
|
if parent:
|
|
|
|
self.top.set_transient_for(parent)
|
2007-03-27 08:48:49 +05:30
|
|
|
|
|
|
|
self.connect = self.glade.get_widget('ok')
|
|
|
|
self.cancel = self.glade.get_widget('cancel')
|
|
|
|
self.new = self.glade.get_widget('new')
|
|
|
|
self.remove = self.glade.get_widget('remove')
|
|
|
|
self.dblist = self.glade.get_widget('dblist')
|
2007-03-29 08:51:54 +05:30
|
|
|
self.rename = self.glade.get_widget('rename')
|
2007-06-12 09:59:15 +05:30
|
|
|
self.repair = self.glade.get_widget('repair')
|
2007-06-13 07:57:31 +05:30
|
|
|
self.msg = self.glade.get_widget('msg')
|
2007-03-27 08:48:49 +05:30
|
|
|
self.model = None
|
2007-04-02 09:26:30 +05:30
|
|
|
self.dbstate = dbstate
|
|
|
|
self.column = None
|
|
|
|
self.data_to_delete = None
|
|
|
|
|
2007-03-28 09:03:11 +05:30
|
|
|
if dbstate:
|
|
|
|
self.active = dbstate.db.get_save_path()
|
|
|
|
else:
|
|
|
|
self.active = None
|
|
|
|
|
|
|
|
self.selection = self.dblist.get_selection()
|
2007-03-27 08:48:49 +05:30
|
|
|
|
2007-03-28 09:35:16 +05:30
|
|
|
self.current_names = []
|
|
|
|
|
2007-03-27 08:48:49 +05:30
|
|
|
self.connect_signals()
|
|
|
|
self.build_interface()
|
|
|
|
self.populate()
|
|
|
|
|
|
|
|
def connect_signals(self):
|
2007-04-02 04:07:10 +05:30
|
|
|
"""
|
|
|
|
Connects the signals to the buttons on the interface.
|
|
|
|
"""
|
2007-03-27 08:48:49 +05:30
|
|
|
self.remove.connect('clicked', self.remove_db)
|
|
|
|
self.new.connect('clicked', self.new_db)
|
2007-03-29 08:51:54 +05:30
|
|
|
self.rename.connect('clicked', self.rename_db)
|
2007-06-12 09:59:15 +05:30
|
|
|
self.repair.connect('clicked', self.repair_db)
|
2007-03-28 09:03:11 +05:30
|
|
|
self.selection.connect('changed', self.selection_changed)
|
2007-03-29 07:12:21 +05:30
|
|
|
self.dblist.connect('button-press-event', self.button_press)
|
|
|
|
|
|
|
|
def button_press(self, obj, event):
|
2007-04-02 09:26:30 +05:30
|
|
|
"""
|
|
|
|
Checks for a double click event. In the tree view, we want to
|
|
|
|
treat a double click as if it was OK button press. However, we have
|
|
|
|
to make sure that an item was selected first.
|
|
|
|
"""
|
2007-03-29 07:12:21 +05:30
|
|
|
if event.type == gtk.gdk._2BUTTON_PRESS and event.button == 1:
|
2007-04-02 09:26:30 +05:30
|
|
|
data = self.selection.get_selected()
|
|
|
|
if data[1]:
|
|
|
|
self.top.response(gtk.RESPONSE_OK)
|
2007-03-29 07:12:21 +05:30
|
|
|
return True
|
|
|
|
return False
|
2007-03-28 09:03:11 +05:30
|
|
|
|
|
|
|
def selection_changed(self, selection):
|
2007-04-02 09:26:30 +05:30
|
|
|
"""
|
|
|
|
Called with the selection is changed in the TreeView. What we
|
|
|
|
are trying to detect is the selection or unselection of a row.
|
|
|
|
When a row is unselected, the Open, Rename, and Remove buttons
|
|
|
|
are set insensitive. If a row is selected, the rename and remove
|
|
|
|
buttons are disabled, and the Open button is disabled if the
|
|
|
|
row represents a open database.
|
|
|
|
"""
|
|
|
|
|
|
|
|
# Get the current selection
|
|
|
|
store, node = selection.get_selected()
|
|
|
|
|
|
|
|
if not node:
|
2007-03-28 09:03:11 +05:30
|
|
|
self.connect.set_sensitive(False)
|
2007-03-29 08:51:54 +05:30
|
|
|
self.rename.set_sensitive(False)
|
2007-06-13 05:01:40 +05:30
|
|
|
self.repair.hide()
|
2007-04-02 09:26:30 +05:30
|
|
|
self.remove.set_sensitive(False)
|
2007-03-28 09:03:11 +05:30
|
|
|
else:
|
2007-04-02 09:26:30 +05:30
|
|
|
if store.get_value(node, OPEN_COL):
|
|
|
|
self.connect.set_sensitive(False)
|
|
|
|
else:
|
|
|
|
self.connect.set_sensitive(True)
|
2007-03-29 08:51:54 +05:30
|
|
|
self.rename.set_sensitive(True)
|
2007-06-13 05:01:40 +05:30
|
|
|
if store.get_value(node, STOCK_COL) == gtk.STOCK_DIALOG_ERROR:
|
|
|
|
path = store.get_value(node, PATH_COL)
|
|
|
|
if os.path.isfile(os.path.join(path,"person.gbkp")):
|
|
|
|
self.repair.show()
|
|
|
|
else:
|
|
|
|
self.repair.hide()
|
|
|
|
else:
|
|
|
|
self.repair.hide()
|
|
|
|
|
2007-04-02 09:26:30 +05:30
|
|
|
self.remove.set_sensitive(True)
|
2007-03-27 08:48:49 +05:30
|
|
|
|
|
|
|
def build_interface(self):
|
2007-04-02 09:26:30 +05:30
|
|
|
"""
|
|
|
|
Builds the columns for the TreeView. The columns are:
|
|
|
|
|
|
|
|
Icon, Database Name, Last Modified
|
|
|
|
|
|
|
|
The Icon column gets its data from column 6 of the database model.
|
|
|
|
It is expecting either None, or a GTK stock icon name
|
|
|
|
|
|
|
|
The Database Name column is an editable column. We connect to the
|
|
|
|
'edited' signal, so that we can change the name when the user changes
|
|
|
|
the column.
|
|
|
|
|
|
|
|
The last modified column simply displays the last modification time.
|
|
|
|
"""
|
|
|
|
|
|
|
|
# build the icon column
|
2007-03-28 09:03:11 +05:30
|
|
|
render = gtk.CellRendererPixbuf()
|
2007-04-02 09:26:30 +05:30
|
|
|
icon_column = gtk.TreeViewColumn('', render, stock_id=STOCK_COL)
|
|
|
|
self.dblist.append_column(icon_column)
|
2007-03-28 09:03:11 +05:30
|
|
|
|
2007-04-02 09:26:30 +05:30
|
|
|
# build the database name column
|
2007-03-27 08:48:49 +05:30
|
|
|
render = gtk.CellRendererText()
|
2007-04-02 09:26:30 +05:30
|
|
|
render.set_property('editable', True)
|
2007-03-27 08:48:49 +05:30
|
|
|
render.connect('edited', self.change_name)
|
2007-03-29 07:12:21 +05:30
|
|
|
self.column = gtk.TreeViewColumn(_('Family tree name'), render,
|
2007-03-28 09:03:11 +05:30
|
|
|
text=NAME_COL)
|
|
|
|
self.dblist.append_column(self.column)
|
2007-03-27 08:48:49 +05:30
|
|
|
|
2007-04-02 09:26:30 +05:30
|
|
|
# build the last modified cocolumn
|
2007-03-27 08:48:49 +05:30
|
|
|
render = gtk.CellRendererText()
|
|
|
|
column = gtk.TreeViewColumn(_('Last modified'), render, text=DATE_COL)
|
|
|
|
self.dblist.append_column(column)
|
2007-04-02 09:26:30 +05:30
|
|
|
|
|
|
|
# set the rules hit
|
2007-03-27 08:48:49 +05:30
|
|
|
self.dblist.set_rules_hint(True)
|
|
|
|
|
|
|
|
def populate(self):
|
2007-04-02 09:26:30 +05:30
|
|
|
"""
|
|
|
|
Builds the display model.
|
|
|
|
"""
|
|
|
|
|
2007-03-28 09:03:11 +05:30
|
|
|
self.model = gtk.ListStore(str, str, str, str, int, bool, str)
|
2007-03-27 08:48:49 +05:30
|
|
|
|
2007-04-02 09:26:30 +05:30
|
|
|
# make the default directory if it does not exist
|
|
|
|
try:
|
|
|
|
if not os.path.isdir(DEFAULT_DIR):
|
|
|
|
os.mkdir(DEFAULT_DIR)
|
|
|
|
except (IOError, OSError), msg:
|
|
|
|
LOG.error(_("Could not make database directory: ") + str(msg))
|
2007-03-27 17:24:10 +05:30
|
|
|
|
2007-03-28 09:35:16 +05:30
|
|
|
self.current_names = []
|
2007-03-27 08:48:49 +05:30
|
|
|
for dpath in os.listdir(DEFAULT_DIR):
|
2007-03-28 09:03:11 +05:30
|
|
|
dirpath = os.path.join(DEFAULT_DIR, dpath)
|
|
|
|
path_name = os.path.join(dirpath, NAME_FILE)
|
2007-03-27 08:48:49 +05:30
|
|
|
if os.path.isfile(path_name):
|
|
|
|
name = file(path_name).readline().strip()
|
|
|
|
|
2007-04-02 09:26:30 +05:30
|
|
|
(tval, last) = time_val(dirpath)
|
2007-06-14 04:18:28 +05:30
|
|
|
(enable, stock_id) = icon_values(dirpath, self.active,
|
|
|
|
self.dbstate.db.is_open())
|
2007-04-02 09:26:30 +05:30
|
|
|
|
|
|
|
self.current_names.append(
|
|
|
|
(name, os.path.join(DEFAULT_DIR, dpath), path_name,
|
|
|
|
last, tval, enable, stock_id))
|
2007-03-27 08:48:49 +05:30
|
|
|
|
2007-03-28 09:35:16 +05:30
|
|
|
self.current_names.sort()
|
|
|
|
for items in self.current_names:
|
2007-04-02 09:26:30 +05:30
|
|
|
data = [items[0], items[1], items[2], items[3],
|
|
|
|
items[4], items[5], items[6]]
|
2007-03-27 08:48:49 +05:30
|
|
|
self.model.append(data)
|
|
|
|
self.dblist.set_model(self.model)
|
|
|
|
|
|
|
|
def run(self):
|
2007-04-02 09:26:30 +05:30
|
|
|
"""
|
|
|
|
Runs the dialog, returning None if nothing has been chosen,
|
|
|
|
or the path and name if something has been selected
|
|
|
|
"""
|
2007-03-27 08:48:49 +05:30
|
|
|
value = self.top.run()
|
|
|
|
if value == gtk.RESPONSE_OK:
|
2007-03-28 09:03:11 +05:30
|
|
|
(model, node) = self.selection.get_selected()
|
2007-03-27 08:48:49 +05:30
|
|
|
if node:
|
|
|
|
self.top.destroy()
|
2007-04-02 09:26:30 +05:30
|
|
|
return (model.get_value(node, PATH_COL),
|
|
|
|
model.get_value(node, NAME_COL))
|
|
|
|
self.top.destroy()
|
|
|
|
return None
|
2007-03-27 08:48:49 +05:30
|
|
|
|
|
|
|
def change_name(self, text, path, new_text):
|
2007-04-02 09:26:30 +05:30
|
|
|
"""
|
|
|
|
Changes the name of the database. This is a callback from the
|
|
|
|
column, which has been marked as editable.
|
|
|
|
|
|
|
|
If the new string is empty, do nothing. Otherwise, renaming the
|
|
|
|
database is simply changing the contents of the name file.
|
|
|
|
"""
|
2007-03-27 08:48:49 +05:30
|
|
|
if len(new_text) > 0:
|
2007-04-02 09:26:30 +05:30
|
|
|
node = self.model.get_iter(path)
|
|
|
|
filename = self.model.get_value(node, FILE_COL)
|
2007-03-27 08:48:49 +05:30
|
|
|
try:
|
2007-04-02 09:26:30 +05:30
|
|
|
name_file = open(filename, "w")
|
|
|
|
name_file.write(new_text)
|
|
|
|
name_file.close()
|
|
|
|
self.model.set_value(node, NAME_COL, new_text)
|
|
|
|
except (OSError, IOError), msg:
|
|
|
|
QuestionDialog.ErrorDialog(
|
|
|
|
_("Could not rename family tree"),
|
|
|
|
str(msg))
|
2007-03-27 08:48:49 +05:30
|
|
|
|
|
|
|
def remove_db(self, obj):
|
2007-04-02 09:26:30 +05:30
|
|
|
"""
|
|
|
|
Callback associated with the Remove button. Get the selected
|
|
|
|
row and data, then call the verification dialog.
|
|
|
|
"""
|
|
|
|
store, node = self.selection.get_selected()
|
|
|
|
self.data_to_delete = store[store.get_path(node)]
|
2007-03-27 08:48:49 +05:30
|
|
|
|
|
|
|
QuestionDialog.QuestionDialog(
|
|
|
|
_("Remove the '%s' database?") % self.data_to_delete[0],
|
2007-04-02 09:26:30 +05:30
|
|
|
_("Removing this database will permanently destroy the data."),
|
2007-03-27 08:48:49 +05:30
|
|
|
_("Remove database"),
|
|
|
|
self.really_delete_db)
|
2007-04-02 09:26:30 +05:30
|
|
|
|
|
|
|
# rebuild the display
|
2007-03-27 08:48:49 +05:30
|
|
|
self.populate()
|
|
|
|
|
|
|
|
def really_delete_db(self):
|
2007-04-02 09:26:30 +05:30
|
|
|
"""
|
|
|
|
Delete the selected database. If the databse is open, close it first.
|
|
|
|
Then scan the database directory, deleting the files, and finally
|
|
|
|
removing the directory.
|
|
|
|
"""
|
2007-03-27 08:48:49 +05:30
|
|
|
|
2007-04-02 09:26:30 +05:30
|
|
|
# close the database if the user has requested to delete the
|
|
|
|
# active database
|
|
|
|
if self.data_to_delete[OPEN_COL]:
|
|
|
|
self.dbstate.no_database()
|
|
|
|
|
|
|
|
try:
|
|
|
|
for (top, dirs, files) in os.walk(self.data_to_delete[1]):
|
|
|
|
for filename in files:
|
|
|
|
os.unlink(os.path.join(top, filename))
|
|
|
|
os.rmdir(self.data_to_delete[1])
|
|
|
|
except (IOError, OSError), msg:
|
|
|
|
QuestionDialog.ErrorDialog(_("Could not delete family tree"),
|
|
|
|
str(msg))
|
|
|
|
|
2007-03-29 08:51:54 +05:30
|
|
|
def rename_db(self, obj):
|
2007-04-02 09:26:30 +05:30
|
|
|
"""
|
|
|
|
Start the rename process by calling the start_editing option on
|
|
|
|
the line with the cursor.
|
|
|
|
"""
|
2007-03-29 08:51:54 +05:30
|
|
|
store, node = self.selection.get_selected()
|
|
|
|
path = self.model.get_path(node)
|
2007-04-02 09:26:30 +05:30
|
|
|
self.dblist.set_cursor(path, focus_column=self.column,
|
|
|
|
start_editing=True)
|
2007-03-29 08:51:54 +05:30
|
|
|
|
2007-06-12 09:59:15 +05:30
|
|
|
def repair_db(self, obj):
|
|
|
|
"""
|
|
|
|
Start the rename process by calling the start_editing option on
|
|
|
|
the line with the cursor.
|
|
|
|
"""
|
|
|
|
store, node = self.selection.get_selected()
|
|
|
|
dirname = store[node][1]
|
|
|
|
opened = store[node][5]
|
|
|
|
if opened:
|
|
|
|
self.dbstate.no_database()
|
|
|
|
|
|
|
|
# delete files that are not backup files or the .txt file
|
|
|
|
for filename in os.listdir(dirname):
|
|
|
|
if os.path.splitext(filename)[1] not in (".gbkp", ".txt"):
|
|
|
|
os.unlink(os.path.join(dirname,filename))
|
|
|
|
|
|
|
|
dbclass = GrampsDb.gramps_db_factory(db_type = "x-directory/normal")
|
|
|
|
db = dbclass(Config.get(Config.TRANSACTIONS))
|
|
|
|
db.set_save_path(dirname)
|
|
|
|
db.load(dirname, None)
|
2007-06-13 07:57:31 +05:30
|
|
|
self.msg.set_label(_("Rebuilding database from backup files"))
|
|
|
|
while (gtk.events_pending()):
|
|
|
|
gtk.main_iteration()
|
2007-06-12 09:59:15 +05:30
|
|
|
GrampsDbUtils.Backup.restore(db)
|
2007-06-13 07:57:31 +05:30
|
|
|
self.msg.set_label("")
|
2007-06-12 09:59:15 +05:30
|
|
|
db.close()
|
2007-06-13 05:01:40 +05:30
|
|
|
self.dbstate.no_database()
|
|
|
|
self.populate()
|
2007-06-12 09:59:15 +05:30
|
|
|
|
2007-03-27 08:48:49 +05:30
|
|
|
def new_db(self, obj):
|
2007-04-02 09:26:30 +05:30
|
|
|
"""
|
|
|
|
Callback wrapper around the actual routine that creates the
|
|
|
|
new database. Catch OSError and IOError and display a warning
|
|
|
|
message.
|
|
|
|
"""
|
|
|
|
try:
|
|
|
|
self.mk_db()
|
|
|
|
except (OSError, IOError), msg:
|
|
|
|
QuestionDialog.ErrorDialog(_("Could not create family tree"),
|
|
|
|
str(msg))
|
|
|
|
|
|
|
|
def mk_db(self):
|
|
|
|
"""
|
|
|
|
Create a new database.
|
|
|
|
"""
|
|
|
|
|
|
|
|
new_path = find_next_db_dir()
|
2007-03-27 08:48:49 +05:30
|
|
|
|
|
|
|
os.mkdir(new_path)
|
|
|
|
path_name = os.path.join(new_path, NAME_FILE)
|
2007-03-28 09:35:16 +05:30
|
|
|
|
2007-04-02 04:07:10 +05:30
|
|
|
name_list = [ name[0] for name in self.current_names ]
|
|
|
|
|
2007-04-02 09:26:30 +05:30
|
|
|
title = find_next_db_name(name_list)
|
2007-03-28 09:35:16 +05:30
|
|
|
|
2007-04-02 09:26:30 +05:30
|
|
|
name_file = open(path_name, "w")
|
|
|
|
name_file.write(title)
|
|
|
|
name_file.close()
|
2007-03-28 09:35:16 +05:30
|
|
|
|
|
|
|
self.current_names.append(title)
|
2007-04-02 09:26:30 +05:30
|
|
|
node = self.model.append([title, new_path, path_name,
|
|
|
|
_("Never"), 0, False, ''])
|
2007-03-28 09:03:11 +05:30
|
|
|
self.selection.select_iter(node)
|
|
|
|
|
|
|
|
path = self.model.get_path(node)
|
2007-04-02 09:26:30 +05:30
|
|
|
self.dblist.set_cursor(path, focus_column=self.column,
|
|
|
|
start_editing=True)
|
|
|
|
|
|
|
|
def find_next_db_name(name_list):
|
|
|
|
"""
|
|
|
|
Scan the name list, looking for names that do not yet exist.
|
|
|
|
Use the DEFAULT_TITLE as the basis for the database name.
|
|
|
|
"""
|
|
|
|
i = 1
|
|
|
|
while True:
|
|
|
|
title = "%s %d" % (DEFAULT_TITLE, i)
|
|
|
|
if title not in name_list:
|
|
|
|
return title
|
|
|
|
i += 1
|
|
|
|
|
|
|
|
def find_next_db_dir():
|
|
|
|
"""
|
|
|
|
Searches the default directory for the first available default
|
|
|
|
database name. Base the name off the current time. In all actuality,
|
|
|
|
the first should be valid.
|
|
|
|
"""
|
|
|
|
while True:
|
|
|
|
base = "%x" % int(time.time())
|
|
|
|
new_path = os.path.join(DEFAULT_DIR, base)
|
|
|
|
if not os.path.isdir(new_path):
|
|
|
|
break
|
|
|
|
return new_path
|
|
|
|
|
|
|
|
def time_val(dirpath):
|
|
|
|
"""
|
|
|
|
Return the last modified time of the database. We do this by looking
|
|
|
|
at the modification time of the meta db file. If this file does not
|
|
|
|
exist, we indicate that database as never modified.
|
|
|
|
"""
|
|
|
|
meta = os.path.join(dirpath, META_NAME)
|
|
|
|
if os.path.isfile(meta):
|
|
|
|
tval = os.stat(meta)[9]
|
|
|
|
last = time.asctime(time.localtime(tval))
|
|
|
|
else:
|
|
|
|
tval = 0
|
|
|
|
last = _("Never")
|
|
|
|
return (tval, last)
|
|
|
|
|
2007-06-14 04:18:28 +05:30
|
|
|
def icon_values(dirpath, active, open):
|
2007-04-02 09:26:30 +05:30
|
|
|
"""
|
|
|
|
If the directory path is the active path, then return values
|
|
|
|
that indicate to use the icon, and which icon to use.
|
|
|
|
"""
|
2007-06-13 05:01:40 +05:30
|
|
|
if os.path.isfile(os.path.join(dirpath,"need_recover")):
|
|
|
|
return (True, gtk.STOCK_DIALOG_ERROR)
|
2007-06-14 04:18:28 +05:30
|
|
|
elif dirpath == active and open:
|
|
|
|
return (True, gtk.STOCK_OPEN)
|
2007-04-02 09:26:30 +05:30
|
|
|
else:
|
|
|
|
return (False, "")
|
|
|
|
|