From 692adc243890ffcdabeb5fde738908e75d85f4fd Mon Sep 17 00:00:00 2001 From: Fred Date: Mon, 4 Mar 2013 11:52:53 +0800 Subject: [PATCH] Remove Command Object --- lib/commands/__init__.py | 1 + lib/commands/remove.py | 70 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 71 insertions(+) create mode 100644 lib/commands/remove.py diff --git a/lib/commands/__init__.py b/lib/commands/__init__.py index c094319..03c5a30 100644 --- a/lib/commands/__init__.py +++ b/lib/commands/__init__.py @@ -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 index 0000000..0280d81 --- /dev/null +++ b/lib/commands/remove.py @@ -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://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') -- 2.11.0