Created
November 28, 2011 17:48
-
-
Save reshefm/1401280 to your computer and use it in GitHub Desktop.
Get the views from couchdb to the file system in a directory structure that fits couchdbkit
This file contains 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
import urllib2 | |
import optparse | |
import json | |
import os | |
def main(): | |
def chdir_safe(path): | |
if not os.path.exists(path): | |
os.makedirs(path) | |
os.chdir(path) | |
parser = optparse.OptionParser() | |
parser.add_option('-s', '--server', default='http://0.0.0.0:5984') | |
parser.add_option('-d', '--database') | |
opts, args = parser.parse_args() | |
resp = urllib2.urlopen('%s/%s/_design/apps' % (opts.server, opts.database)) | |
design_doc = json.loads(resp.read()) | |
design_doc_id = design_doc['_id'] | |
chdir_safe('%s/views' % design_doc_id) | |
for view_name, view_code in design_doc['views'].items(): | |
chdir_safe(view_name) | |
with open('map.js', 'w') as map_func: | |
map_func.write(view_code['map']) | |
os.chdir('..') | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment