def do_get_meta_attr(self): ret_obj = { "return_value" : 1, "return_desc" : "get-meta-attr failed" } query = {"_id":self.para.id} if self.is_exists(query) == 1: loginfo = "Cannot find the record which query is:" + bytes(query) print logfinfo self.log.info(loginfo) return ret_obj meta_string = self.db_collection.find_one(query) tmp_obj = meta_string #need to check if the key is exists for key in self.para.key.split("."): if common.is_key_in_dict(key, tmp_obj) != 0: loginfo = "the key:\"%s\" doesnot exists!" % (self.para.key) print loginfo self.log.info(loginfo) return ret_obj else: tmp_obj = tmp_obj[key] if type(tmp_obj) != dict: print tmp_obj else: if self.para.pretty == True: common.json_print_pretty(tmp_obj) else: common.json_print_string(tmp_obj) return ret_obj
def do_set_meta_all(self): ret_obj = { "return_value" : 1, "return_desc" : "get-meta-attr failed" } #check if the data is valid json string if common.is_valid_json(self.para.data) != 0: loginfo = "The data string is unvalid json string!" print loginfo self.log.info(loginfo) return ret_obj #字符编码转换 ss = common.json_dump(self.para.data) data_obj = common.json_load(ss) #check if _id is exists and the recored is exists if common.is_key_in_dict("_id", data_obj) == 0: loginfo = "the key _id cannot be exists in the data string" print loginfo self.log.info(loginfo) return ret_obj #override data_obj["_id"] data_obj["_id"] = self.para.id query = {"_id":self.para.id} if self.is_exists(query) != 0: loginfo = "The id \"%s\" doesnot in database" % (self.para.id) print loginfo self.log.info(loginfo) return ret_obj #这里比较危险可能,set-meta-all 的时候是先删除再insert self.db_collection.remove(query) #exec the sql ret = self.db_collection.insert(data_obj) if ret != self.para.id: print "update failed" return ret_obj else: ret_obj["return_value"] = 0 return ret_obj