def prepare_test_db(self, config): # change the name of the DB used. dbinfo = config.couches['local'] # then blindly nuke it. db = get_db('local', None) def _nuke_failed(failure, retries_left): # worm around a bug on windows in couch 0.9: # https://issues.apache.org/jira/browse/COUCHDB-326 # We just need to wait a little and try again... failure.trap(Error) if failure.value.status == '500' and retries_left: import time;time.sleep(0.1) return db.deleteDB(dbinfo['name'] ).addCallbacks(_nuked_ok, _nuke_failed, errbackArgs=(retries_left-1,) ) if failure.value.status != '404': failure.raiseException() def _nuked_ok(d): pass @defer.inlineCallbacks def del_non_test_accounts(result): # 'insert_default_docs' may have created an account (eg RSS) which # may get in the way of testing; nuke any which aren't in our # config. got = yield db.openView(dbinfo['name'], 'raindrop!content!all', 'megaview', key=['rd.core.content', 'schema_id', 'rd.account'], include_docs=True, reduce=False) wanted_ids = set(acct['id'] for acct in config.accounts.itervalues()) to_del = [{'_id': r['doc']['_id'], '_rev': r['doc']['_rev'], '_deleted': True, } for r in got['rows'] if r['doc']['id'] not in wanted_ids] _ = yield db.updateDocuments(dbinfo['name'], to_del) opts = self.get_options() return db.deleteDB(dbinfo['name'] ).addCallbacks(_nuked_ok, _nuke_failed, errbackArgs=(5,) ).addCallback(fab_db ).addCallback(bootstrap.check_accounts, config # client files are expensive (particularly dojo) and not # necessary yet... #).addCallback(bootstrap.install_client_files, opts #).addCallback(bootstrap.update_apps ).addCallback(bootstrap.insert_default_docs, opts ).addCallback(bootstrap.install_views, opts ).addCallback(del_non_test_accounts )
def gen_views(): for arg in args: # don't use open_view as then we'd need to parse the query portion! # grrr - just to get the dbname :() dbinfo = get_config().couches["local"] dbname = dbinfo["name"] if arg.startswith("/"): uri = "/%s/%s" % (dbname, arg) else: try: doc, rest = arg.split("/") except ValueError: parser.error("View name must be in the form design_doc_name/view") uri = "/%s/_design/%s/_view/%s" % (dbname, doc, rest) db = model.get_db() yield db.get(uri).addCallback(db.parseResult).addCallback(print_view, arg)
def prepare_test_db(self, config): # change the name of the DB used. dbinfo = config.couches['local'] # then blindly nuke it. db = get_db('local', dbinfo['name']) def del_non_test_accounts(): # 'insert_default_docs' may have created an account (eg RSS) which # may get in the way of testing; nuke any which aren't in our # config. got = db.openView('raindrop!content!all', 'megaview', key=['schema_id', 'rd.account'], include_docs=True, reduce=False) wanted_ids = set(acct['id'] for acct in config.accounts.itervalues()) to_del = [{'_id': r['doc']['_id'], '_rev': r['doc']['_rev'], '_deleted': True, } for r in got['rows'] if r['doc']['id'] not in wanted_ids] db.updateDocuments(to_del) db.deleteDB() fab_db() opts = self.get_options() bootstrap.install_views(opts, True) bootstrap.check_accounts(config) bootstrap.insert_default_docs(opts) del_non_test_accounts() if not getattr(self, 'no_sync_status_doc', False): # and make a dummy 'sync-status' doc so we don't attempt to send # welcome emails. items = {'new_items': 0, 'num_syncs': 2, } si = {'rd_key': ["raindrop", "sync-status"], 'rd_schema_id': 'rd.core.sync-status', 'rd_source': None, 'rd_ext_id': 'rd.core', 'items': items, } self.doc_model.create_schema_items([si])
def show_view(parser, options, args): """Pretty-print the result of executing a view. All arguments after this command are URLs to be executed as the view. If the view name starts with '/', the URL will be used as-is. This is suitable for builtin views - eg: show-view /_all_docs?limit=5 will fetch the first 5 results from the URL: http://[dbhost]/[dbname]/_all_docs?limit=5" whereas show-view my_design_doc/my_view?limit=5 will fetch the first 5 results from the URL http://[dbhost]/[dbname]/_design/my_design_doc/_view/my_view?limit=5 """ from pprint import pprint for arg in args: # don't use open_view as then we'd need to parse the query portion! # grrr - just to get the dbname :() dbinfo = get_config().couches['local'] dbname = dbinfo['name'] if arg.startswith("/"): uri = "/%s/%s" % (dbname, arg) else: try: doc, rest = arg.split("/") except ValueError: parser.error("View name must be in the form design_doc_name/view") uri = "/%s/_design/%s/_view/%s" % (dbname, doc, rest) db = model.get_db() result = db.get(uri) print "** view %r **" % arg pprint(result)
def __init__(self, name, host=None, port=None): self.name = name self.uri = "/" + quote(name) + "/" db = model.get_db("local", name) # this is a little hacky - we construct a doc_model with no DB self.doc_model = model.DocumentModel(db)