Exemplo n.º 1
0
 def connect(self):
     if self.client is None:
         self.client = CouchDB(self.username,
                               self.password,
                               url=self.url,
                               connect=True)
     self.db = self.client[self.database]
Exemplo n.º 2
0
 def setUp(self):
     """
     Set up test attributes for unit tests targeting a database
     """
     if os.environ.get('RUN_CLOUDANT_TESTS') is None:
         admin_party = False
         if (os.environ.get('ADMIN_PARTY')
                 and os.environ.get('ADMIN_PARTY') == 'true'):
             admin_party = True
         self.user = os.environ.get('DB_USER', None)
         self.pwd = os.environ.get('DB_PASSWORD', None)
         self.url = os.environ['DB_URL']
         self.client = CouchDB(self.user,
                               self.pwd,
                               admin_party,
                               url=self.url)
     else:
         self.account = os.environ.get('CLOUDANT_ACCOUNT')
         self.user = os.environ.get('DB_USER')
         self.pwd = os.environ.get('DB_PASSWORD')
         self.url = os.environ.get(
             'DB_URL', 'https://{0}.cloudant.com'.format(self.account))
         self.client = Cloudant(self.user,
                                self.pwd,
                                url=self.url,
                                x_cloudant_user=self.account)
Exemplo n.º 3
0
    def __init__(self,
                 uri='http://127.0.0.1:5984',
                 uuid_batch_count=DEFAULT_UUID_BATCH_COUNT):
        """ constructor for Server object

        @param uri: uri of CouchDb host
        @param uuid_batch_count: max of uuids to get in one time
        """

        if not uri or uri is None:
            raise ValueError("Server uri is missing")

        if uri.endswith("/"):
            uri = uri[:-1]

        url = urlparse(uri)
        if url.password is not None:
            # remove username and password from uri to reduce chances of
            # them showing up in logs
            uri = url._replace(netloc=url.netloc.rsplit('@', 1)[1]).geturl()
            params = {
                "user": url.username,
                "auth_token": url.password,
                "use_basic_auth": True,
            }
        else:
            params = {"user": "", "auth_token": "", "admin_party": True}

        self.uri = uri
        self.uuid_batch_count = uuid_batch_count
        self._uuid_batch_count = uuid_batch_count
        self._uuids = deque()
        self.cloudant_client = CouchDB(url=uri, connect=True, **params)
Exemplo n.º 4
0
def set_led():
    global wiringpi
    global DB_IP
    # 9
    content = request.form
    print(content['led_index'])

    # 10
    if int(content['led_index']) == 1:
        wiringpi.digitalWrite(LED_PIN_1, int(content['status']))  # 12
    elif int(content['led_index']) == 2:
        wiringpi.digitalWrite(LED_PIN_2, int(content['status']))  # 12

    # 13 -- DATABSE WRITE DOCUEMTENT --
    couch_client = CouchDB('admin',
                           'admin',
                           url='http://' + DB_IP + ':5984',
                           connect=True)
    log_db = couch_client['logs']
    doc = log_db.create_document({
        'action':
        "SET LED " + str(content['led_index']) + " BY USER TO " +
        str(content['status'])
    })
    couch_client.disconnect()

    return jsonify({'status': 'ok'})
Exemplo n.º 5
0
def _access_covidsafe_nums():
    client = CouchDB("admin",
                     "password",
                     url='http://172.26.131.173:5984',
                     connect=True)
    session = client.session()
    db = client['tweet-covid-covidsafe']

    #Connect a designdocument name covid
    ddoc = DesignDocument(db, 'covidsafe')
    total = 0
    view = View(ddoc, 'sentiment_location', partition_key='name')

    for i in view(reduce=True, group=True, group_level=1)['rows']:
        #print(i['value'])
        total = total + i['value']

    view = View(ddoc, 'sentiment_location', partition_key='geo')

    for i in view(reduce=True, group=True, group_level=1)['rows']:
        #print(i['value'])
        total = total + i['value']

    view = View(ddoc, 'sentiment_location', partition_key='none')

    for i in view(reduce=True, group=True, group_level=1)['rows']:
        #print(i['value'])
        total = total + i['value']

    return total
Exemplo n.º 6
0
 def __init__(self):
     client = CouchDB(os.environ['COUCHDB_USER'],
                      os.environ['COUCHDB_PASSWORD'],
                      url=os.environ['COUCHDB_HOST'],
                      connect=True,
                      auto_renew=True)
     self.db = client["leihlokal"]
Exemplo n.º 7
0
 def set_up_client(self, auto_connect=False, encoder=None):
     if os.environ.get('RUN_CLOUDANT_TESTS') is None:
         admin_party = False
         if (os.environ.get('ADMIN_PARTY')
                 and os.environ.get('ADMIN_PARTY') == 'true'):
             admin_party = True
         self.user = os.environ.get('DB_USER', None)
         self.pwd = os.environ.get('DB_PASSWORD', None)
         self.url = os.environ['DB_URL']
         self.client = CouchDB(self.user,
                               self.pwd,
                               admin_party,
                               url=self.url,
                               connect=auto_connect,
                               encoder=encoder)
     else:
         self.account = os.environ.get('CLOUDANT_ACCOUNT')
         self.user = os.environ.get('DB_USER')
         self.pwd = os.environ.get('DB_PASSWORD')
         self.url = os.environ.get(
             'DB_URL', 'https://{0}.cloudant.com'.format(self.account))
         self.client = Cloudant(self.user,
                                self.pwd,
                                url=self.url,
                                x_cloudant_user=self.account,
                                connect=auto_connect,
                                encoder=encoder)
Exemplo n.º 8
0
def db_cleanup(request):

    username = os.environ['USERNAME']
    password = os.environ['PASSWORD']
    url = os.environ['URL']

    client = CouchDB(username, password, url=url, connect=True)

    def remove_doc():
        try:
            db = client[DB_NAME]
            test_conf = db['test_doc']
            test_conf.delete()

            client.delete_database(DB_NAME)
            print("Deleted")
        except KeyError:
            print("Nothing to deleted")

    def db_shutdown():
        client.disconnect()

    remove_doc()

    request.addfinalizer(remove_doc)

    return client
Exemplo n.º 9
0
def view_covid(name, partition_key="", area_col="area_code", var_col="variable", val_col="count", reduce=True,
               group=True, group_level=2,
               docid="", dbname="",
               ip="", username="******", password="******", port=5984, connect=True):
    """
    View database
    """

    url = f"http://{ip}:{port}"
    client = CouchDB(username, password, url=url, connect=connect)
    db = client[dbname]  # database
    ddoc = DesignDocument(db, docid)

    # View
    view = View(ddoc, name, partition_key=partition_key)
    area_codes = []
    variables = []
    counts = []
    for row in view(reduce=reduce, group=group, group_level=group_level)['rows']:
        var, code = row["key"]  # variable, area code
        variables.append(var)
        area_codes.append(code)
        counts.append(row["value"])

    # Data
    data = pd.DataFrame(
        {area_col: map(str, area_codes), var_col: variables, val_col: counts})  # area code in geo-map string stype

    return data
Exemplo n.º 10
0
    def airports_inside(self, bounding_boxes):
        """
        Retrieves within the airports the given bounding boxes

        :param list bounding_boxes: boxes where airports are searched
        :returns: List of airports
        """
        airports = []
        try:
            client = CouchDB(None,
                             None,
                             url=self.server_url,
                             admin_party=True,
                             connect=True)
            db = cloudant.database.CloudantDatabase(client, self.db_name,
                                                    ROW_LIMIT)
            for bounding_box in bounding_boxes:
                query = self.create_query_string(bounding_box)
                optional_args = dict(query=query,
                                     include_docs=True,
                                     limit=ROW_LIMIT)
                is_query_finished = False
                while not is_query_finished:
                    resp = db.get_search_result(self.ddoc_id, self.index_name,
                                                **optional_args)
                    airports += resp["rows"]
                    optional_args.update({'bookmark': resp['bookmark']})
                    if 0 == len(resp['rows']):
                        is_query_finished = True
        finally:
            client.disconnect()
        return airports
Exemplo n.º 11
0
def connect():
    """
    Conect to the CouchDB server.
    """

    if __DB_ADDRESS  is None or \
       __DB_PASSWORD is None or \
       __DB_USERNAME is None:

        print("Database not initialized.")

        return None

    try:

        g._client = CouchDB(__DB_USERNAME,
                            __DB_PASSWORD,
                            url=__DB_ADDRESS + ':5984',
                            connect=True)

    except Exception as e:

        print("Error when connecting to database")

        pass
Exemplo n.º 12
0
 def _connect(self):
     self.log.debug("{!s} CONNECTING".format(self))
     self.client = CouchDB(self._auth[0],
                           self._auth[1],
                           url=self._couch_db_url,
                           connect=True,
                           auto_renew=True)
Exemplo n.º 13
0
def check_folder_for_files_from_tokens(task_id, dummy, number, **context):
    xcom_results = context['ti'].xcom_pull(task_ids=task_id)
    tokens = list(xcom_results['token_ids'])
    token_type = xcom_results['token_type']
    pc = picas_cred()
    client = CouchDB(pc.user,
                     pc.password,
                     url='https://picas-lofar.grid.surfsara.nl:6984',
                     connect=True)
    db = client[pc.database]
    tokenlist = TokenList(token_type=token_type, database=db)
    for token_id in tokens:
        tokenlist.append(
            caToken(database=db, token_type=token_type, token_id=token_id))
    tokenlist.fetch()
    for t in tokenlist:
        if t['status'] != 'done':
            raise RuntimeError(
                "Token {} is not in status 'done' but in status {}".format(
                    t['_id'], t['status']))
    print("All jobs in status 'done' ")
    locations = [t['Results_location'] for t in tokenlist]
    if len(locations) < number:
        print("Only {} files found!".format(len(locations)))
    for output_file in locations:
        c = subprocess.Popen(['uberftp', '-ls', output_file],
                             stdout=subprocess.PIPE,
                             stderr=subprocess.PIPE)
        out = c.communicate()
        if not out[0].decode().strip().split('\n')[0]:
            print("{} not found".format(output_file))
Exemplo n.º 14
0
    def getContextManager(self, isOnBoot=False):
        db_url = os.getenv("DB_URL")
        if db_url and db_url.strip() != "":
            creds = db_url.split("//")[1].split("@")[0].split(":")
            while self.down:
                try:
                    db = CouchDB(
                        creds[0],
                        creds[1],
                        url=db_url,
                        connect=True,
                        auto_renew=True,
                        timeout=20,
                    )
                    print("DATABASE UP: Database connection recovered.")
                    self.down = False
                    return db
                except Exception as e:

                    if self.test:
                        raise e

                    if isOnBoot:
                        print(e)
                        print(
                            "Database is not available on boot. Entering dead spin. No services online."
                        )
                        time.sleep(DEFAULT_CONTEXT_MANAGER_RETRY_WAIT)
                        self.down = True
                    else:
                        time.sleep(DEFAULT_CONTEXT_MANAGER_RETRY_WAIT)
        else:
            raise Exception("DB_URL not provided.")
Exemplo n.º 15
0
 def __init__(self):
     self.db_name = 'sensitive'
     self.db_client = CouchDB('admin',
                              'SHFJ3QrCBNJAq8pc47LnhxBLsaAfzu',
                              url='https://couchbk.stag.sensitve.app',
                              connect=True)
     self.db = self.db_client[self.db_name]
Exemplo n.º 16
0
def CreateDocHandler(req):
	if not req.body:
		glob.LOGGER("[MOD] Invalid Request: Null body")
		print("[MOD] Invalid Request: Null body")
		return HttpResponse(status=400)
	body = JSON.loads(req.body)
	if 'Whos_Asking' not in body or not body['Whos_Asking']:
		glob.LOGGER("[MOD] Invalid Request: Null Whos_Asking")
		print("[MOD] Invalid Request: Null Whos_Asking")
		return HttpResponse(status=400)
	if 'Password' not in body or not body['Password']:
		glob.LOGGER("[MOD] Invalid Request: Null Password")
		print("[MOD] Invalid Request: Null Password")
		return HttpResponse(status=400)
	if 'Database_Name' not in body or not body['Database_Name']:
		glob.LOGGER("[MOD] Invalid Request: Null database name")
		print("[MOD] Invalid Request: Null database name")
		return HttpResponse(status=400)
	if 'Populate' not in body or not body['Populate']:
		glob.LOGGER("[MOD] Invalid Request: Null Populate")
		print("[MOD] Invalid Request: Null Populate")
		return HttpResponse(status=400)
	
	glob.LOGGER("[MOD] Create Doc request by {} for {}".format(body['Whos_Asking'], body['Database_Name']))
	print("[MOD] Create Doc request by {} for {}".format(body['Whos_Asking'], body['Database_Name']))

	try:
		admin_couch_client = CouchDB(
			body['Whos_Asking'],
			body['Password'],
			url = glob.COUCH_HOST + ':' + glob.COUCH_PORT,
			connect = True
		)
		glob.LOGGER("[MOD] {} found".format(body[ 'Whos_Asking' ]))
		print("[MOD] {} found".format(body[ 'Whos_Asking' ]))
	except KeyError:
		glob.LOGGER("[MOD] Couch Admin {} not found".format(body[ 'Whos_Asking' ]))
		print("[MOD] Couch Admin {} not found".format(body[ 'Whos_Asking' ]))
		return HttpResponse(status=404)
	except Exception as err:
		glob.LOGGER("[MOD] Could not connect to couch as {} \n {}".format(body[ 'Whos_Asking' ], err))
		print("[MOD] Could not connect to couch as {} \n {}".format(body[ 'Whos_Asking' ], err))
		return HttpResponse(status=500)

	try:
		if type(body['Populate']).__name__ == 'list':
			if PopulateDatabase(admin_couch_client, body['Database_Name'], body['Populate']):
				return HttpResponse(status=201)
		elif type(body['Populate']).__name__ == 'dict':
			if PopulateDatabase(admin_couch_client, body['Database_Name'], [ body['Populate'] ]):
				return HttpResponse(status=201)
		else:
			glob.LOGGER("[MOD] Invalid data type of document {}".format(type(body['Populate']).__name__))
			print("[MOD] Invalid data type of document {}".format(type(body['Populate']).__name__))
			return HttpResponse(status=400)
	except Exception as err:
		glob.LOGGER("[MOD] Error @ Populate \n {}".format(err))
		print("[MOD] Error @ Populate \n {}".format(err))
		return HttpResponse(status=500)
Exemplo n.º 17
0
 def test_backoff_arg_Replay429Adapter(self):
     """
     Test constructing a new Replay429Adapter with a configured initial backoff.
     """
     self.client = CouchDB(self.user,
                           self.pwd,
                           url=self.url,
                           adapter=Replay429Adapter(initialBackoff=0.1))
Exemplo n.º 18
0
 def __init__(self, db_name):
     server_config = Config(CONFIG_PATH).get('couchdb')
     self.client = CouchDB(server_config['username'],
                           server_config['password'],
                           url=server_config['server_addr'],
                           connect=True,
                           auto_renew=True)
     self.select_db(db_name)
Exemplo n.º 19
0
 def test_new_Replay429Adapter(self):
     """
     Test that a new Replay429Adapter is accepted as a parameter for a client.
     """
     self.client = CouchDB(self.user,
                           self.pwd,
                           url=self.url,
                           adapter=Replay429Adapter())
Exemplo n.º 20
0
 def __init__(self, db_name):
     self.client = CouchDB(USERNAME, PASSWORD, url=URL, connect=True)
     self.db_name = db_name
     self.db = None
     try:
         self.db = self.client.create_database(self.db_name)
     except:
         self.db = self.client[self.db_name]
Exemplo n.º 21
0
 def test_retries_arg_Replay429Adapter(self):
     """
     Test constructing a new Replay429Adapter with a configured number of retries.
     """
     self.client = CouchDB(self.user,
                           self.pwd,
                           url=self.url,
                           adapter=Replay429Adapter(retries=10))
Exemplo n.º 22
0
def on_message(client, userdata, msg):
    """Call when a PUBLISH message is received from the server.

    Args:
        client ([type]): [description]
        userdata ([type]): [description]
        msg ([type]): [description]
    """
    try:
        reading = {}
        values = {}

        payload = str(msg.payload.decode("utf-8"))
        splittopic = msg.topic.split("/")
        deviceID = splittopic[1]
        topic = splittopic[2]

        # Set values. Return if it isn't the right topic to put in DB
        if topic == "moisture":
            values["moisture_level"] = payload
        elif topic == "availability":
            values["device_availability"] = payload
        elif topic == "reservoir":
            # If high moisture there is water. If low moisture there is not.
            if float(payload) >= 50.0:
                values["reservoir_empty"] = 0
            else:
                # empty
                values["reservoir_empty"] = 1
        elif topic == "pumpstatus":
            values["pump_status"] = payload
        else:
            return

        reading["type"] = topic
        reading["device_id"] = str(deviceID)
        reading["time_reading"] = int(time())
        reading["values"] = values

        print(reading)

    except Exception as e:
        print("Error processing message: " + str(e))

    # Connect to DB
    try:
        dbclient = CouchDB(environ.get("COUCHDB_USER"),
                           environ.get("COUCHDB_PASSWORD"),
                           url='http://db:5984',
                           connect=True)
        db = dbclient['plant_device_reading']
        document = db.create_document(reading)
        if document.exists():
            print("Added to DB.")
        dbclient.disconnect()

    except Exception as e:
        print("Error Writing to DB" + str(e))
Exemplo n.º 23
0
 def test_args_Replay429Adapter(self):
     """
     Test constructing a new Replay429Adapter with configured retries and initial backoff.
     """
     self.client = CouchDB(self.user,
                           self.pwd,
                           url=self.url,
                           adapter=Replay429Adapter(retries=10,
                                                    initialBackoff=0.01))
Exemplo n.º 24
0
def TruncateDBHandler(req):
	if not req.body:
		glob.LOGGER("[MOD] Invalid Request: Null body")
		print("[MOD] Invalid Request: Null body")
		return HttpResponse(status=400)
	body = JSON.loads(req.body)
	if 'Whos_Asking' not in body or not body['Whos_Asking']:
		glob.LOGGER("[MOD] Invalid Request: Null Whos_Asking")
		print("[MOD] Invalid Request: Null Whos_Asking")
		return HttpResponse(status=400)
	if 'Password' not in body or not body['Password']:
		glob.LOGGER("[MOD] Invalid Request: Null Password")
		print("[MOD] Invalid Request: Null Password")
		return HttpResponse(status=400)
	if 'Database_Name' not in body or not body['Database_Name']:
		glob.LOGGER("[MOD] Invalid Request: Null database name")
		print("[MOD] Invalid Request: Null database name")
		return HttpResponse(status=400)
	
	glob.LOGGER("[MOD] Truncate request by {} for {}".format(body['Whos_Asking'], body['Database_Name']))
	print("[MOD] Truncate request by {} for {}".format(body['Whos_Asking'], body['Database_Name']))
	
	try:
		admin_couch_client = CouchDB(
			body['Whos_Asking'],
			body['Password'],
			url = glob.COUCH_HOST + ':' + glob.COUCH_PORT,
			connect = True
		)
		glob.LOGGER("[MOD] {} found".format(body[ 'Whos_Asking' ]))
		print("[MOD] {} found".format(body[ 'Whos_Asking' ]))
	except KeyError:
		glob.LOGGER("[MOD] Couch Admin {} not found".format(body[ 'Whos_Asking' ]))
		print("[MOD] Couch Admin {} not found".format(body[ 'Whos_Asking' ]))
		return HttpResponse(status=404)
	except Exception as err:
		glob.LOGGER("[MOD] Could not connect to couch as {} \n {}".format(body[ 'Whos_Asking' ], err))
		print("[MOD] Could not connect to couch as {} \n {}".format(body[ 'Whos_Asking' ], err))
		return HttpResponse(status=500)

	try:
		if admin_couch_client[ str(body[ 'Database_Name' ]) ].exists():
			glob.LOGGER("[MOD] Database {} found".format(body[ 'Database_Name' ]))
			print("[MOD] Database {} found".format(body[ 'Database_Name' ]))
		for doc in admin_couch_client[ str(body[ 'Database_Name' ]) ]:
			doc.delete()
		glob.LOGGER("[MOD] Database {} truncated!".format(body[ 'Database_Name' ]))
		print("[MOD] Database {} truncated!".format(body[ 'Database_Name' ]))
		return HttpResponse(status=200)
	except KeyError:
		glob.LOGGER("[MOD] Database {} does not exist to truncate".format(body[ 'Database_Name' ]))
		print("[MOD] Database {} does not exist to truncate".format(body[ 'Database_Name' ]))
		return HttpResponse(status=404)
	except Exception as err:
		glob.LOGGER("[MOD] Error at checking existing DB {}".format(body[ 'Database_Name' ]))
		print("[MOD] Error at checking existing DB {}".format(body[ 'Database_Name' ]))
		return HttpResponse(status=500)
Exemplo n.º 25
0
def db_connect(db_name='testing3'):
    client = CouchDB("admin",
                     "admin",
                     url='http://127.0.0.1:5984',
                     connect=True)
    try:
        return client[db_name]
    except:
        return client.create_database(db_name)
Exemplo n.º 26
0
def connect() -> bool:
    global __client
    try:
        __client = CouchDB(user=cfg["DB_USERNAME"],
                           auth_token=cfg["DB_PASSWORD"],
                           url=cfg["DB_HOST_URL"],
                           connect=True)
    except:
        return False
    return True
Exemplo n.º 27
0
 def __init__(self, url=DB_URL):
     client = CouchDB(user=USERNAME,
                      auth_token=PASSWORD,
                      url=DB_URL,
                      connect=True,
                      auto_renew=True,
                      use_basic_auth=True)
     self.db = CouchDatabase(client,
                             DB_NAME,
                             fetch_limit=100,
                             partitioned=False)
Exemplo n.º 28
0
 def __init__(self, url):
   # logging.debug(url)
   import yurl
   # noinspection PyArgumentList
   parse_result = yurl.URL(url=url)
   import re
   url_without_credentials = re.sub(parse_result.username + ":" + parse_result.authorization, "", url)
   from cloudant.client import CouchDB
   self.client = CouchDB(user=parse_result.username, auth_token=parse_result.authorization,
                         url=url_without_credentials, connect=True, auto_renew=True)
   # logging.debug(self.client)
   assert self.client is not None, logging.error(self.client)
Exemplo n.º 29
0
def CreateDBHandler(req):
	if not req.body:
		glob.LOGGER("[MOD] Invalid Request: Null body")
		print("[MOD] Invalid Request: Null body")
		return HttpResponse(status=400)
	body = JSON.loads(req.body)
	if 'Whos_Asking' not in body or not body['Whos_Asking']:
		glob.LOGGER("[MOD] Invalid Request: Null Whos_Asking")
		print("[MOD] Invalid Request: Null Whos_Asking")
		return HttpResponse(status=400)
	if 'Password' not in body or not body['Password']:
		glob.LOGGER("[MOD] Invalid Request: Null Password")
		print("[MOD] Invalid Request: Null Password")
		return HttpResponse(status=400)
	if 'Database_Name' not in body or not body['Database_Name']:
		glob.LOGGER("[MOD] Invalid Request: Null database name")
		print("[MOD] Invalid Request: Null database name")
		return HttpResponse(status=400)

	glob.LOGGER("[MOD] Create DB request by {}".format(body['Whos_Asking']))
	print("[MOD] Create DB request by {}".format(body['Whos_Asking']))
	populate = body['Populate'] if 'Populate' in body and body['Populate'] is not None else False
	
	try:
		admin_couch_client = CouchDB(
			body['Whos_Asking'],
			body['Password'],
			url = glob.COUCH_HOST+':'+glob.COUCH_PORT,
			connect = True
		)
	except KeyError:
		glob.LOGGER("[MOD] Couch Admin not found")
		print("[MOD] Couch Admin not found")
		return HttpResponse(status=404)
	except Exception as err:
		glob.LOGGER("[MOD] Could not connect to couch as {} \n {}".format(body[ 'Whos_Asking' ], err))
		print("[MOD] Could not connect to couch as {} \n {}".format(body[ 'Whos_Asking' ], err))
		return HttpResponse(status=500)

	try:
		admin_couch_client[ str(body[ 'Database_Name' ]) ].exists()
		glob.LOGGER("[MOD] Database {} already exists".format(body[ 'Database_Name' ]))
		print("[MOD] Database {} already exists".format(body[ 'Database_Name' ]))
		return HttpResponse(status=406)
	except KeyError:
		glob.LOGGER("[MOD] Creating new {} database".format(body[ 'Database_Name' ]))
		print("[MOD] Creating new {} database".format(body[ 'Database_Name' ]))
		admin_couch_client.create_database(body[ 'Database_Name' ])
		if populate:
			if PopulateDatabase(admin_couch_client, body[ 'Database_Name' ], populate):
				return HttpResponse(status=200)
			else:
				return HttpResponse(status=500)
Exemplo n.º 30
0
def get_db_connection():
    client = CouchDB(config['DBUSER'],
                     config['DBPASS'],
                     url=config['COUCHDB'],
                     connect=True,
                     auto_renew=True)

    db = client[config['DBNAME']]
    try:
        yield db
    finally:
        client.disconnect()