Command to purge cache
authorFrederic Massart <fred@moodle.com>
Fri, 31 Aug 2012 06:52:51 +0000 (14:52 +0800)
committerFrederic Massart <fred@moodle.com>
Fri, 31 Aug 2012 06:52:51 +0000 (14:52 +0800)
moodle-purge.py [new file with mode: 0755]

diff --git a/moodle-purge.py b/moodle-purge.py
new file mode 100755 (executable)
index 0000000..da93498
--- /dev/null
@@ -0,0 +1,48 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+"""
+Moodle Development Kit
+
+Copyright (c) 2012 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
+"""
+
+import sys
+import argparse
+from lib import config, workplace, moodle, tools
+from lib.tools import debug
+
+C = config.Conf().get
+Wp = workplace.Workplace()
+
+# Arguments
+parser = argparse.ArgumentParser(description='Purge an instance cache')
+parser.add_argument('name', metavar='name', default=None, nargs='?', help='name of the instance')
+args = parser.parse_args()
+
+M = Wp.resolve(args.name)
+if not M:
+    debug('This is not a Moodle instance')
+    sys.exit(1)
+
+try:
+       M.cli('admin/cli/purge_caches.php', stderr=None, stdout=None)
+except Exception as e:
+       debug(e)
+
+debug('Done.')