From: Frederic Massart Date: Wed, 9 Oct 2013 07:09:32 +0000 (+0800) Subject: New command to uninstall an instance X-Git-Tag: v0.5~3 X-Git-Url: https://git.cameron1729.xyz/?a=commitdiff_plain;h=0714f0bf2b16186e6bae0a5c476b4875470d5964;p=mdk.git New command to uninstall an instance --- diff --git a/README.md b/README.md index 837755a..2a08044 100644 --- a/README.md +++ b/README.md @@ -323,6 +323,13 @@ Gets some information about the issue on the tracker. Tester : Tim Barker (timb) ------------------------------------------------------------------------ + +uninstall +--------- + +Uninstall an instance: removes config file, drops the database, delete dataroot content, ... + + update ------ diff --git a/extra/bash_completion b/extra/bash_completion index d3fe715..ebf446b 100644 --- a/extra/bash_completion +++ b/extra/bash_completion @@ -61,7 +61,7 @@ function _mdk() { if [[ "${COMP_CWORD}" == 1 ]]; then # List the commands and aliases. # Ignoring these commands on purpose: init - OPTS="alias backport backup behat check config create fix info install phpunit plugin purge pull push rebase remove run update upgrade" + OPTS="alias backport backup behat check config create fix info install phpunit plugin purge pull push rebase remove run tracker uninstall update upgrade" OPTS="$OPTS $($BIN alias list 2> /dev/null | cut -d ':' -f 1)" else # List of options according to the command. diff --git a/lib/commands/__init__.py b/lib/commands/__init__.py index a019137..35de075 100644 --- a/lib/commands/__init__.py +++ b/lib/commands/__init__.py @@ -49,6 +49,7 @@ commandsList = [ 'remove', 'run', 'tracker', + 'uninstall', 'update', 'upgrade' ] diff --git a/lib/commands/uninstall.py b/lib/commands/uninstall.py new file mode 100644 index 0000000..ec17c5b --- /dev/null +++ b/lib/commands/uninstall.py @@ -0,0 +1,69 @@ +#!/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 +""" + +import logging +from lib.command import Command + + +class UninstallCommand(Command): + + _description = 'Uninstall a Moodle instance' + _arguments = [ + ( + ['name'], + { + 'default': None, + 'help': 'name of the instance', + 'metavar': 'name', + 'nargs': '?' + } + ), + ( + ['-y'], + { + 'action': 'store_true', + 'dest': 'do', + 'help': 'do not ask for confirmation' + } + ) + ] + + def run(self, args): + + M = self.Wp.resolve(args.name) + if not M: + raise Exception('This is not a Moodle instance') + elif not M.isInstalled(): + logging.info('This instance is not installed') + return + + if not args.do: + confirm = raw_input('Are you sure? (Y/n) ') + if confirm != 'Y': + logging.info('Aborting...') + return + + logging.info('Uninstalling %s...' % M.get('identifier')) + M.uninstall() + logging.info('Done.') diff --git a/lib/moodle.py b/lib/moodle.py index eb8919b..dcf9821 100644 --- a/lib/moodle.py +++ b/lib/moodle.py @@ -627,6 +627,31 @@ class Moodle(object): self.removeConfig(name) self.addConfig(name, value) + def uninstall(self): + """Uninstall the instance""" + + if not self.isInstalled(): + raise Exception('The instance is not installed') + + # Delete the content in moodledata + dataroot = self.get('dataroot') + if os.path.isdir(dataroot): + logging.debug('Deleting dataroot content (%s)' % (dataroot)) + shutil.rmtree(dataroot) + mkdir(dataroot, 0777) + + # Drop the database + dbname = self.get('dbname') + if self.dbo().dbexists(dbname): + logging.debug('Droping database (%s)' % (dbname)) + self.dbo().dropdb(dbname) + + # Remove the config file + configFile = os.path.join(self.get('path'), 'config.php') + if os.path.isfile(configFile): + logging.debug('Deleting config.php') + os.remove(configFile) + def updateTrackerGitInfo(self, branch=None, ref=None): """Updates the git info on the tracker issue"""