Пример #1
0
    def getport(self, eventid):
        """get port or insert data."""
        cdb = ThreadSafeDatabase(self._DATABASE)
        if cdb.exists():
            cdb.open()
            cdb.reindex()
            try:
                print eventid
                record_dict = cdb.get('eventid', eventid, with_doc=True, with_storage=True)
                record = record_dict['doc']
                cdb.close()
                return record['port']

            except RecordNotFound:
                print "Record not Found"
                self.dict['eventid'] = eventid
                cdb.insert(self.dict)
                cdb.close()
                return None

        else:
            cdb.create()
            cdb.add_index(CustomEventidIndex(cdb.path, "eventid"))
            self.dict['eventid'] = eventid
            cdb.insert(self.dict)
            cdb.close()
            return None
Пример #2
0
 def insert_data(cls, eventid, key, value):
     """insert data."""
     cdb = ThreadSafeDatabase(cls._DATABASE)
     status = False
     if cdb.exists():
         cdb.open()
         cdb.reindex()
     try:
         record_dict = cdb.get('eventid', eventid, with_doc=True, with_storage=False)
         record = record_dict['doc']
         cdb.update({key: value, "server": record['server'], "eventid": eventid, '_id': record['_id'], '_rev': record['_rev']})
         status = True
     except RecordNotFound:
         status = False
     except:
         status = False
     finally:
         cdb.close()
         return status
Пример #3
0
class DBObject(object):

    def __init__(self, filename=None):
        """

        :param filename:
        :return:
        """
        self.db = Database(filename)
        if self.db.exists():
            self._open_db()
            self.db.reindex()
        else:
            self.db.create()

    def _open_db(self):
        try:
            self.db.open()
        except DatabaseConflict:
            pass

    def save(self, info=None):
        """

        :param info:
        :return:
        """
        if info is None:
            raise MissingPropertyException("info must not be None!")
        self._open_db()
        self.db.insert(info)

    def reindex(self):
        """
        Does a reindex of the database.
        :return:
        """
        self._open_db()
        self.db.reindex()

    def list_all(self):
        return self.db.all("id")
Пример #4
0
 def delete_data(cls, eventid):
     """delete data."""
     cdb = ThreadSafeDatabase(cls._DATABASE)
     status = False
     if cdb.exists():
         cdb.open()
         cdb.reindex()
     try:
         record_dict = cdb.get('eventid', eventid, with_doc=True, with_storage=True)
         record = record_dict['doc']
         cdb.delete({'_id': record['_id'], '_rev': record['_rev']})
         status = True
     except RecordNotFound:
         print "Record not Found"
         status = False
     except:
         print "Error"
         status = False
     finally:
         cdb.close()
         return status
Пример #5
0
 def get_data(cls, eventid, key):
     """get data."""
     cdb = ThreadSafeDatabase(cls._DATABASE)
     return_data = None
     if cdb.exists():
         cdb.open()
         cdb.reindex()
     try:
         print eventid
         record_dict = cdb.get('eventid', eventid, with_doc=True, with_storage=True)
         print record_dict
         record = record_dict['doc']
         return_data = record[key]
         print record
     except RecordNotFound:
         print "Record not Found"
         return_data = None
     except:
         print "Error"
         return_data = None
     finally:
         cdb.close()
         return return_data
Пример #6
0
#!/usr/bin/env python

from CodernityDB.database import Database
from CodernityDB.hash_index import HashIndex

from CodernityDB.database_thread_safe import ThreadSafeDatabase
from CodernityDB.database import RecordNotFound

import time

cdb = ThreadSafeDatabase('database')
#db = Database('database')
if cdb.exists():
    cdb.open()
    cdb.reindex()
else:
    #from database_indexes import UserIndex, MessageAllIndex, MessageUserIndex, FollowerRel1Index, FollowerRel2Index, UserIDIndex, FollowerIndex
    print("no database pressent")
    quit()

print cdb.count(cdb.all, 'eventid')
insert_dict = {"eventid": "123" , "port": "0", "server": "127.0.0.1" }
cdb.insert(insert_dict)
try:
    print "tesit"
    rv = cdb.get('eventid', '123', with_doc=True, with_storage=True)
    # rv= user['doc']['pw_hash']
except RecordNotFound:
    rv = None
else:
    #time.sleep(20)