diff --git a/gramps/cli/arghandler.py b/gramps/cli/arghandler.py index 4a07dba77..bb84fdd5a 100644 --- a/gramps/cli/arghandler.py +++ b/gramps/cli/arghandler.py @@ -407,7 +407,7 @@ class ArgHandler(object): # Handle the "--remove" Family Tree if self.removes: for name in self.removes: - self.dbman.remove_database(name) + self.dbman.remove_database(name, self.user) if should_exit: sys.exit(0) else: diff --git a/gramps/cli/argparser.py b/gramps/cli/argparser.py index 0ff80ef9c..a50171a0d 100644 --- a/gramps/cli/argparser.py +++ b/gramps/cli/argparser.py @@ -62,7 +62,7 @@ Application options -C, --create=FAMILY_TREE Create on open if new Family Tree -i, --import=FILENAME Import file -e, --export=FILENAME Export file - -r, --remove=FAMILY_TREE Remove a Family Tree + -r, --remove=FAMILY_TREE_PATTERN Remove matching Family Tree(s) -f, --format=FORMAT Specify Family Tree format -a, --action=ACTION Specify action -p, --options=OPTIONS_STRING Specify options @@ -138,7 +138,7 @@ class ArgParser(object): -C, --create=FAMILY_TREE Create on open if new Family Tree -i, --import=FILENAME Import file -e, --export=FILENAME Export file - -r, --remove=FAMILY_TREE Remove a Family Tree + -r, --remove=PATTERN Remove matching Family Tree(s) -f, --format=FORMAT Specify Family Tree format -a, --action=ACTION Specify action -p, --options=OPTIONS_STRING Specify options diff --git a/gramps/cli/clidbman.py b/gramps/cli/clidbman.py index 56adaa33d..4e3181499 100644 --- a/gramps/cli/clidbman.py +++ b/gramps/cli/clidbman.py @@ -30,6 +30,7 @@ creating, and deleting of databases. # Standard python modules # #------------------------------------------------------------------------- +import re import os import sys import time @@ -380,9 +381,10 @@ class CLIDbManager(object): return True return False - def remove_database(self, dbname): + def remove_database(self, dbname, user=None): """ - Deletes a database folder given its proper name. + Deletes a database folder given a pattenr that matches + its proper name. """ dbdir = os.path.expanduser(config.get('behavior.database-path')) match_list = [] @@ -393,21 +395,25 @@ class CLIDbManager(object): file = open(path_name, 'r', encoding='utf8') name = file.readline().strip() file.close() - if name == dbname: # currently exact match; could add re.match - match_list.append(dirpath) + if re.match("^" + dbname + "$", name): + match_list.append((name, dirpath)) if len(match_list) == 0: CLIDbManager.ERROR("Family tree not found", "No matching family tree found: '%s'" % dbname) # now delete them: - for directory in match_list: - try: - for (top, dirs, files) in os.walk(directory): - for filename in files: - os.unlink(os.path.join(top, filename)) - os.rmdir(directory) - except (IOError, OSError) as msg: - CLIDbManager.ERROR(_("Could not delete Family Tree"), - str(msg)) + for (name, directory) in match_list: + if user is None or user.prompt( + _('Remove family tree warning'), + _('Are you sure you want to remove the family tree named\n"%s"?' % name), + _('Yes'), _('No'), None): + try: + for (top, dirs, files) in os.walk(directory): + for filename in files: + os.unlink(os.path.join(top, filename)) + os.rmdir(directory) + except (IOError, OSError) as msg: + CLIDbManager.ERROR(_("Could not delete Family Tree"), + str(msg)) def rename_database(self, filepath, new_text): """