Exemple #1
0
    def parse(self):
        try:
            self.userid = self.doc[4]
            self.ts = self.doc[9]
            self.mediaid = self.doc[10]
            if self.version == "1.1":
                self.retention = int(self.doc[14]) / 1000
                self.vender = self.doc[12]
            elif self.version == "1.0":
                self.retention = int(self.doc[13]) / 1000
                self.vender = self.doc[10]
            else:
                err('Log_5010_Entry::parse() invalid version %s' %
                    self.version)
                return False

            if int(self.retention) > 10800:
                #if int(self.retention) > 86400:
                # invalid retention, maybe the retention was set to ts
                return False

        except Exception, e:
            import traceback
            debug(traceback.format_exc())
            debug("exception meet for Log_5011_Entry %s" % self.doc)
            #print traceback.format_exc()
            #print "exception meet for Log_5011_Entry %s"%self.doc
            return False
    def parse(self):
        try:
            self.userid = self.doc[4]
            self.ts = self.doc[9]
            self.mediaid = self.doc[10]
            if self.version == "1.1":
                self.retention = int(self.doc[14])/1000
                self.vender = self.doc[12]
            elif self.version == "1.0":
                self.retention = int(self.doc[13])/1000
                self.vender = self.doc[10]
            else:
                err('Log_5010_Entry::parse() invalid version %s'%self.version)
                return False
                
            if int(self.retention) > 10800:
            #if int(self.retention) > 86400:
                # invalid retention, maybe the retention was set to ts
                return False

        except Exception, e:
            import traceback
            debug(traceback.format_exc())
            debug("exception meet for Log_5011_Entry %s"%self.doc)
            #print traceback.format_exc()
            #print "exception meet for Log_5011_Entry %s"%self.doc
            return False
Exemple #3
0
 def connect(self, db_name):
     f = os.path.join(db_path, self.name)
     if not os.path.exists(f):
         err("cannot open database %s"%db_name)
         self.connected = False
         return False
     self.name = db_name
     self.connected = True
Exemple #4
0
 def _select(self, key):
     if not isinstance(key, dict):
         err("MySession::_select() invalid key type, dict is required")
         return None
     key = hash_key(key)
     value = self.entries.get(key, None)
     if value is None:
         return None
     return [key, value]
Exemple #5
0
 def __init__(self, dbname, tbname):
     self.dbname = dbname
     self.tbname = tbname
     f = os.path.join(db_path, self.dbname, self.tbname+".in")
     try:
         self.fd = open(f, 'r+')
         self.opened = True
     except Exception, e:
         err("fail to open file")
         self.opened = False
Exemple #6
0
 def open(self, table_name):
     if self.connected is False:
         err("database is not connected")
         return False
     f = os.path.join(db_path, self.name, table_name+".in")
     fd = None
     try:
         fd = open(f, "ra")
         fd.close()
     except Exception,e :
         print repr(e)
         return None
Exemple #7
0
 def parse(self):
     try:
         self.userid = self.doc[4]
         self.ts = self.doc[-5]
         if self.version == '1.0':
             self.vender = self.doc[-4]
         elif self.version == "1.1":
             self.vender = self.doc[-2]
         else:
             err('Log_5010_Entry::parse() invalid version %s'%self.version)
             return False
     except Exception, e:
         import traceback
         debug(traceback.format_exc())
         debug("exception meet for Log_5010_Entry %s"%self.doc)
         return False
Exemple #8
0
 def parse(self):
     try:
         self.userid = self.doc[4]
         self.ts = self.doc[-5]
         if self.version == '1.0':
             self.vender = self.doc[-4]
         elif self.version == "1.1":
             self.vender = self.doc[-2]
         else:
             err('Log_5010_Entry::parse() invalid version %s'%self.version)
             return False
     except Exception, e:
         import traceback
         debug(traceback.format_exc())
         debug("exception meet for Log_5010_Entry %s"%self.doc)
         return False
Exemple #9
0
    def insert(self, kwargs, to_update=True):
        if not isinstance(kwargs, dict):
            err("invalid data format for insert opeation")
            return -1

        for keyf in self.kfields:
            if keyf not in kwargs:
                err("required key(%s) not in input data"%(keyf))
                return -1

        params = {}
        for keyf in self.kfields:
            params[keyf] = kwargs[keyf]

        key = hash_key(params)
            
        if key in self.entries:
            #err("MySession::insert() key already exist for \"%s\""%key)
            if to_update is True:
                self.update(kwargs)
            return 1

        values = []
        for field in self.fields:
            if field not in kwargs:
                err("field (%s) not provided"%field)
                return 2
            values.append(str(kwargs[field]))
        self.entries[key] = values
        self._append_entry(values)
        return 0
Exemple #10
0
    def update(self, kwargs):
        if not isinstance(kwargs, dict):
            err("invalid data format for update opeation")
            return -1

        for keyf in self.kfields:
            if keyf not in kwargs:
                err("required key(%s) not in input data"%(keyf))
                return -1
        params = {}
        for keyf in self.kfields:
            params[keyf] = kwargs[keyf]

        key = hash_key(params)

        if key not in self.entries:
            err("key field not found (%s)"%key)
            return -1
        
        values = self.entries[key]
        need_update = False
        for i in range(len(self.fields)):
            field = self.fields[i]
            if field in self.kfields:
                continue
            if field not in kwargs:
                continue
            value = kwargs[field]
            if str(value) == values[i]:
                #warn('MySession::update() data no change for (%s)'%str(kwargs))
                continue
            values[i] = str(value)
            need_update = True
        if need_update is True:
            self._append_entry(values)
        return 0
Exemple #11
0
 def _flush_data(self):
     if self.opened is False:
         err("MySession::_append_entry() session is not opened")
         return False
     self.fd.flush()
Exemple #12
0
 def _append_entry(self, values):
     if self.opened is False:
         err("MySession::_append_entry() session is not opened")
         return False
     self.buffers.append(values)
Exemple #13
0
 def close(self):
     if self.opened == False:
         err("session %s already closed"%self.tbname)
         return False
     self.fd.close()
     self.opened = False