From: Stefan Kögl Date: Tue, 2 Jul 2013 14:20:32 +0000 (+0200) Subject: replace cleanup-views by couchdb-view-cleanup for all dbs X-Git-Url: https://repo.or.cz/w/mygpo.git/commitdiff_plain/1ea15be2ac07e2cac73e5827bf0552505d019f6b replace cleanup-views by couchdb-view-cleanup for all dbs --- diff --git a/bin/cleanup-views.sh b/bin/cleanup-views.sh deleted file mode 100755 index 93122806..00000000 --- a/bin/cleanup-views.sh +++ /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 index 00000000..9a454297 --- /dev/null +++ b/mygpo/db/couchdb/management/commands/couchdb-view-cleanup.py @@ -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() diff --git a/mygpo/db/couchdb/utils.py b/mygpo/db/couchdb/utils.py index 1e8f13b0..5ec44f99 100644 --- a/mygpo/db/couchdb/utils.py +++ b/mygpo/db/couchdb/utils.py @@ -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)