Adds -r, --remove FAMILY_TREE_NAME to command-line

* gives error if doesn't exist
* currently requires exact match
* doesn't ask for permission (yet)
This commit is contained in:
Doug Blank 2015-12-18 07:30:03 -05:00
parent 392e9eb399
commit 72662bcf06
4 changed files with 27 additions and 4 deletions

View File

@ -177,6 +177,7 @@ class ArgHandler(object):
self.cl = 0 self.cl = 0
self.imports = [] self.imports = []
self.exports = [] self.exports = []
self.removes = parser.removes
self.open = self.__handle_open_option(parser.open, parser.create) self.open = self.__handle_open_option(parser.open, parser.create)
self.sanitize_args(parser.imports, parser.exports) self.sanitize_args(parser.imports, parser.exports)
@ -403,6 +404,15 @@ class ArgHandler(object):
else: else:
return return
# Handle the "--remove" Family Tree
if self.removes:
for name in self.removes:
self.dbman.remove_database(name)
if should_exit:
sys.exit(0)
else:
return
# Handle the "-L" List Family Trees in detail option. # Handle the "-L" List Family Trees in detail option.
if self.list_more: if self.list_more:
self.dbman.print_family_tree_summaries() self.dbman.print_family_tree_summaries()

View File

@ -62,6 +62,7 @@ Application options
-C, --create=FAMILY_TREE Create on open if new 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
-r, --remove=FAMILY_TREE Remove a Family Tree
-f, --format=FORMAT Specify Family Tree format -f, --format=FORMAT Specify Family Tree format
-a, --action=ACTION Specify action -a, --action=ACTION Specify action
-p, --options=OPTIONS_STRING Specify options -p, --options=OPTIONS_STRING Specify options
@ -137,6 +138,7 @@ class ArgParser(object):
-C, --create=FAMILY_TREE Create on open if new 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
-r, --remove=FAMILY_TREE Remove a Family Tree
-f, --format=FORMAT Specify Family Tree format -f, --format=FORMAT Specify Family Tree format
-a, --action=ACTION Specify action -a, --action=ACTION Specify action
-p, --options=OPTIONS_STRING Specify options -p, --options=OPTIONS_STRING Specify options
@ -194,6 +196,7 @@ class ArgParser(object):
self.exports = [] self.exports = []
self.actions = [] self.actions = []
self.imports = [] self.imports = []
self.removes = []
self.imp_db_path = None self.imp_db_path = None
self.list = False self.list = False
self.list_more = False self.list_more = False
@ -267,6 +270,8 @@ class ArgParser(object):
and options[opt_ix + 1][0] in ( '-f', '--format'): and options[opt_ix + 1][0] in ( '-f', '--format'):
family_tree_format = options[opt_ix + 1][1] family_tree_format = options[opt_ix + 1][1]
self.imports.append((value, family_tree_format)) self.imports.append((value, family_tree_format))
elif option in ['-r', '--remove']:
self.removes.append(value)
elif option in ['-e', '--export']: elif option in ['-e', '--export']:
family_tree_format = None family_tree_format = None
if opt_ix < len(options) - 1 \ if opt_ix < len(options) - 1 \
@ -359,9 +364,10 @@ class ArgParser(object):
for ind in cleandbg: for ind in cleandbg:
del options[ind] del options[ind]
if len(options) > 0 and self.open is None and self.imports == [] \ if (len(options) > 0 and self.open is None and self.imports == []
and not (self.list or self.list_more or self.list_table or and self.removes == []
self.help or self.runqml): and not (self.list or self.list_more or self.list_table or
self.help or self.runqml)):
# Extract and convert to unicode the arguments in the list. # Extract and convert to unicode the arguments in the list.
# The % operator replaces the list elements with repr() of # The % operator replaces the list elements with repr() of
# the list elements, which is OK for latin characters # the list elements, which is OK for latin characters
@ -388,6 +394,9 @@ class ArgParser(object):
#errors in argument parsing ==> give cli error, no gui needed #errors in argument parsing ==> give cli error, no gui needed
return False return False
if len(self.removes) > 0:
return False
if self.list or self.list_more or self.list_table or self.help: if self.list or self.list_more or self.list_table or self.help:
return False return False

View File

@ -395,6 +395,9 @@ class CLIDbManager(object):
file.close() file.close()
if name == dbname: # currently exact match; could add re.match if name == dbname: # currently exact match; could add re.match
match_list.append(dirpath) match_list.append(dirpath)
if len(match_list) == 0:
CLIDbManager.ERROR("Family tree not found",
"No matching family tree found: '%s'" % dbname)
# now delete them: # now delete them:
for directory in match_list: for directory in match_list:
try: try:

View File

@ -313,6 +313,7 @@ LONGOPTS = [
"sm-config-prefix=", "sm-config-prefix=",
"sm-disable", "sm-disable",
"sync", "sync",
"remove=",
"usage", "usage",
"version", "version",
"qml", "qml",
@ -320,7 +321,7 @@ LONGOPTS = [
"quiet", "quiet",
] ]
SHORTOPTS = "O:C:i:e:f:a:p:d:c:lLthuv?syq" SHORTOPTS = "O:C:i:e:f:a:p:d:c:r:lLthuv?syq"
GRAMPS_UUID = uuid.UUID('516cd010-5a41-470f-99f8-eb22f1098ad6') GRAMPS_UUID = uuid.UUID('516cd010-5a41-470f-99f8-eb22f1098ad6')