Remove Command Object
authorFred <fmcell@gmail.com>
Mon, 4 Mar 2013 03:52:53 +0000 (11:52 +0800)
committerFred <fmcell@gmail.com>
Mon, 4 Mar 2013 03:52:53 +0000 (11:52 +0800)
lib/commands/__init__.py
lib/commands/remove.py [new file with mode: 0644]

index c094319..03c5a30 100644 (file)
@@ -37,3 +37,4 @@ from pull import PullCommand
 from purge import PurgeCommand
 from push import PushCommand
 from rebase import RebaseCommand
+from remove import RemoveCommand
diff --git a/lib/commands/remove.py b/lib/commands/remove.py
new file mode 100644 (file)
index 0000000..0280d81
--- /dev/null
@@ -0,0 +1,70 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+"""
+Moodle Development Kit
+
+Copyright (c) 2013 Frédéric Massart - FMCorz.net
+
+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
+the Free Software Foundation, either version 3 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+http://github.com/FMCorz/mdk
+"""
+
+from lib.command import Command
+from lib.tools import debug
+
+
+class RemoveCommand(Command):
+
+    _arguments = [
+        (
+            ['name'],
+            {
+                'help': 'name of the instance'
+            }
+        ),
+        (
+            ['-y'],
+            {
+                'action': 'store_true',
+                'dest': 'do',
+                'help': 'do not ask for confirmation'
+            }
+        )
+    ]
+    _description = 'Completely remove an instance'
+
+    def run(self, args):
+
+        try:
+            M = self.Wp.get(args.name)
+        except:
+            raise Exception('This is not a Moodle instance')
+
+        if not args.do:
+            confirm = raw_input('Are you sure? (Y/n) ')
+            if confirm != 'Y':
+                debug('Aborting...')
+                return
+
+        debug('Removing %s...' % args.name)
+        try:
+            self.Wp.delete(args.name)
+        except OSError:
+            raise Exception('Error while deleting the instance.\n' +
+                'This is probably a permission issue.\n' +
+                'Run: sudo chmod -R 0777 %s' % self.Wp.getPath(args.name))
+
+        debug('Instance removed')