From 6f1ce05caa45d5ca15a931c5212ea4dfe179302d Mon Sep 17 00:00:00 2001 From: Frederic Massart Date: Wed, 19 Sep 2012 17:05:25 +0800 Subject: [PATCH] Purge command is now a method --- lib/moodle.py | 12 ++++++++++++ moodle-purge.py | 13 ++----------- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/lib/moodle.py b/lib/moodle.py index 39383c4..64aabc9 100644 --- a/lib/moodle.py +++ b/lib/moodle.py @@ -355,6 +355,18 @@ class Moodle(object): self._loaded = True return True + def purge(self): + """Purge the cache of an instance""" + if not self.isInstalled(): + raise Exception('Instance not installed, cannot purge.') + elif self.branch_compare('22', '<'): + raise Exception('Instance does not support cache purging.') + + try: + self.cli('admin/cli/purge_caches.php', stderr=None, stdout=None) + except Exception as e: + raise Exception('Error while purging cache!') + def reload(self): """Reloads the information""" self._loaded = False diff --git a/moodle-purge.py b/moodle-purge.py index 1a3ad7a..2abb58e 100755 --- a/moodle-purge.py +++ b/moodle-purge.py @@ -54,19 +54,10 @@ if len(Mlist) < 1: for M in Mlist: debug('Purging cache on %s' % (M.get('identifier'))) - if not M.isInstalled(): - debug('Instance not installed. Skipping...') - debug('') - continue - elif M.branch_compare('22', '<'): - debug('Instance does not support cache purging. Skipping...') - debug('') - continue - try: - M.cli('admin/cli/purge_caches.php', stderr=None, stdout=None) + M.purge() except Exception as e: - debug('Error while purging cache!') + debug(e) else: debug('Cache purged!') -- 2.11.0