Example #1
0
    def Push_NonLock(self, dict_param):
        slice_unite = dict(SliceUniteParam)
        slice_unite['Type'] = 0
        slice_unite['SERVICE_NAME'] = dict_param.get('SERVICE_NAME')
        slice_unite['TimeSlice'] = dict_param.get('BEGIN_DATE')
        slice_unite['STAT'] = dict_param.get('STAT')
        slice_unite['TimeLen'] = dict_param.get('USED_TIME')
        slice_unite['BATCH_SEQID'] = dict_param.get('BATCH_SEQID')
        slice_unite['MAC_IP'] = dict_param.get('MAC_IP')
        key = self.__ToKey(dict_param.get('BEGIN_DATE'), dict_param.get('SERVICE_NAME'))

        obj_unite = self.__dict_slice.get(key)
        if obj_unite == None:
            # new a obj_unite
            try:
                self.__dict_slice[key] = CServiceSliceUnite(slice_unite)
            except:
                LOGError.error("New ServiceSliceUnite abort!")
                return -1

        else:
            # update the obj_unite
            self.__mutex.release()              # UnLock
            obj_unite.Update(slice_unite)
            self.__dict_slice[key] = obj_unite

        return 0
Example #2
0
 def DeleteData(self, condition):
     try:
         if type(condition) is not dict:
             LOGError.error("Input parameter is not illegal, please check!")
             sys.exit(1)
         self.__coll.delete_one(condition)
     except Exception,e:
         LOGError.error("some error happened: %s"%e)
Example #3
0
 def InsertData(self, DictData):
     try:
         if type(DictData) is not dict:
             LOGError.error("Input parameter is not illegal, please check!")
             sys.exit(1)
         self.__coll.insert_one(DictData)
     except Exception,e:
         print DictData
         LOGError.error("some error happened: %s"%e)
Example #4
0
 def FileOpen(self, str_fileName):
     if(str_fileName == ""):
         return -1
     try:
         self.__str_file = self.__Open(str_fileName)
         if self.__str_file == None:
             return -1
     except:
         LOGError.error("Open file faild!")
         return -1
     return 0
Example #5
0
    def __Push(self, key, slice_unite):
        self.__mutex.acquire()                  # Lock
        obj_unite = self.__dict_slice.get(key)
        if obj_unite == None:
            # new a obj_unite
            try:
                self.__dict_slice[key] = CServiceSliceUnite(slice_unite)
            except:
                self.__mutex.release()
                LOGError.error("New ServiceSliceUnite abort!")
                return -1

            self.__mutex.release()

        else:
            # update the obj_unite
            self.__mutex.release()              # UnLock
            obj_unite.Update(slice_unite)
        return 0
Example #6
0
    def FindData(self, ListData, condition):
        try:
            ListFindRet = []
            if type(condition) is not dict:
                LOGError.error("Input parameter is not illegal, please check!")
                sys.exit(1)
            findRets = self.__coll.find(condition)

            for rets in findRets:
                #find all the elements
                if [] == ListData:
                    ListFindRet.append(rets)
                    continue
                DictFindRet = {}
                for data in ListData:
                    if data in rets.keys():
                        DictFindRet[data] = rets[data]
                ListFindRet.append(DictFindRet)
            return ListFindRet
        except Exception,e:
            LOGError.error("some error happened: %s"%e)
Example #7
0
    def ReadSection(self):
        self.__str_list = []
        is_eof = False
        cur_session_id = ''
        try:
            pattern = re.compile(MATCH_SESSIONID)
            while (not is_eof):

                if self.__str_lastline == '':
                    self.__str_line = self.__str_file.readline()
                else:
                    self.__str_line = self.__str_lastline
                    self.__str_lastline = ''

                #print("Read:len=%s"%self.__str_line)

                if self.__str_line == '':           ### 判断文件是否结束
                    LOGDebug.debug("Reach end of file.")
                    is_eof = True
                    continue

                session_id_list = pattern.findall( self.__str_line)
                if len(session_id_list) > 0:        # 找到session_id
                    if session_id_list[0] != cur_session_id:
                        if cur_session_id == '':
                            cur_session_id = session_id_list[0]
                        else:
                            self.__str_lastline = self.__str_line
                            break
                    self.__str_list.append(self.__str_line)

        except EOFError:
            LOGError.error("End of File Error!")
        except:
            LOGError.error("Read file faild!")
            self.__str_file.close()
            return []
        return self.__str_list
Example #8
0
 def UpdateData(self, DictData, condition):
     try:
         if type(condition) is not dict:
             LOGError.error("Input parameter is not illegal, please check!")
             sys.exit(1)
         if type(DictData) is not dict:
             LOGError.error("Input parameter is not illegal, please check!")
             sys.exit(1)
         self.__coll.update_one(condition,{"$set":DictData})
     except Exception,e:
         LOGError.error("some error happened: %s"%e)
Example #9
0
 def ConnectDb(self):
     try:
         # before operation,check db is connect or not
         self.__conn = pymongo.MongoClient(self._host,27017)
         self.__db = self.__conn[self._dbName]
         if [] == self.__db.collection_names():
             LOGError.error("dbName is invalid!")
         elif self._tableName not in self.__db.collection_names():
             LOGError.error("collection is invalid!")
         else:
             self.__coll = self.__db[self._tableName]
     except Exception,e:
         LOGError.error("some error happened: "%e)
Example #10
0
 def FileClose(self):
     try:
         self.__str_file.close()
     except:
         LOGError.error("Close file faild!")