From e8387f71c734d2fd1aca5ae47283c4a96d212fde Mon Sep 17 00:00:00 2001 From: Don Allingham Date: Wed, 28 Mar 2007 04:05:16 +0000 Subject: [PATCH] do the sensible thing, prevent duplicate names when creating a new db. svn: r8332 --- ChangeLog | 2 +- src/DbManager.py | 37 ++++++++++++++++++++++++------------- 2 files changed, 25 insertions(+), 14 deletions(-) diff --git a/ChangeLog b/ChangeLog index 0a5c72d6d..4e49e5405 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,7 +1,7 @@ 2007-03-27 Don Allingham * src/ViewManager.py: pass dbstate to DbManager * 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 * src/ReportBase/_ReportDialog.py diff --git a/src/DbManager.py b/src/DbManager.py index 4781670b5..8e567844d 100644 --- a/src/DbManager.py +++ b/src/DbManager.py @@ -60,7 +60,7 @@ import QuestionDialog DEFAULT_DIR = os.path.expanduser("~/grampsdb") -DEFAULT_TITLE = _("Unnamed Database") +DEFAULT_TITLE = _("Database") NAME_FILE = "name.txt" META_NAME = "meta_data.db" @@ -90,6 +90,8 @@ class DbManager: self.selection = self.dblist.get_selection() + self.current_names = [] + self.connect_signals() self.build_interface() self.populate() @@ -134,14 +136,14 @@ class DbManager: except: print "did not make default dir" - sort_list = [] + self.current_names = [] for dpath in os.listdir(DEFAULT_DIR): dirpath = os.path.join(DEFAULT_DIR, dpath) path_name = os.path.join(dirpath, NAME_FILE) if os.path.isfile(path_name): 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): tval = os.stat(meta)[9] last = time.asctime(time.localtime(tval)) @@ -156,16 +158,16 @@ class DbManager: enable = False stock_id = "" - sort_list.append((name, - os.path.join(DEFAULT_DIR, dpath), - path_name, - last, - tval, - enable, - stock_id)) + self.current_names.append((name, + os.path.join(DEFAULT_DIR, dpath), + path_name, + last, + tval, + enable, + stock_id)) - sort_list.sort() - for items in sort_list: + self.current_names.sort() + for items in self.current_names: data = [items[0], items[1], items[2], items[3], items[4], items[5], items[6]] self.model.append(data) self.dblist.set_model(self.model) @@ -228,10 +230,19 @@ class DbManager: os.mkdir(new_path) 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.write(title) f.close() + + self.current_names.append(title) node = self.model.append([title, new_path, path_name, _("Never"), 0, False, '']) self.selection.select_iter(node)