Purge command is now a method
authorFrederic Massart <fred@moodle.com>
Wed, 19 Sep 2012 09:05:25 +0000 (17:05 +0800)
committerFrederic Massart <fred@moodle.com>
Wed, 19 Sep 2012 09:05:25 +0000 (17:05 +0800)
lib/moodle.py
moodle-purge.py

index 39383c4..64aabc9 100644 (file)
@@ -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
index 1a3ad7a..2abb58e 100755 (executable)
@@ -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!')