Exemplo n.º 1
0
    def __init__(self, host, bucket_auth="default", logger=None):
        """
    Init and connect to a couchbase database.

    Args

    host <string> hostname (can include port separated by :)

    Keyword arguments
    
    bucket_auth <string> bucket to load with possibility of also providing a password delimited 
    by ":" - defaults to "default"
    logger <logger> python logger instance to log debug and info messages
    """

        try:

            # parse and store url information
            bucket_auth = bucket_auth.split(":")
            self.host = host
            self.bucket_name = bucket_auth[0]
            if len(bucket_auth) > 1:
                self.password = bucket_auth[1]
            self.log = logger

            # attempt to connect to database
            self.cb = Couchbase(self.host, self.bucket_name, self.password)

            # get bucket
            self.dbg("Setting bucket: %s" % self.bucket_name)
            self.bucket = self.cb.bucket(self.bucket_name)

        except:
            raise
Exemplo n.º 2
0
    def __init__(self, settings):

        server = settings['COUCHBASE_SERVER']
        bucket = settings['COUCHBASE_BUCKET']
        password = settings['COUCHBASE_PASSWORD']
        couchbase = Couchbase(server, bucket, password)
        self.bucket = couchbase[bucket]
Exemplo n.º 3
0
def main(global_config, **settings):
    """ This function returns a Pyramid WSGI application.
    """
    engine = engine_from_config(settings, 'sqlalchemy.')
    DBSession.configure(bind=engine)
    here = os.path.dirname(os.path.abspath(__file__))
    settings['mako.directories'] = os.path.join(here, 'templates')
    Base.metadata.bind = engine
    config = Configurator(settings=settings)
    config.add_static_view('static', 'static', cache_max_age=3600)
    config.include('pyramid_handlers')
    config.scan()
    config.add_handler('account', 'account/{action}', handler=Account)
    config.add_handler('item', 'item/{action}', handler=Item)
    config.add_handler('comment',
                       'comment/{action}',
                       handler=CommentController)
    config.add_handler('home', '/', handler=Home, action='index')
    cb = Couchbase(
        settings['couchbase.host'], settings['couchbase.bucket'],
        settings['couchbase.password'])[settings['couchbase.bucket']]
    models.couchbase = cb
    s3 = S3Connection(settings['aws.access_key'], settings['aws.secret_key'])
    models.s3 = s3
    return config.make_wsgi_app()
    def setUp(self):
        super(DesignDocTest, self).setUp()
        self.cb = Couchbase(self.host + ':' + self.port, self.username,
                            self.password)
        self.client = self.cb[self.bucket_name]
        self.rest = self.client.server._rest()
        if self.rest.couch_api_base is None:
            raise SkipTest

        self.ddoc = {
            "views": {
                "testing": {
                    "map": """function(doc, meta) {
                           if (meta.type === 'json' && doc.name) {
                             emit(doc.name, doc.num);
                           }
                        }""",
                    "reduce": "_count"
                }
            }
        }
        self.rest.create_design_doc(self.client.name, 'test_ddoc',
                                    json.dumps(self.ddoc))
        self.design_docs = self.client.design_docs()
Exemplo n.º 5
0
#!/usr/bin/env python
# -*- coding" utf-8 -*-

import os 
from couchbase.client import Couchbase
from blessings import Terminal
import json
import hashlib

# establish connection
couchbase = Couchbase("127.0.0.1:8091", "default", "")

# connect to default bucket
cb = couchbase["default"]


def parse_json( val ):
	vtype = type(val[2])
	if vtype is str:
		try:
			json_doc = json.loads(val[2])
			return json_doc
		except:
			print
			return val[2]
	
t = Terminal()

os.system('clear')
print t.bold_red("--------------------------------------------------------------------------")
print t.bold_red("Couchbase JSON Document Retrieve Operations")
Exemplo n.º 6
0
from couchbase.client import Couchbase
from blessings import Terminal

t = Terminal()

os.system('clear')
print t.bold_red(
    "--------------------------------------------------------------------------"
)
print t.bold_red("Couchbase Connections")
print t.bold_red(
    "--------------------------------------------------------------------------"
)
print

# establish connection
couchbase = Couchbase("127.0.0.1:8091", "default", "")

# set bucket object
cb = couchbase["default"]

print couchbase.servers

# establish connection to beer-sample
couchbase = Couchbase("127.0.0.1:8091", "beer-sample", "")

# set bucket instance
beers = couchbase["beer-sample"]

print couchbase.servers
print
 def get_bucket(self, bucket):
     if bucket not in self.buckets:
         self.buckets[bucket] = Couchbase(
             "%s:%s" % (self.server, self.port), bucket, "")[bucket]
     return self.buckets[bucket]
 def test_couchbase_object_construction_without_port(self):
     if self.port != "8091":
         raise SkipTest
     cb = Couchbase(self.host, self.username, self.password)
     self.assertIsInstance(cb.servers, types.ListType)
 def test_couchbase_object_construction(self):
     cb = Couchbase(self.host + ':' + self.port, self.username,
                    self.password)
     self.assertIsInstance(cb.servers, types.ListType)
Exemplo n.º 10
0
 def setup_cb(self):
     self.cb = Couchbase(self.host + ':' + self.port, self.username,
                         self.password)
Exemplo n.º 11
0
 def test_bucket_object_creation(self):
     cb = Couchbase(self.host + ':' + self.port, self.username,
                    self.password)
     bucket = Bucket(self.bucket_name, cb)
     self.assertIsInstance(bucket.server, Couchbase)
     self.assertIsInstance(bucket.mc_client, CouchbaseClient)
Exemplo n.º 12
0
 def setUp(self):
     super(BucketTest, self).setUp()
     self.cb = Couchbase(self.host + ':' + self.port, self.username,
                         self.password)
     self.client = self.cb[self.bucket_name]