Moodle command to remove an instance
authorFred <fmcell@gmail.com>
Sun, 29 Jul 2012 15:25:12 +0000 (23:25 +0800)
committerFred <fmcell@gmail.com>
Sun, 29 Jul 2012 15:25:12 +0000 (23:25 +0800)
moodle-remove.py [new file with mode: 0644]

diff --git a/moodle-remove.py b/moodle-remove.py
new file mode 100644 (file)
index 0000000..ba77579
--- /dev/null
@@ -0,0 +1,34 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+import os
+import sys
+import argparse
+
+from lib import config, tools, workplace
+from lib.tools import debug
+
+C = config.Conf().get
+
+# Arguments
+parser = argparse.ArgumentParser(description='Completely remove an instance')
+parser.add_argument('name', help='name of the instance')
+parser.add_argument('-y', action='store_true', help='do not ask for confirmation', dest='do')
+args = parser.parse_args()
+
+Wp = workplace.Workplace()
+try:
+       M = Wp.get(args.name)
+except:
+       debug('This is not a Moodle instance')
+       sys.exit(1)
+
+if not args.do:
+       confirm = raw_input('Are you sure? (Y/n) ')
+       if confirm != 'Y':
+               debug('Exiting...')
+               sys.exit(0)
+
+debug('Removing %s...' % args.name)
+Wp.delete(args.name)
+debug('Instance removed')