Created
June 7, 2012 19:51
-
-
Save danfairs/2891161 to your computer and use it in GitHub Desktop.
couchapp dispatch
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def get_or_create_db(self, db_name, designs=ALL_DESIGNS): | |
from couchapp import dispatch | |
couchapp_dir = os.path.join( | |
settings.PROJECT_DIR, '..', '..', 'couchdb', 'tweet_counts' | |
) | |
server = couchdbkit.Server(uri=settings.COUCHDB_SERVER_URI, | |
resource_class=couchdb.RequestsResource) | |
db = server.get_db(db_name) | |
try: | |
db.info() | |
except couchdbkit.exceptions.ResourceNotFound: | |
db = server.create_db(db_name) | |
for design in designs: | |
db_path = '%s/%s' % (server.uri, db_name) | |
design_path = '%s/_design/%s' % (couchapp_dir, design) | |
dispatch.dispatch(('push', design_path, db_path)) | |
return db |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment