replace cleanup-views by couchdb-view-cleanup for all dbs
authorStefan Kögl <stefan@skoegl.net>
Tue, 2 Jul 2013 14:20:32 +0000 (2 16:20 +0200)
committerStefan Kögl <stefan@skoegl.net>
Tue, 2 Jul 2013 14:24:23 +0000 (2 16:24 +0200)
bin/cleanup-views.sh [deleted file]
mygpo/db/couchdb/management/commands/couchdb-view-cleanup.py [new file with mode: 0755]
mygpo/db/couchdb/utils.py

diff --git a/bin/cleanup-views.sh b/bin/cleanup-views.sh
deleted file mode 100755 (executable)
index 9312280..0000000
+++ /dev/null
@@ -1,7 +0,0 @@
-#!/bin/bash
-
-COUCHDB=`mygpo/print-couchdb.py`
-
-curl -s -H "Content-Type: application/json" -X POST $COUCHDB/_view_cleanup > /dev/null
-
-
diff --git a/mygpo/db/couchdb/management/commands/couchdb-view-cleanup.py b/mygpo/db/couchdb/management/commands/couchdb-view-cleanup.py
new file mode 100755 (executable)
index 0000000..9a45429
--- /dev/null
@@ -0,0 +1,10 @@
+from django.core.management.base import BaseCommand
+from mygpo.db.couchdb.utils import view_cleanup
+
+
+class Command(BaseCommand):
+    """ Sync design docs from filesystem """
+
+    def handle(self, *args, **options):
+
+        view_cleanup()
index 1e8f13b..5ec44f9 100644 (file)
@@ -102,3 +102,20 @@ def sync_design_docs():
             db = loading.get_db(label)
             loader = FileSystemDocsLoader(path)
             loader.sync(db, verbose=True)
+
+
+def view_cleanup():
+    """ do a view-cleanup for all databases """
+
+    logger.info('Doing view cleanup for all databases')
+    for label in settings.COUCHDB_DDOC_MAPPING.values():
+        logger.info('Doing view cleanup for database "%s"', label)
+        db = loading.get_db(label)
+        res = db.view_cleanup()
+
+        if res.get('ok', False):
+            log = logger.info
+        else:
+            log = logger.warn
+
+        log('Result of view cleanup for database "%s": %s', label, res)