do the sensible thing, prevent duplicate names when creating a new db.

svn: r8332
This commit is contained in:
Don Allingham
2007-03-28 04:05:16 +00:00
parent e5f0c18781
commit e8387f71c7
2 changed files with 25 additions and 14 deletions

View File

@@ -1,7 +1,7 @@
2007-03-27 Don Allingham <don@gramps-project.org> 2007-03-27 Don Allingham <don@gramps-project.org>
* src/ViewManager.py: pass dbstate to DbManager * src/ViewManager.py: pass dbstate to DbManager
* src/DbManager.py: add icon, prevent deletion of open db, make buttons * src/DbManager.py: add icon, prevent deletion of open db, make buttons
do the sensible thing do the sensible thing, prevent duplicate names when creating a new db.
2007-03-27 Brian Matherly <brian@gramps-project.org> 2007-03-27 Brian Matherly <brian@gramps-project.org>
* src/ReportBase/_ReportDialog.py * src/ReportBase/_ReportDialog.py

View File

@@ -60,7 +60,7 @@ import QuestionDialog
DEFAULT_DIR = os.path.expanduser("~/grampsdb") DEFAULT_DIR = os.path.expanduser("~/grampsdb")
DEFAULT_TITLE = _("Unnamed Database") DEFAULT_TITLE = _("Database")
NAME_FILE = "name.txt" NAME_FILE = "name.txt"
META_NAME = "meta_data.db" META_NAME = "meta_data.db"
@@ -90,6 +90,8 @@ class DbManager:
self.selection = self.dblist.get_selection() self.selection = self.dblist.get_selection()
self.current_names = []
self.connect_signals() self.connect_signals()
self.build_interface() self.build_interface()
self.populate() self.populate()
@@ -134,14 +136,14 @@ class DbManager:
except: except:
print "did not make default dir" print "did not make default dir"
sort_list = [] self.current_names = []
for dpath in os.listdir(DEFAULT_DIR): for dpath in os.listdir(DEFAULT_DIR):
dirpath = os.path.join(DEFAULT_DIR, dpath) dirpath = os.path.join(DEFAULT_DIR, dpath)
path_name = os.path.join(dirpath, NAME_FILE) path_name = os.path.join(dirpath, NAME_FILE)
if os.path.isfile(path_name): if os.path.isfile(path_name):
name = file(path_name).readline().strip() name = file(path_name).readline().strip()
meta = os.path.join(dirpath, dpath, META_NAME) meta = os.path.join(dirpath, META_NAME)
if os.path.isfile(meta): if os.path.isfile(meta):
tval = os.stat(meta)[9] tval = os.stat(meta)[9]
last = time.asctime(time.localtime(tval)) last = time.asctime(time.localtime(tval))
@@ -156,16 +158,16 @@ class DbManager:
enable = False enable = False
stock_id = "" stock_id = ""
sort_list.append((name, self.current_names.append((name,
os.path.join(DEFAULT_DIR, dpath), os.path.join(DEFAULT_DIR, dpath),
path_name, path_name,
last, last,
tval, tval,
enable, enable,
stock_id)) stock_id))
sort_list.sort() self.current_names.sort()
for items in sort_list: for items in self.current_names:
data = [items[0], items[1], items[2], items[3], items[4], items[5], items[6]] data = [items[0], items[1], items[2], items[3], items[4], items[5], items[6]]
self.model.append(data) self.model.append(data)
self.dblist.set_model(self.model) self.dblist.set_model(self.model)
@@ -228,10 +230,19 @@ class DbManager:
os.mkdir(new_path) os.mkdir(new_path)
path_name = os.path.join(new_path, NAME_FILE) path_name = os.path.join(new_path, NAME_FILE)
title = DEFAULT_TITLE
i = 1
while True:
title = "%s %d" % (DEFAULT_TITLE, i)
if title not in self.current_names:
break
i += 1
f = open(path_name, "w") f = open(path_name, "w")
f.write(title) f.write(title)
f.close() f.close()
self.current_names.append(title)
node = self.model.append([title, new_path, path_name, _("Never"), 0, False, '']) node = self.model.append([title, new_path, path_name, _("Never"), 0, False, ''])
self.selection.select_iter(node) self.selection.select_iter(node)