Example #1
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
Example #2
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
Example #3
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
Example #4
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