Пример #1
0
def run_api_timings(opts):
    import httplib
    from urllib import urlencode    
    couch = get_config().couches['local']
    c = httplib.HTTPConnection(couch['host'], couch['port'])
    tpath = '/%s/_api/inflow/%s'
    
    def make_req(path):
        c.request('GET', path)
        return c.getresponse()

    def do_timings(api, desc=None, **kw):
        api_path = tpath % (couch['name'], api)
        if kw:
            opts = kw.copy()
            for opt_name in opts:
                opts[opt_name] = json.dumps(opts[opt_name])
            api_path += "?" + urlencode(opts)
        resp, reqt = timeit(make_req, api_path)
        dat, respt = timeit(resp.read)
        if not desc:
            desc = api
        if resp.status != 200:
            print "*** api %r failed with %s: %s" % (desc, resp.status, resp.reason)
        print "Made '%s' API request in %.3f, read response in %.3f (size was %s)" \
              % (desc, reqt, respt, format_num_bytes(len(dat)))
        return json.loads(dat)

    result = do_timings("grouping/summary")
    for gs in result:
        title = gs.get('title') or gs['rd_key']
        do_timings("conversations/in_groups", "in_groups: " + str(title),
                   limit=60, message_limit=2, keys=[gs['rd_key']])
Пример #2
0
def show_info(parser, options):
    """Print a list of all extensions, loggers etc"""
    dm = model.get_doc_model()
    print "Database:"
    info = dm.db.infoDB()
    fmt = "  %(doc_count)d docs total, %(doc_del_count)d deleted, " \
          "update seq at %(update_seq)d, %(disk_size)d bytes."
    print fmt % info
    # ouch - this seems a painful way of fetching total unique keys?
    results = dm.open_view(
                startkey=["key"],
                endkey=["key", {}],
                group_level=2)
    print "  %d unique raindrop keys" % len(results['rows'])

    print "API groupings:"
    from urllib import urlencode
    dbconfig = get_config().couches['local']
    try:
        summaries = _call_api(dbconfig, "_api/inflow/grouping/summary")
        print " %d groupings exist" % len(summaries)
        for gs in summaries:
            title = gs.get('title') or gs['rd_key']
            opts = {'limit': 60, 'message_limit': 2,
                    'keys': json.dumps([gs['rd_key']]),
                    }
            path = "_api/inflow/conversations/in_groups?" + urlencode(opts)
            this = _call_api(dbconfig, path)
            print "  %s: %d conversations" % (title, len(this))
    except dm.db.Error, exc:
        print "Failed to call the API:", exc
Пример #3
0
 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)
Пример #4
0
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)