Update cmd_rm.py : Ask user to confirm and add more exception handler
authorDonghoon Shin <dhs.shine@gmail.com>
Wed, 21 Sep 2016 22:31:39 +0000 (07:31 +0900)
committerDonghoon Shin <dhs.shine@gmail.com>
Wed, 21 Sep 2016 22:31:39 +0000 (07:31 +0900)
litmus/cmds/cmd_rm.py

index 1321f9d1b5cceec622b0536edd1f6b46842fae63..ca0d6364c4694209fa176ca8ccf1aeaa2e0f3554 100755 (executable)
@@ -24,8 +24,17 @@ def main(args):
     configparser.read(args.projects)
 
     if args.project in configparser.sections():
+
+        yn = input('Do you really want to remove {0}? (y/N) '
+                   .format(args.project))
+        if not yn or yn.capitalize().startswith('N'):
+            return
+
         path = configparser.get(args.project, 'path')
-        shutil.rmtree(path)
+        try:
+            shutil.rmtree(path)
+        except FileNotFoundError:
+            logging.debug('{0} does not exists'.format(path))
 
         configparser.remove_section(args.project)
         with open(args.projects, 'w') as f: