5394: Gramps support for backup/restore of multiple trees needs to be better thought out

partial fix (nothing done about media directories);
original patch by Doug Blank, then modified by me


svn: r18845
This commit is contained in:
Paul Franklin 2012-02-10 18:38:27 +00:00
parent 4bc1428a85
commit da16f93a45
3 changed files with 37 additions and 11 deletions

View File

@ -7,6 +7,8 @@
# Copyright (C) 2008 Raphael Ackermann # Copyright (C) 2008 Raphael Ackermann
# Copyright (C) 2008 Brian G. Matherly # Copyright (C) 2008 Brian G. Matherly
# Copyright (C) 2010 Jakim Friant # Copyright (C) 2010 Jakim Friant
# Copyright (C) 2012 Doug Blank
# Copyright (C) 2012 Paul Franklin
# #
# This program is free software; you can redistribute it and/or modify # 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 # it under the terms of the GNU General Public License as published by
@ -168,7 +170,7 @@ class ArgHandler(object):
self.imports = [] self.imports = []
self.exports = [] self.exports = []
self.open = self.__handle_open_option(parser.open) self.open = self.__handle_open_option(parser.open, parser.create)
self.sanitize_args(parser.imports, parser.exports) self.sanitize_args(parser.imports, parser.exports)
def __error(self, msg1, msg2=None): def __error(self, msg1, msg2=None):
@ -196,10 +198,11 @@ class ArgHandler(object):
for (value, family_tree_format) in exportlist: for (value, family_tree_format) in exportlist:
self.__handle_export_option(value, family_tree_format) self.__handle_export_option(value, family_tree_format)
def __handle_open_option(self, value): def __handle_open_option(self, value, create):
""" """
Handle the "-O" or "--open" option. Handle the "-O" or "--open" and "-C" or "--create" options.
Only Family trees or a dir with a family tree can be opened. Only Family trees or a dir with a family tree can be opened.
If create is True, then create the tree if it doesn't exist.
""" """
if value is None: if value is None:
return None return None
@ -211,6 +214,14 @@ class ArgHandler(object):
# Check if it is good. # Check if it is good.
if not self.check_db(db_path, self.force_unlock): if not self.check_db(db_path, self.force_unlock):
sys.exit(0) sys.exit(0)
if create:
self.__error( _("Error: Family tree '%s' already exists.\n"
"The '-C' option cannot be used.") % value)
sys.exit(0)
return db_path
elif create:
# create the tree here, and continue
db_path, title = self.dbman.create_new_db_cli(title=value)
return db_path return db_path
else: else:
self.__error( _('Error: Input family tree "%s" does not exist.\n' self.__error( _('Error: Input family tree "%s" does not exist.\n'

View File

@ -7,6 +7,8 @@
# Copyright (C) 2008 Lukasz Rymarczyk # Copyright (C) 2008 Lukasz Rymarczyk
# Copyright (C) 2008 Raphael Ackermann # Copyright (C) 2008 Raphael Ackermann
# Copyright (C) 2008 Brian G. Matherly # Copyright (C) 2008 Brian G. Matherly
# Copyright (C) 2012 Doug Blank
# Copyright (C) 2012 Paul Franklin
# #
# This program is free software; you can redistribute it and/or modify # 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 # it under the terms of the GNU General Public License as published by
@ -60,6 +62,7 @@ Help options
Application options Application options
-O, --open=FAMILY_TREE Open family tree -O, --open=FAMILY_TREE Open family tree
-C, --create=FAMILY_TREE Create on open if new family tree
-i, --import=FILENAME Import file -i, --import=FILENAME Import file
-e, --export=FILENAME Export file -e, --export=FILENAME Export file
-f, --format=FORMAT Specify family tree format -f, --format=FORMAT Specify family tree format
@ -174,6 +177,7 @@ class ArgParser(object):
self.help = False self.help = False
self.usage = False self.usage = False
self.force_unlock = False self.force_unlock = False
self.create = None
self.runqml = False self.runqml = False
self.errors = [] self.errors = []
@ -252,6 +256,8 @@ class ArgParser(object):
option, value = options[opt_ix] option, value = options[opt_ix]
if option in ( '-O', '--open'): if option in ( '-O', '--open'):
self.open = value self.open = value
elif option in ( '-C', '--create'):
self.create = value
elif option in ( '-i', '--import'): elif option in ( '-i', '--import'):
family_tree_format = None family_tree_format = None
if opt_ix < len(options) - 1 \ if opt_ix < len(options) - 1 \
@ -376,6 +382,12 @@ class ArgParser(object):
if (self.exports or self.actions): if (self.exports or self.actions):
# have both data and what to do with it => no GUI # have both data and what to do with it => no GUI
return False return False
elif self.create:
if self.open: # create an empty DB, open a GUI to fill it
return True
else: # create a DB, then do the import, with no GUI
self.open = self.create
return False
else: else:
# data given, but no action/export => GUI # data given, but no action/export => GUI
return True return True

View File

@ -3,6 +3,7 @@
# Gramps - a GTK+/GNOME based genealogy program # Gramps - a GTK+/GNOME based genealogy program
# #
# Copyright (C) 2000-2006 Donald N. Allingham # Copyright (C) 2000-2006 Donald N. Allingham
# Copyright (C) 2012 Doug Blank
# #
# This program is free software; you can redistribute it and/or modify # 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 # it under the terms of the GNU General Public License as published by
@ -245,6 +246,7 @@ NO_GIVEN = "(%s)" % _("none")
POPT_TABLE = [ POPT_TABLE = [
("config", 'c', str, None, 0, "Set config setting(s) and start Gramps", ""), ("config", 'c', str, None, 0, "Set config setting(s) and start Gramps", ""),
("open", 'O', str, None, 0, "Open family tree", "FAMILY_TREE"), ("open", 'O', str, None, 0, "Open family tree", "FAMILY_TREE"),
("create", 'C', str, None, 0, "Create or Open family tree", "FAMILY_TREE"),
("import", 'i', str, None, 0, "Import file", "FILENAME"), ("import", 'i', str, None, 0, "Import file", "FILENAME"),
("export", 'e', str, None, 0, "Export file", "FILENAME"), ("export", 'e', str, None, 0, "Export file", "FILENAME"),
("format", 'f', str, None, 0, 'Specify format', "FORMAT"), ("format", 'f', str, None, 0, 'Specify format', "FORMAT"),
@ -286,6 +288,7 @@ LONGOPTS = [
"oaf-ior-fd=", "oaf-ior-fd=",
"oaf-private", "oaf-private",
"open=", "open=",
"create=",
"options=", "options=",
"screen=", "screen=",
"show", "show",
@ -298,6 +301,6 @@ LONGOPTS = [
"qml", "qml",
] ]
SHORTOPTS = "O:i:e:f:a:p:d:c:lLhuv?s" SHORTOPTS = "O:C:i:e:f:a:p:d:c:lLhuv?s"
GRAMPS_UUID = uuid.UUID('516cd010-5a41-470f-99f8-eb22f1098ad6') GRAMPS_UUID = uuid.UUID('516cd010-5a41-470f-99f8-eb22f1098ad6')