Best Python code snippet using molotov_python
content_cfg_worker.py
Source:content_cfg_worker.py
...51 result.description = err_code_mgr.get_error_msg(err_code_mgr.ERR_PORTAL_DESERIALIZE_ERROR,52 cmd = 'PORTAL_CONTENT_ARTICLE_CREATE',53 param_name = 'PortalContentArticleCreateReq')54 result.user_session = ''55 self.get_worker().get_app().send_ack_dispatch(frame, (result.serialize(), ))56 return57 58 if article_cfg.title is None or len(article_cfg.title) == 0 or article_cfg.pic_url is None or len(article_cfg.pic_url) == 0 or article_cfg.content is None or len(article_cfg.content) == 0:59 result.return_code = err_code_mgr.ERR_PORTAL_ARTICLE_PARAMS_INVALID60 result.description = err_code_mgr.get_error_msg(err_code_mgr.ERR_PORTAL_ARTICLE_PARAMS_INVALID)61 result.prepare_for_ack(article_cfg, result.return_code, result.description)62 self.get_worker().get_app().send_ack_dispatch(frame, (result.serialize(), ))63 return64 65 article_moc = self.get_worker().get_app().get_mit_manager().gen_rdm("Article")66 article_moc.article_id = self.get_worker().get_app().get_article_no_creator().get_new_no()67 self._article_id = article_moc.article_id68 69 article_moc.title = article_cfg.title70 article_moc.description = article_cfg.description71 article_moc.subject_id = int(article_cfg.subject_id)72 article_moc.pic_url = self.get_worker().update_url(article_cfg.pic_url)73 content_url = "%s/%s" % (article_cfg.content_url, article_moc.article_id)74 article_moc.content_url = self.get_worker().update_url(content_url)75 article_moc.content = article_cfg.content76 article_moc.push_timer = article_cfg.push_timer77 article_moc.push_times = article_cfg.push_times78 article_moc.counter = 079 80 ret = self.get_worker().get_app().get_mit_manager().rdm_add(article_moc)81 82 if ret.get_err_code() == err_code_mgr.ER_OBJECT_ADD_CONFLICT:83 result.return_code = err_code_mgr.ERR_PORTAL_ARTICLE_RECORDS_FULL84 result.description = err_code_mgr.get_error_msg(err_code_mgr.ERR_PORTAL_ARTICLE_RECORDS_FULL)85 result.prepare_for_ack(article_cfg, result.return_code, result.description)86 self.get_worker().get_app().send_ack_dispatch(frame, (result.serialize(), ))87 return88 89 elif ret.get_err_code() != 0:90 result.return_code = ret.get_err_code()91 result.description = ret.get_msg()92 93 result.prepare_for_ack(article_cfg, result.return_code, result.description)94 self.get_worker().get_app().send_ack_dispatch(frame, (result.serialize(), ))95 return96 gids = msg_params_def.GroupList()97 gids.group_ids = [int(gid) for gid in article_cfg.sub_group_ids] 98 99 mo_id = self.get_worker().get_app().get_mit_manager().gen_moid("Article", article_id = self._article_id)100 self.get_worker().get_app().get_mit_manager().mod_complex_attr('Article', 101 moid = mo_id, 102 group_ids = gids)103 104 if article_moc.push_timer is not None and len(article_moc.push_timer) > 0:105 if article_moc.push_times is None or len(article_moc.push_times) == 0:106 times = 1107 else:108 times = int(article_moc.push_times)109 time_stru = time.strptime(article_moc.push_timer, '%Y-%m-%d %H:%M:%S')110 abs_time = time.mktime(time_stru) 111 112 self.get_worker().get_app().get_push_task_manager().del_task(msg_params_def.PORTAL_TASK_PUSH_ARTICLE,113 article_moc.article_id)114 self.get_worker().get_app().get_push_task_manager().add_task(msg_params_def.PORTAL_TASK_PUSH_ARTICLE,115 abs_time, 116 times,117 article_moc.article_id)118 new_frame = bf.AppFrame()119 new_frame.set_cmd_code(cmd_code_def.CLOUD_PORTAL_CONTENT_UPDATE_MSG)120 self.get_worker().get_app().dispatch_frame_to_process_by_pid(self.get_worker().get_pid("SubscriberManApp"), new_frame) 121 122 if frame.get_sender_pid() == self.get_worker().get_pid('WebGate'):123 # ¸øWEB»Ø³É¹¦ÏìÓ¦124 result.return_code = err_code_mgr.ER_SUCCESS125 result.description = err_code_mgr.get_error_msg(err_code_mgr.ER_SUCCESS) 126 result.prepare_for_ack(article_cfg, result.return_code, result.description)127 128 self.get_worker().get_app().send_ack_dispatch(frame, (result.serialize(), ))129 130 if article_cfg.pic_url != '':131 create_frame = bf.AppFrame()132 create_frame.set_cmd_code(cmd_code_def.CLOUD_PORTAL_ARTICLE_UPLOAD_MSG)133 create_frame.set_receiver_pid(self.get_worker().get_pid('SubscriberManApp'))134 create_frame.add_data(msg_params_def.PORTAL_CLOUD_IMAGE_UPLOAD_NEW)135 create_frame.add_data(str(self._article_id))136 self.get_worker().get_app().dispatch_frame_to_process_by_pid(self.get_worker().get_pid("SubscriberManApp"), create_frame) 137 138 # ·¢Ë͹ؼü²Ù×÷ʼþ֪ͨ139 oper_type = msg_params_def.EVENT_PORTAL_OPERATION_ADD + msg_params_def.EVENT_PORTAL_OBJECT_ARTICLE140 self.get_worker().get_app().send_portal_operation_event(article_cfg.user_session, oper_type.decode('gbk').encode('utf-8'), article_cfg.title)141class PortalContentArticleModifyHandler(bf.CmdHandler):142 """143 Class: PortalContentArticleModifyHandler144 Description: PortalÏ·¢µÄÐÞ¸ÄÖ÷ÌâÎÄÕµÄÃüÁîhandler145 Base: CmdHandler146 Others: 147 """148 def handle_cmd(self, frame):149 """150 Method: handle_cmd151 Description: ´¦ÀíÐÞ¸ÄÖ÷ÌâÎÄÕµÄÃüÁîÏûÏ¢152 Parameter: 153 frame: AppFrame154 Return: 155 Others: 156 """157 tracelog.info(self)158 159 result = basic_rep_to_web.BasicRepToWeb()160 result.init_all_attr()161 tracelog.info('content man worker recv article frame: %s' % frame)162 buf = frame.get_data()163 164 try:165 article_mod = msg_params_def.PortalContentArticleModReq.deserialize(buf)166 except:167 result.return_code = err_code_mgr.ERR_PORTAL_DESERIALIZE_ERROR168 result.description = err_code_mgr.get_error_msg(err_code_mgr.ERR_PORTAL_DESERIALIZE_ERROR,169 cmd = 'PORTAL_CONTENT_ARTICLE_MODIFY',170 param_name = 'PortalContentArticleModReq')171 result.user_session = ''172 self.get_worker().get_app().send_ack_dispatch(frame, (result.serialize(), ))173 return174 if article_mod.title is None or len(article_mod.title) == 0 or article_mod.pic_url is None or len(article_mod.pic_url) == 0 or article_mod.content is None or len(article_mod.content) == 0:175 result.return_code = err_code_mgr.ERR_PORTAL_ARTICLE_PARAMS_INVALID176 result.description = err_code_mgr.get_error_msg(err_code_mgr.ERR_PORTAL_ARTICLE_PARAMS_INVALID)177 result.prepare_for_ack(article_mod, result.return_code, result.description)178 self.get_worker().get_app().send_ack_dispatch(frame, (result.serialize(), ))179 return180 181 self._article_id = int(article_mod.article_id)182 article_moc = self.get_worker().get_app().get_mit_manager().rdm_find("Article", article_id = self._article_id)183 if len(article_moc) == 0:184 result.return_code = err_code_mgr.ERR_PORTAL_ARTICLE_NOT_EXISTS185 result.description = err_code_mgr.get_error_msg(err_code_mgr.ERR_PORTAL_ARTICLE_NOT_EXISTS)186 result.prepare_for_ack(article_mod, result.return_code, result.description)187 self.get_worker().get_app().send_ack_dispatch(frame, (result.serialize(), ))188 return189 190 article_moc[0].title = article_mod.title191 article_moc[0].description = article_mod.description192 article_moc[0].subject_id = int(article_mod.subject_id)193 article_moc[0].pic_url = self.get_worker().update_url(article_mod.pic_url)194 article_moc[0].content = article_mod.content195 article_moc[0].push_timer = article_mod.push_timer196 article_moc[0].push_times = article_mod.push_times197 198 ret = self.get_worker().get_app().get_mit_manager().rdm_mod(article_moc[0])199 200 if ret.get_err_code() != 0:201 result.return_code = ret.get_err_code()202 result.description = ret.get_msg()203 204 result.prepare_for_ack(article_mod, result.return_code, result.description)205 self.get_worker().get_app().send_ack_dispatch(frame, (result.serialize(), ))206 return207 gids = msg_params_def.GroupList()208 gids.group_ids = [int(gid) for gid in article_mod.sub_group_ids] 209 210 mo_id = self.get_worker().get_app().get_mit_manager().gen_moid("Article", article_id = self._article_id)211 self.get_worker().get_app().get_mit_manager().mod_complex_attr('Article', 212 moid = mo_id, 213 group_ids = gids)214 if article_moc[0].push_timer is not None and len(article_moc[0].push_timer) > 0:215 if article_moc[0].push_times is None or len(article_moc[0].push_times) == 0:216 times = 1217 else:218 times = int(article_moc[0].push_times)219 time_stru = time.strptime(article_moc[0].push_timer, '%Y-%m-%d %H:%M:%S')220 abs_time = time.mktime(time_stru)221 222 self.get_worker().get_app().get_push_task_manager().del_task(msg_params_def.PORTAL_TASK_PUSH_ARTICLE,223 article_moc[0].article_id)224 self.get_worker().get_app().get_push_task_manager().add_task(msg_params_def.PORTAL_TASK_PUSH_ARTICLE,225 abs_time, 226 times,227 article_moc[0].article_id)228 new_frame = bf.AppFrame()229 new_frame.set_cmd_code(cmd_code_def.CLOUD_PORTAL_CONTENT_UPDATE_MSG)230 self.get_worker().get_app().dispatch_frame_to_process_by_pid(self.get_worker().get_pid("SubscriberManApp"), new_frame) 231 232 # ¸øWEB»Ø³É¹¦ÏìÓ¦233 result.return_code = err_code_mgr.ER_SUCCESS234 result.description = err_code_mgr.get_error_msg(err_code_mgr.ER_SUCCESS) 235 result.prepare_for_ack(article_mod, result.return_code, result.description)236 self.get_worker().get_app().send_ack_dispatch(frame, (result.serialize(), ))237 if article_mod.pic_url != '':238 mod_frame = bf.AppFrame()239 mod_frame.set_cmd_code(cmd_code_def.CLOUD_PORTAL_ARTICLE_UPLOAD_MSG)240 mod_frame.set_receiver_pid(self.get_worker().get_pid('SubscriberManApp'))241 mod_frame.add_data(msg_params_def.PORTAL_CLOUD_IMAGE_UPLOAD_MOD)242 mod_frame.add_data(str(self._article_id))243 self.get_worker().get_app().dispatch_frame_to_process_by_pid(self.get_worker().get_pid("SubscriberManApp"), mod_frame) 244 245 # ·¢Ë͹ؼü²Ù×÷ʼþ֪ͨ246 oper_type = msg_params_def.EVENT_PORTAL_OPERATION_MOD + msg_params_def.EVENT_PORTAL_OBJECT_ARTICLE247 self.get_worker().get_app().send_portal_operation_event(article_mod.user_session, oper_type.decode('gbk').encode('utf-8'), article_mod.title)248class PortalContentArticleRemoveHandler(bf.CmdHandler):249 """250 Class: PortalContentArticleRemoveHandler251 Description: PortalÏ·¢µÄɾ³ýÖ÷ÌâÎÄÕµÄÃüÁîhandler252 Base: CmdHandler253 Others: 254 """255 def handle_cmd(self, frame):256 """257 Method: handle_cmd258 Description: ´¦Àíɾ³ýÖ÷ÌâÎÄÕµÄÃüÁîÏûÏ¢259 Parameter: 260 frame: AppFrame261 Return: 262 Others: 263 """264 tracelog.info(self)265 266 result = basic_rep_to_web.BasicRepToWeb()267 result.init_all_attr()268 tracelog.info('content man worker recv article frame: %s' % frame)269 buf = frame.get_data()270 271 try:272 article_rmv = msg_params_def.PortalContentArticleRemoveReq.deserialize(buf)273 except:274 result.return_code = err_code_mgr.ERR_PORTAL_DESERIALIZE_ERROR275 result.description = err_code_mgr.get_error_msg(err_code_mgr.ERR_PORTAL_DESERIALIZE_ERROR,276 cmd = 'PORTAL_CONTENT_ARTICLE_REMOVE',277 param_name = 'PortalContentArticleRemoveReq')278 result.user_session = ''279 self.get_worker().get_app().send_ack_dispatch(frame, (result.serialize(), ))280 return281 articles = self.get_worker().get_app().get_mit_manager().rdm_find(moc_name = "Article", article_id = int(article_rmv.article_id))282 if len(articles) == 1:283 wx_news_id = articles[0].wx_news_id 284 # ɾ³ý±¾µØͼƬÎļþ285 if articles[0].pic_url.find(msg_params_def.PORTAL_LOGO_IMG_FILE_LOCAL_PATH) < 0 and articles[0].pic_url.find(msg_params_def.WX_HEAD_IMG_FILE_SAVE_LOCAL_PATH) < 0:286 try:287 pic_url = articles[0].pic_url.strip('http://')288 pic_path = msg_params_def.PORTAL_IMG_FILE_LOCAL_PATH_PREFIX + pic_url[pic_url.find('/'):].lstrip('/')289 os.remove(pic_path)290 except Exception, e:291 tracelog.error('del img file(%s) in local path failed(%s)' % (pic_path, e))292 293 title = articles[0].title 294 self.get_worker().get_app().get_mit_manager().rdm_remove(articles[0])295 self.get_worker().get_app().get_push_task_manager().del_task(msg_params_def.PORTAL_TASK_PUSH_ARTICLE,296 int(article_rmv.article_id))297 new_frame = bf.AppFrame()298 new_frame.set_cmd_code(cmd_code_def.CLOUD_PORTAL_CONTENT_UPDATE_MSG)299 self.get_worker().get_app().dispatch_frame_to_process_by_pid(self.get_worker().get_pid("SubscriberManApp"), new_frame) 300 # ¸øWEB»Ø³É¹¦ÏìÓ¦301 result.return_code = err_code_mgr.ER_SUCCESS302 result.description = err_code_mgr.get_error_msg(err_code_mgr.ER_SUCCESS) 303 result.prepare_for_ack(article_rmv, result.return_code, result.description)304 self.get_worker().get_app().send_ack_dispatch(frame, (result.serialize(), ))305 del_frame = bf.AppFrame()306 del_frame.set_cmd_code(cmd_code_def.CLOUD_PORTAL_ARTICLE_UPLOAD_MSG)307 del_frame.set_receiver_pid(self.get_worker().get_pid('SubscriberManApp'))308 del_frame.add_data(msg_params_def.PORTAL_CLOUD_IMAGE_UPLOAD_DEL)309 del_frame.add_data(str(article_rmv.article_id))310 del_frame.add_data(wx_news_id)311 312 self.get_worker().get_app().dispatch_frame_to_process_by_pid(self.get_worker().get_pid("SubscriberManApp"), del_frame) 313 # ·¢Ë͹ؼü²Ù×÷ʼþ֪ͨ314 oper_type = msg_params_def.EVENT_PORTAL_OPERATION_DEL + msg_params_def.EVENT_PORTAL_OBJECT_ARTICLE315 self.get_worker().get_app().send_portal_operation_event(article_rmv.user_session, oper_type.decode('gbk').encode('utf-8'), title)316class PortalContentArticleQueryHandler(bf.CmdHandler):317 """318 Class: PortalContentArticleQueryHandler319 Description: PortalÏ·¢µÄ²éѯÖ÷ÌâÎÄÕµÄÃüÁîhandler320 Base: CmdHandler321 Others: 322 """323 def handle_cmd(self, frame):324 """325 Method: handle_cmd326 Description: ´¦Àí²éѯÖ÷ÌâÎÄÕµÄÃüÁîÏûÏ¢327 Parameter: 328 frame: AppFrame329 Return: 330 Others: 331 """332 tracelog.info(self)333 334 result = msg_params_def.PortalContentArticleQueryRsp()335 result.init_all_attr()336 tracelog.info('content man worker recv article frame: %s' % frame)337 buf = frame.get_data()338 339 try:340 article_qry = msg_params_def.PortalContentArticleQueryReq.deserialize(buf)341 except:342 result.return_code = err_code_mgr.ERR_PORTAL_DESERIALIZE_ERROR343 result.description = err_code_mgr.get_error_msg(err_code_mgr.ERR_PORTAL_DESERIALIZE_ERROR,344 cmd = 'PORTAL_CONTENT_ARTICLE_QUERY',345 param_name = 'PortalContentArticleQueryReq')346 result.user_session = ''347 self.get_worker().get_app().send_ack_dispatch(frame, (result.serialize(), ))348 return349 num_per_page = None350 current_page = None351 batch_query = True352 pfm_count = False353 354 if article_qry is not None:355 if hasattr(article_qry, "num_per_page"):356 num_per_page = article_qry.num_per_page357 if hasattr(article_qry, "current_page"):358 current_page = article_qry.current_page359 360 if article_qry.subject_id is not None and len(article_qry.subject_id) != 0 and article_qry.subject_id != 'FFFF':361 subject_id = int(article_qry.subject_id)362 records = self.get_worker().get_app().get_mit_manager().lookup_attrs('Article',363 [364 'article_id',365 'title',366 'subject_id',367 'description',368 'pic_url',369 'content_url',370 'content',371 'group_ids',372 'push_timer',373 'push_times' 374 ],375 num_per_page = num_per_page,376 current_page = current_page,377 subject_id = subject_id)378 379 result.count = self.get_worker().get_app().get_mit_manager().count('Article', subject_id = subject_id)380 elif article_qry.article_id is not None and len(article_qry.article_id) != 0:381 batch_query = False382 article_id = int(article_qry.article_id)383 records = self.get_worker().get_app().get_mit_manager().lookup_attrs('Article',384 [385 'article_id',386 'title',387 'subject_id',388 'description',389 'pic_url',390 'content_url',391 'content',392 'group_ids',393 'push_timer',394 'push_times' 395 ],396 num_per_page = num_per_page, 397 current_page = current_page,398 article_id = article_id)399 result.count = self.get_worker().get_app().get_mit_manager().count('Article', article_id = article_id)400 if article_qry.subject_id != 'FFFF':401 pfm_count = True402 else:403 records = self.get_worker().get_app().get_mit_manager().lookup_attrs('Article',404 [405 'article_id',406 'title',407 'subject_id',408 'description',409 'pic_url',410 'content_url',411 'content',412 'group_ids',413 'push_timer',414 'push_times' 415 ],416 num_per_page = num_per_page, 417 current_page = current_page)418 result.count = self.get_worker().get_app().get_mit_manager().count('Article') 419 420 result.articles = []421 for article_rec in records:422 423 article = msg_params_def.Article()424 article.init_all_attr()425 article.article_id = str(article_rec[0])426 article.title = article_rec[1]427 article.subject_id = str(article_rec[2])428 article.description = article_rec[3]429 article.pic_url = article_rec[4]430 article.content_url = article_rec[5]431 if batch_query is True:432 article.content = ''433 else:434 article.content = article_rec[6]435 436 article.sub_group_ids = [str(gid) for gid in article_rec[7].group_ids]437 438 article.push_timer = article_rec[8]439 article.push_times = article_rec[9]440 441 if pfm_count is True:442 arts = self.get_worker().get_app().get_mit_manager().rdm_find('Article', article_id = article_rec[0])443 arts[0].counter += 1444 self.get_worker().get_app().get_mit_manager().rdm_mod(arts[0])445 446 result.articles.append(article)447 # ¸øWEB»Ø³É¹¦ÏìÓ¦448 result.return_code = err_code_mgr.ER_SUCCESS449 result.description = err_code_mgr.get_error_msg(err_code_mgr.ER_SUCCESS)450 result.prepare_for_ack(article_qry, result.return_code, result.description)451 tracelog.info(result.serialize())452 453 self.get_worker().get_app().send_ack_dispatch(frame, (result.serialize(), ))454 455class PortalContentSubjectCreateHandler(bf.CmdHandler):456 """457 Class: PortalContentSubjectCreateHandler458 Description: PortalÏ·¢µÄ´´½¨À¸Ä¿µÄÃüÁîhandler459 Base: CmdHandler460 Others: 461 """462 def handle_cmd(self, frame):463 """464 Method: handle_cmd465 Description: ´¦Àí´´½¨À¸Ä¿µÄÃüÁîÏûÏ¢466 Parameter: 467 frame: AppFrame468 Return: 469 Others: 470 """471 tracelog.info(self)472 473 result = basic_rep_to_web.BasicRepToWeb()474 result.init_all_attr()475 tracelog.info('content man worker recv subject frame: %s' % frame)476 buf = frame.get_data()477 478 try:479 sub_cfg = msg_params_def.PortalContentSubjectCreateReq.deserialize(buf)480 except:481 result.return_code = err_code_mgr.ERR_PORTAL_DESERIALIZE_ERROR482 result.description = err_code_mgr.get_error_msg(err_code_mgr.ERR_PORTAL_DESERIALIZE_ERROR,483 cmd = 'PORTAL_CONTENT_SUBJECT_CREATE',484 param_name = 'PortalContentSubjectCreateReq')485 result.user_session = ''486 self.get_worker().get_app().send_ack_dispatch(frame, (result.serialize(), ))487 return488 489 sub_moc = self.get_worker().get_app().get_mit_manager().gen_rdm("Subject")490 sub_moc.subject_id = self.get_worker().get_app().get_subject_no_creator().get_new_no()491 sub_moc.name = sub_cfg.name492 sub_moc.description = sub_cfg.description493 sub_moc.counter = 0494 ret = self.get_worker().get_app().get_mit_manager().rdm_add(sub_moc)495 496 if ret.get_err_code() == err_code_mgr.ER_OBJECT_ADD_CONFLICT:497 result.return_code = err_code_mgr.ERR_PORTAL_ARTICLE_RECORDS_FULL498 result.description = err_code_mgr.get_error_msg(err_code_mgr.ERR_PORTAL_ARTICLE_RECORDS_FULL)499 result.prepare_for_ack(sub_cfg, result.return_code, result.description)500 self.get_worker().get_app().send_ack_dispatch(frame, (result.serialize(), ))501 return502 503 elif ret.get_err_code() != 0:504 result.return_code = ret.get_err_code()505 result.description = ret.get_msg()506 507 result.prepare_for_ack(sub_cfg, result.return_code, result.description)508 self.get_worker().get_app().send_ack_dispatch(frame, (result.serialize(), ))509 return510 511 new_frame = bf.AppFrame()512 new_frame.set_cmd_code(cmd_code_def.CLOUD_PORTAL_CONTENT_UPDATE_MSG)513 self.get_worker().get_app().dispatch_frame_to_process_by_pid(self.get_worker().get_pid("SubscriberManApp"), new_frame) 514 # ¸øWEB»Ø³É¹¦ÏìÓ¦515 result.return_code = err_code_mgr.ER_SUCCESS516 result.description = err_code_mgr.get_error_msg(err_code_mgr.ER_SUCCESS) 517 result.prepare_for_ack(sub_cfg, result.return_code, result.description)518 self.get_worker().get_app().send_ack_dispatch(frame, (result.serialize(), ))519 # ·¢Ë͹ؼü²Ù×÷ʼþ֪ͨ520 oper_type = msg_params_def.EVENT_PORTAL_OPERATION_ADD + msg_params_def.EVENT_PORTAL_OBJECT_SUBJECT521 self.get_worker().get_app().send_portal_operation_event(sub_cfg.user_session, oper_type.decode('gbk').encode('utf-8'), sub_cfg.name)522class PortalContentSubjectModifyHandler(bf.CmdHandler):523 """524 Class: PortalContentSubjectModifyHandler525 Description: PortalÏ·¢µÄÐÞ¸ÄÀ¸Ä¿µÄÃüÁîhandler526 Base: CmdHandler527 Others: 528 """529 def handle_cmd(self, frame):530 """531 Method: handle_cmd532 Description: ´¦ÀíÐÞ¸ÄÀ¸Ä¿µÄÃüÁîÏûÏ¢533 Parameter: 534 frame: AppFrame535 Return: 536 Others: 537 """538 tracelog.info(self)539 540 result = basic_rep_to_web.BasicRepToWeb()541 result.init_all_attr()542 tracelog.info('content man worker recv subject frame: %s' % frame)543 buf = frame.get_data()544 545 try:546 sub_mod = msg_params_def.PortalContentSubjectModReq.deserialize(buf)547 except:548 result.return_code = err_code_mgr.ERR_PORTAL_DESERIALIZE_ERROR549 result.description = err_code_mgr.get_error_msg(err_code_mgr.ERR_PORTAL_DESERIALIZE_ERROR,550 cmd = 'PORTAL_CONTENT_SUBJECT_MODIFY',551 param_name = 'PortalContentSubjectModReq')552 result.user_session = ''553 self.get_worker().get_app().send_ack_dispatch(frame, (result.serialize(), ))554 return555 556 sub_moc = self.get_worker().get_app().get_mit_manager().rdm_find("Subject", subject_id = int(sub_mod.subject_id))557 if len(sub_moc) == 0:558 result.return_code = err_code_mgr.ERR_PORTAL_SUBJECT_NOT_EXISTS559 result.description = err_code_mgr.get_error_msg(err_code_mgr.ERR_PORTAL_SUBJECT_NOT_EXISTS)560 result.prepare_for_ack(sub_mod, result.return_code, result.description)561 self.get_worker().get_app().send_ack_dispatch(frame, (result.serialize(), ))562 return563 sub_moc[0].name = sub_mod.name564 sub_moc[0].description = sub_mod.description565 ret = self.get_worker().get_app().get_mit_manager().rdm_mod(sub_moc[0])566 if ret.get_err_code() != 0:567 result.return_code = ret.get_err_code()568 result.description = ret.get_msg()569 570 result.prepare_for_ack(sub_mod, result.return_code, result.description)571 self.get_worker().get_app().send_ack_dispatch(frame, (result.serialize(), ))572 return573 new_frame = bf.AppFrame()574 new_frame.set_cmd_code(cmd_code_def.CLOUD_PORTAL_CONTENT_UPDATE_MSG)575 self.get_worker().get_app().dispatch_frame_to_process_by_pid(self.get_worker().get_pid("SubscriberManApp"), new_frame) 576 # ¸øWEB»Ø³É¹¦ÏìÓ¦577 result.return_code = err_code_mgr.ER_SUCCESS578 result.description = err_code_mgr.get_error_msg(err_code_mgr.ER_SUCCESS) 579 result.prepare_for_ack(sub_mod, result.return_code, result.description)580 self.get_worker().get_app().send_ack_dispatch(frame, (result.serialize(), ))581 # ·¢Ë͹ؼü²Ù×÷ʼþ֪ͨ582 oper_type = msg_params_def.EVENT_PORTAL_OPERATION_MOD + msg_params_def.EVENT_PORTAL_OBJECT_SUBJECT583 self.get_worker().get_app().send_portal_operation_event(sub_mod.user_session, oper_type.decode('gbk').encode('utf-8'), sub_mod.name)584class PortalContentSubjectRemoveHandler(bf.CmdHandler):585 """586 Class: PortalContentSubjectRemoveHandler587 Description: PortalÏ·¢µÄɾ³ýÀ¸Ä¿µÄÃüÁîhandler588 Base: CmdHandler589 Others: 590 """591 def handle_cmd(self, frame):592 """593 Method: handle_cmd594 Description: ´¦Àíɾ³ýÀ¸Ä¿µÄÃüÁîÏûÏ¢595 Parameter: 596 frame: AppFrame597 Return: 598 Others: 599 """600 tracelog.info(self)601 602 result = basic_rep_to_web.BasicRepToWeb()603 result.init_all_attr()604 tracelog.info('content man worker recv subject frame: %s' % frame)605 buf = frame.get_data()606 607 try:608 sub_rmv = msg_params_def.PortalContentSubjectRemoveReq.deserialize(buf)609 except:610 result.return_code = err_code_mgr.ERR_PORTAL_DESERIALIZE_ERROR611 result.description = err_code_mgr.get_error_msg(err_code_mgr.ERR_PORTAL_DESERIALIZE_ERROR,612 cmd = 'PORTAL_CONTENT_SUBJECT_REMOVE',613 param_name = 'PortalContentSubjectRemoveReq')614 result.user_session = ''615 self.get_worker().get_app().send_ack_dispatch(frame, (result.serialize(), ))616 return617 subs = self.get_worker().get_app().get_mit_manager().rdm_find(moc_name = "Subject", subject_id = int(sub_rmv.subject_id))618 if len(subs) == 1:619 name = subs[0].name620 self.get_worker().get_app().get_mit_manager().rdm_remove(subs[0])621 622 arts = self.get_worker().get_app().get_mit_manager().rdm_find(moc_name = "Article", subject_id = int(sub_rmv.subject_id))623 for art in arts:624 self.get_worker().get_app().get_mit_manager().rdm_remove(art)625 new_frame = bf.AppFrame()626 new_frame.set_cmd_code(cmd_code_def.CLOUD_PORTAL_CONTENT_UPDATE_MSG)627 self.get_worker().get_app().dispatch_frame_to_process_by_pid(self.get_worker().get_pid("SubscriberManApp"), new_frame) 628 # ¸øWEB»Ø³É¹¦ÏìÓ¦629 result.return_code = err_code_mgr.ER_SUCCESS630 result.description = err_code_mgr.get_error_msg(err_code_mgr.ER_SUCCESS) 631 result.prepare_for_ack(sub_rmv, result.return_code, result.description)632 self.get_worker().get_app().send_ack_dispatch(frame, (result.serialize(), ))633 # ·¢Ë͹ؼü²Ù×÷ʼþ֪ͨ634 oper_type = msg_params_def.EVENT_PORTAL_OPERATION_DEL + msg_params_def.EVENT_PORTAL_OBJECT_SUBJECT635 self.get_worker().get_app().send_portal_operation_event(sub_rmv.user_session, oper_type.decode('gbk').encode('utf-8'), name)636class PortalContentSubjectQueryHandler(bf.CmdHandler):637 """638 Class: PortalContentSubjectQueryHandler639 Description: PortalÏ·¢µÄ²éѯÀ¸Ä¿µÄÃüÁîhandler640 Base: CmdHandler641 Others: 642 """643 def handle_cmd(self, frame):644 """645 Method: handle_cmd646 Description: ´¦Àí²éѯÀ¸Ä¿µÄÃüÁîÏûÏ¢647 Parameter: 648 frame: AppFrame649 Return: 650 Others: 651 """652 tracelog.info(self)653 654 result = msg_params_def.PortalContentSubjectQueryRsp()655 result.init_all_attr()656 tracelog.info('content man worker recv subject frame: %s' % frame)657 buf = frame.get_data()658 659 try:660 sub_qry = msg_params_def.CommonQueryReq.deserialize(buf)661 except:662 result.return_code = err_code_mgr.ERR_PORTAL_DESERIALIZE_ERROR663 result.description = err_code_mgr.get_error_msg(err_code_mgr.ERR_PORTAL_DESERIALIZE_ERROR,664 cmd = 'PORTAL_CONTENT_SUBJECT_QUERY',665 param_name = 'CommonQueryReq')666 result.user_session = ''667 self.get_worker().get_app().send_ack_dispatch(frame, (result.serialize(), ))668 return669 records = self.get_worker().get_app().get_mit_manager().rdm_find('Subject')670 671 result.subjects = []672 for sub_rec in records:673 sub = msg_params_def.Subject()674 sub.init_all_attr()675 sub.subject_id = str(sub_rec.subject_id)676 sub.name = sub_rec.name677 sub.description = sub_rec.description678 sub.article_num = self.get_worker().get_app().get_mit_manager().count('Article', subject_id = sub_rec.subject_id)679 result.subjects.append(sub)680 # ¸øWEB»Ø³É¹¦ÏìÓ¦681 result.count = len(result.subjects) 682 result.return_code = err_code_mgr.ER_SUCCESS683 result.description = err_code_mgr.get_error_msg(err_code_mgr.ER_SUCCESS)684 result.prepare_for_ack(sub_qry, result.return_code, result.description)685 tracelog.info(result.serialize())686 687 self.get_worker().get_app().send_ack_dispatch(frame, (result.serialize(), ))688class PortalContentHelpTipsSetHandler(bf.CmdHandler):689 """690 Class: PortalContentHelpTipsSetHandler691 Description: PortalÏ·¢µÄÉèÖû¶Ó´ÊÓë°ïÖúµÄÃüÁîhandler692 Base: CmdHandler693 Others: 694 """695 def handle_cmd(self, frame):696 """697 Method: handle_cmd698 Description: ´¦ÀíÉèÖû¶Ó´ÊÓë°ïÖúµÄÃüÁîÏûÏ¢699 Parameter: 700 frame: AppFrame701 Return: 702 Others: 703 """704 tracelog.info(self)705 706 result = basic_rep_to_web.BasicRepToWeb()707 result.init_all_attr()708 tracelog.info('content man worker recv helptips frame: %s' % frame)709 buf = frame.get_data()710 711 try:712 help_cfg = msg_params_def.CommonContentReq.deserialize(buf)713 except:714 result.return_code = err_code_mgr.ERR_PORTAL_DESERIALIZE_ERROR715 result.description = err_code_mgr.get_error_msg(err_code_mgr.ERR_PORTAL_DESERIALIZE_ERROR,716 cmd = 'PORTAL_CONTENT_HELPTIPS_SET',717 param_name = 'CommonContentReq')718 result.user_session = ''719 self.get_worker().get_app().send_ack_dispatch(frame, (result.serialize(), ))720 return721 helps = self.get_worker().get_app().get_mit_manager().rdm_find("HelpTips")722 if len(helps) == 1: 723 self.get_worker().get_app().get_mit_manager().rdm_remove(helps[0])724 725 help_moc = self.get_worker().get_app().get_mit_manager().gen_rdm("HelpTips")726 help_moc.tips_id = 0727 help_moc.content = help_cfg.content728 ret = self.get_worker().get_app().get_mit_manager().rdm_add(help_moc)729 730 if ret.get_err_code() != 0:731 result.return_code = ret.get_err_code()732 result.description = ret.get_msg()733 734 result.prepare_for_ack(help_cfg, result.return_code, result.description)735 self.get_worker().get_app().send_ack_dispatch(frame, (result.serialize(), ))736 return737 new_frame = bf.AppFrame()738 new_frame.set_cmd_code(cmd_code_def.CLOUD_PORTAL_CONTENT_UPDATE_MSG)739 self.get_worker().get_app().dispatch_frame_to_process_by_pid(self.get_worker().get_pid("SubscriberManApp"), new_frame) 740 # ¸øWEB»Ø³É¹¦ÏìÓ¦741 result.return_code = err_code_mgr.ER_SUCCESS742 result.description = err_code_mgr.get_error_msg(err_code_mgr.ER_SUCCESS) 743 result.prepare_for_ack(help_cfg, result.return_code, result.description)744 self.get_worker().get_app().send_ack_dispatch(frame, (result.serialize(), ))745 # ·¢Ë͹ؼü²Ù×÷ʼþ֪ͨ746 oper_type = msg_params_def.EVENT_PORTAL_OPERATION_MOD + msg_params_def.EVENT_PORTAL_OBJECT_HELPTIPS747 self.get_worker().get_app().send_portal_operation_event(help_cfg.user_session, oper_type.decode('gbk').encode('utf-8'), '')748class PortalContentHelpTipsQueryHandler(bf.CmdHandler):749 """750 Class: PortalContentHelpTipsQueryHandler751 Description: PortalÏ·¢µÄ²éѯ»¶Ó´ÊÓë°ïÖúµÄÃüÁîhandler752 Base: CmdHandler753 Others: 754 """755 def handle_cmd(self, frame):756 """757 Method: handle_cmd758 Description: ´¦Àí²éѯ»¶Ó´ÊÓë°ïÖúµÄÃüÁîÏûÏ¢759 Parameter: 760 frame: AppFrame761 Return: 762 Others: 763 """764 tracelog.info(self)765 766 result = msg_params_def.CommonContentRsp()767 result.init_all_attr()768 tracelog.info('content man worker recv helptips frame: %s' % frame)769 buf = frame.get_data()770 771 try:772 help_qry = basic_rep_to_web.BasicReqFromWeb.deserialize(buf)773 except:774 result.return_code = err_code_mgr.ERR_PORTAL_DESERIALIZE_ERROR775 result.description = err_code_mgr.get_error_msg(err_code_mgr.ERR_PORTAL_DESERIALIZE_ERROR,776 cmd = 'PORTAL_CONTENT_HELPTIPS_QUERY',777 param_name = 'BasicReqFromWeb')778 result.user_session = ''779 self.get_worker().get_app().send_ack_dispatch(frame, (result.serialize(), ))780 return781 helps = self.get_worker().get_app().get_mit_manager().rdm_find("HelpTips")782 783 if len(helps) == 1:784 result.content = helps[0].content785 else:786 result.content = ''787 # ¸øWEB»Ø³É¹¦ÏìÓ¦788 result.return_code = err_code_mgr.ER_SUCCESS789 result.description = err_code_mgr.get_error_msg(err_code_mgr.ER_SUCCESS)790 result.prepare_for_ack(help_qry, result.return_code, result.description)791 tracelog.info(result.serialize())792 793 self.get_worker().get_app().send_ack_dispatch(frame, (result.serialize(), ))794class PortalContentNewsIdUpdateHandler(bf.CmdHandler):795 """796 Class: PortalContentNewsIdUpdateHandler797 Description: 798 Base: CmdHandler799 Others: 800 """801 def handle_cmd(self, frame):802 """803 Method: handle_cmd804 Description: 805 Parameter: 806 frame: AppFrame807 Return: 808 Others: 809 """810 tracelog.info(self)811 article_id = int(frame.get_data())812 wx_news_id = frame.get_data(1)813 814 arts = self.get_worker().get_app().get_mit_manager().rdm_find("Article", article_id = article_id)815 if len(arts) == 0:816 tracelog.info('update article(%d) news id(%s), but the article does not exist in mit!' % (article_id, wx_news_id))817 return818 819 arts[0].wx_news_id = wx_news_id820 self.get_worker().get_app().get_mit_manager().rdm_mod(arts[0])821 tracelog.info('update article(id %d) to wx portal (news id %s) success!' % (article_id, wx_news_id))822class PortalContentWanIpUpdateHandler(bf.CmdHandler):823 """824 Class: PortalContentWanIpUpdateHandler825 Description: 826 Base: CmdHandler827 Others: 828 """829 def handle_cmd(self, frame):830 """831 Method: handle_cmd832 Description: 833 Parameter: 834 frame: AppFrame835 Return: 836 Others: 837 """838 tracelog.info(self)839 new_ip = frame.get_data()840 old_ip = self.get_worker().get_wan_ip()841 842 tracelog.info('new wan ip %s, old wan ip %s' % (new_ip, old_ip))843 844 self.get_worker().update_wan_ip(new_ip)845 846 arts = self.get_worker().get_app().get_mit_manager().rdm_find("Article")847 for art in arts:848 mod_flag = False849 if art.pic_url.find(new_ip) < 0:850 mod_flag = True851 u = art.pic_url.strip('http://')852 art.pic_url = 'http://' + new_ip + u[u.find('/'):]853 854 if art.content_url.find(new_ip) < 0:855 mod_flag = True856 u = art.content_url.strip('http://')857 art.content_url = 'http://' + new_ip + u[u.find('/'):]858 859 if mod_flag is True:860 tracelog.info('update article(id %d) all url!' % art.article_id)861 self.get_worker().get_app().get_mit_manager().rdm_mod(art)862 new_frame = bf.AppFrame()863 new_frame.set_cmd_code(cmd_code_def.CLOUD_PORTAL_CONTENT_UPDATE_MSG)864 self.get_worker().get_app().dispatch_frame_to_process_by_pid(self.get_worker().get_pid("SubscriberManApp"), new_frame) 865class PortalContentArticlePushHandler(bf.CmdHandler):866 """867 Class: PortalContentArticlePushHandler868 Description: PortalÏ·¢µÄÖ÷ÌâÄÚÈÝÈ˹¤ÍÆË͵ÄÃüÁîhandler869 Base: CmdHandler870 Others: 871 """872 def handle_cmd(self, frame):873 """874 Method: handle_cmd875 Description: ´¦ÀíÖ÷ÌâÄÚÈÝÈ˹¤ÍÆË͵ÄÃüÁîÏûÏ¢876 Parameter: 877 frame: AppFrame878 Return: 879 Others: 880 """881 tracelog.info(self)882 883 result = basic_rep_to_web.BasicRepToWeb()884 result.init_all_attr()885 tracelog.info('content man worker recv article push frame: %s' % frame)886 buf = frame.get_data()887 888 try:889 push_info = msg_params_def.PortalContentArticleSubscriberPush.deserialize(buf)890 except:891 result.return_code = err_code_mgr.ERR_PORTAL_DESERIALIZE_ERROR892 result.description = err_code_mgr.get_error_msg(err_code_mgr.ERR_PORTAL_DESERIALIZE_ERROR,893 cmd = 'PORTAL_CONTENT_ARTICLE_SUBSCRIBER_PUSH',894 param_name = 'PortalContentArticleSubscriberPush')895 result.user_session = ''896 self.get_worker().get_app().send_ack_dispatch(frame, (result.serialize(), ))897 return898 articles = self.get_worker().get_app().get_mit_manager().lookup_attrs("Article",899 [900 'article_id',901 'wx_news_id',902 'group_ids',903 'title'904 ],905 article_id = int(push_info.article_id))906 if len(articles) == 0: 907 result.return_code = err_code_mgr.ERR_PORTAL_ARTICLE_NOT_EXISTS908 result.description = err_code_mgr.get_error_msg(err_code_mgr.ERR_PORTAL_ARTICLE_NOT_EXISTS)909 910 result.prepare_for_ack(push_info, result.return_code, result.description)911 self.get_worker().get_app().send_ack_dispatch(frame, (result.serialize(), ))912 return913 914 if len(articles[0][1]) == 0:915 result.return_code = err_code_mgr.ERR_PORTAL_ARTICLE_NOT_UPLOADED916 result.description = err_code_mgr.get_error_msg(err_code_mgr.ERR_PORTAL_ARTICLE_NOT_UPLOADED)917 918 result.prepare_for_ack(push_info, result.return_code, result.description)919 self.get_worker().get_app().send_ack_dispatch(frame, (result.serialize(), ))920 return921 922 # ¹¹ÔìÍÆËÍÏûÏ¢·¢¸øSubscriberManApp£¬ÓÉËü·Ö·¢¸ø¸÷¸ö¶©ÔÄÕß923 push_msg = msg_params_def.CloudPortalArticlePushMessage()924 push_msg.init_all_attr()925 push_msg.article_id = articles[0][0]926 push_msg.wx_news_id = articles[0][1]927 928 subs = self.get_worker().get_app().get_mit_manager().lookup_attrs("Subscriber",929 [930 'subscriber_open_id',931 'group_ids'932 ])933 sub_map = {}934 for gid in articles[0][2].group_ids:935 for sub in subs:936 if gid in sub[1].group_ids:937 sub_map[sub[0]] = True938 939 push_msg.sub_open_ids = sub_map.keys() 940 941 push_frame = bf.AppFrame()942 push_frame.set_cmd_code(cmd_code_def.CLOUD_PORTAL_ARTICLE_PUSH_MSG)943 push_frame.add_data(push_msg.serialize())944 self.get_worker().get_app().dispatch_frame_to_process_by_pid(self.get_worker().get_pid("SubscriberManApp"), push_frame)945 946 # ¸øWEB»Ø³É¹¦ÏìÓ¦947 result.return_code = err_code_mgr.ER_SUCCESS948 result.description = err_code_mgr.get_error_msg(err_code_mgr.ER_SUCCESS) 949 result.prepare_for_ack(push_info, result.return_code, result.description)950 self.get_worker().get_app().send_ack_dispatch(frame, (result.serialize(), ))951 # ·¢Ë͹ؼü²Ù×÷ʼþ֪ͨ952 oper_type = msg_params_def.EVENT_PORTAL_OPERATION_PUSH + msg_params_def.EVENT_PORTAL_OBJECT_ARTICLE953 self.get_worker().get_app().send_portal_operation_event(push_info.user_session, oper_type.decode('gbk').encode('utf-8'), articles[0][3])954class PortalContentArticlePreviewHandler(bf.CmdHandler):955 """956 Class: PortalContentArticlePreviewHandler957 Description: PortalÏ·¢µÄÖ÷ÌâÄÚÈÝÔ¤ÀÀÍÆË͵ÄÃüÁîhandler958 Base: CmdHandler959 Others: 960 """961 def handle_cmd(self, frame):962 """963 Method: handle_cmd964 Description: ´¦ÀíÖ÷ÌâÄÚÈÝÔ¤ÀÀÍÆË͵ÄÃüÁîÏûÏ¢965 Parameter: 966 frame: AppFrame967 Return: 968 Others: 969 """970 tracelog.info(self)971 972 result = basic_rep_to_web.BasicRepToWeb()973 result.init_all_attr()974 tracelog.info('content man worker recv article preview frame: %s' % frame)975 buf = frame.get_data()976 977 try:978 push_info = msg_params_def.PortalContentArticleSubscriberPush.deserialize(buf)979 except:980 result.return_code = err_code_mgr.ERR_PORTAL_DESERIALIZE_ERROR981 result.description = err_code_mgr.get_error_msg(err_code_mgr.ERR_PORTAL_DESERIALIZE_ERROR,982 cmd = 'PORTAL_CONTENT_ARTICLE_ADMIN_PUSH',983 param_name = 'PortalContentArticleSubscriberPush')984 result.user_session = ''985 self.get_worker().get_app().send_ack_dispatch(frame, (result.serialize(), ))986 return987 articles = self.get_worker().get_app().get_mit_manager().lookup_attrs("Article",988 [989 'article_id',990 'wx_news_id',991 'group_ids',992 'title'993 ],994 article_id = int(push_info.article_id))995 if len(articles) == 0: 996 result.return_code = err_code_mgr.ERR_PORTAL_ARTICLE_NOT_EXISTS997 result.description = err_code_mgr.get_error_msg(err_code_mgr.ERR_PORTAL_ARTICLE_NOT_EXISTS)998 999 result.prepare_for_ack(push_info, result.return_code, result.description)1000 self.get_worker().get_app().send_ack_dispatch(frame, (result.serialize(), ))1001 return1002 1003 if len(articles[0][1]) == 0:1004 result.return_code = err_code_mgr.ERR_PORTAL_ARTICLE_NOT_UPLOADED1005 result.description = err_code_mgr.get_error_msg(err_code_mgr.ERR_PORTAL_ARTICLE_NOT_UPLOADED)1006 1007 result.prepare_for_ack(push_info, result.return_code, result.description)1008 self.get_worker().get_app().send_ack_dispatch(frame, (result.serialize(), ))1009 return1010 1011 # ¹¹ÔìÍÆËÍÏûÏ¢·¢¸øSubscriberManApp£¬ÓÉËü·Ö·¢¸ø¸÷¸ö¶©ÔÄÕß1012 push_msg = msg_params_def.CloudPortalArticlePushMessage()1013 push_msg.init_all_attr()1014 push_msg.article_id = articles[0][0]1015 push_msg.wx_news_id = articles[0][1]1016 1017 subs = self.get_worker().get_app().get_mit_manager().rdm_find("Subscriber", admin_flag = 'True')1018 if len(subs) == 0:1019 result.return_code = err_code_mgr.ERR_PORTAL_SUBSCRIBER_ADMIN_NOT_EXISTS1020 result.description = err_code_mgr.get_error_msg(err_code_mgr.ERR_PORTAL_SUBSCRIBER_ADMIN_NOT_EXISTS)1021 1022 result.prepare_for_ack(push_info, result.return_code, result.description)1023 self.get_worker().get_app().send_ack_dispatch(frame, (result.serialize(), ))1024 return1025 1026 push_msg.sub_open_ids = [subs[0].subscriber_open_id] 1027 1028 push_frame = bf.AppFrame()1029 push_frame.set_cmd_code(cmd_code_def.CLOUD_PORTAL_ARTICLE_PUSH_MSG)1030 push_frame.add_data(push_msg.serialize())1031 self.get_worker().get_app().dispatch_frame_to_process_by_pid(self.get_worker().get_pid("SubscriberManApp"), push_frame)1032 1033 # ¸øWEB»Ø³É¹¦ÏìÓ¦1034 result.return_code = err_code_mgr.ER_SUCCESS1035 result.description = err_code_mgr.get_error_msg(err_code_mgr.ER_SUCCESS) 1036 result.prepare_for_ack(push_info, result.return_code, result.description)1037 self.get_worker().get_app().send_ack_dispatch(frame, (result.serialize(), ))1038 # ·¢Ë͹ؼü²Ù×÷ʼþ֪ͨ1039 oper_type = msg_params_def.EVENT_PORTAL_OPERATION_PUSH + msg_params_def.EVENT_PORTAL_OBJECT_ARTICLE1040 self.get_worker().get_app().send_portal_operation_event(push_info.user_session, oper_type.decode('gbk').encode('utf-8'), articles[0][3])1041class PortalContentMgrInitMsgHandler(bf.CmdHandler):1042 1043 def handle_cmd(self, frame):1044 pass1045 1046class ContentConfigWorker(bf.CmdWorker):1047 """1048 Class: ContentConfigWorker1049 Description: ÄÚÈݹÜÀíÏß³ÌworkerÀà1050 Base: CmdWorker1051 Others: 1052 """1053 1054 def __init__(self, min_task_id, max_task_id):...
ntpd_handler.py
Source:ntpd_handler.py
...49 except:50 result = ntpd_params.GetNtpdHandlerResult()51 result.return_code = err_code_mgr.ER_NTPD_INVALID_DESERIALIZE_ERROR52 result.description = err_code_mgr.get_error_msg(err_code_mgr.ER_NTPD_INVALID_DESERIALIZE_ERROR)53 self.get_worker().send_ack(frame, (result.serialize(), ))54 return55 56 rdms = self.get_worker().get_mit_manager().rdm_find("NtpdControlMOC")57 if len(rdms)==0:58 result = ntpd_params.GetNtpdHandlerResult()59 result.return_code = err_code_mgr.ER_NTPD_DB_ERROR60 result.description = err_code_mgr.get_error_msg(err_code_mgr.ER_NTPD_DB_ERROR)61 self.get_worker().send_ack(frame, (result.serialize(), ))62 return63 64 if rdms[0].openserver==msg.openserver:65 response= ntpd_params.GetNtpdHandlerResult() 66 response.return_code = err_code_mgr.ER_NTPD_HAS_OP_ERROR67 response.description = err_code_mgr.get_error_msg(err_code_mgr.ER_NTPD_HAS_OP_ERROR)68 self.get_worker().send_ack(frame, (response.serialize(), ))69 return70 rdms[0].openserver = msg.openserver71 rdms[0].stratum = msg.stratum72 ret = self.get_worker().get_mit_manager().rdm_mod(rdms[0])73 if ret.get_err_code()!=err_code_mgr.ER_SUCCESS:74 result = ntpd_params.GetNtpdHandlerResult() 75 result.init_all_attr()76 result.return_code = ret.get_err_code()77 result.description = ret.get_msg()78 self.get_worker().send_ack(frame, (result.serialize(), ))79 return80 return_code, description = ntpd_set.ntpd_write(self.get_worker().get_mit_manager()) 81 response= ntpd_params.GetNtpdHandlerResult() 82 response.return_code = return_code83 response.description = description84 self.get_worker().send_ack(frame, (response.serialize(), )) 85 86class AddSubnetHandler(bf.CmdHandler):87 """88 Class: AddSubnetHandler89 Description: ΪNTPD·þÎñÉèÖÃ×ÓÍø¶Î90 Base: CmdHandler91 Others: ÎÞ92 """93 def handle_cmd(self, frame):94 """95 Method: handle_cmd96 Description: ΪNTPD·þÎñÉèÖÃ×ÓÍø¶Î97 Parameter: 98 frame: ÊÕµ½µÄ´¦ÀíÏûÏ¢99 dataÇøÒ»¸ö²ÎÊý£º100 msg£ºNtpdSubnet¶ÔÏó101 Return: ÎÞ102 Others: ÎÞ103 """104 try:105 msg = ntpd_params.NtpdSubnet().deserialize(frame.get_data())106 except:107 result = ntpd_params.GetNtpdHandlerResult()108 result.return_code = err_code_mgr.ER_NTPD_INVALID_DESERIALIZE_ERROR109 result.description = err_code_mgr.get_error_msg(err_code_mgr.ER_NTPD_INVALID_DESERIALIZE_ERROR)110 self.get_worker().send_ack(frame, (result.serialize(), ))111 return112 113 if msg.subnetip is None or msg.mask is None:114 result = ntpd_params.GetNtpdHandlerResult()115 result.return_code = err_code_mgr.ER_NTPD_INVALID_DESERIALIZE_ERROR116 result.description = err_code_mgr.get_error_msg(err_code_mgr.ER_NTPD_INVALID_DESERIALIZE_ERROR)117 self.get_worker().send_ack(frame, (result.serialize(), ))118 return119 ntpdsubnet_moc = self.get_worker().get_mit_manager().gen_rdm("NtpdSubnetMOC") 120 ntpdsubnet_moc.subnetip = msg.subnetip121 ntpdsubnet_moc.mask = msg.mask 122 ret = self.get_worker().get_mit_manager().rdm_add(ntpdsubnet_moc)123 124 if ret.get_err_code()==err_code_mgr.ER_OBJECT_ADD_CONFLICT:125 result = ntpd_params.GetNtpdHandlerResult()126 result.return_code = err_code_mgr.ER_DUPLICATE_NTPD_SUBNET_ERROR127 result.description = err_code_mgr.get_error_msg(err_code_mgr.ER_DUPLICATE_NTPD_SUBNET_ERROR)128 self.get_worker().send_ack(frame, (result.serialize(), ))129 return130 if ret.get_err_code()!=err_code_mgr.ER_SUCCESS:131 result = ntpd_params.GetNtpdHandlerResult()132 result.return_code = ret.get_err_code()133 result.description = ret.get_msg()134 self.get_worker().send_ack(frame, (result.serialize(), ))135 return136 137 return_code, description = ntpd_set.ntpd_write(self.get_worker().get_mit_manager()) 138 response= ntpd_params.GetNtpdHandlerResult() 139 response.return_code = return_code140 response.description = description141 self.get_worker().send_ack(frame, (response.serialize(), )) 142 143class AddServerHandler(bf.CmdHandler):144 """145 Class: AddServerHandler146 Description: ΪNTPDÉèÖ÷þÎñÆ÷IPµØÖ·147 Base: CmdHandler148 Others: ÎÞ149 """150 def handle_cmd(self, frame):151 """152 Method: handle_cmd153 Description: ΪNTPDÉèÖ÷þÎñÆ÷IPµØÖ·154 Parameter: 155 frame: ÊÕµ½µÄ´¦ÀíÏûÏ¢156 dataÇøÒ»¸ö²ÎÊý157 msg£ºNtpdServer¶ÔÏó158 Return: ÎÞ159 Others: ÎÞ160 """161 try:162 msg = ntpd_params.NtpdServer().deserialize(frame.get_data())163 except:164 result = ntpd_params.GetNtpdHandlerResult()165 result.return_code = err_code_mgr.ER_NTPD_INVALID_DESERIALIZE_ERROR166 result.description = err_code_mgr.get_error_msg(err_code_mgr.ER_NTPD_INVALID_DESERIALIZE_ERROR)167 self.get_worker().send_ack(frame, (result.serialize(), ))168 return169 170 if msg.serverip is None:171 result = ntpd_params.GetNtpdHandlerResult()172 result.return_code = err_code_mgr.ER_NTPD_INVALID_DESERIALIZE_ERROR173 result.description = err_code_mgr.get_error_msg(err_code_mgr.ER_NTPD_INVALID_DESERIALIZE_ERROR)174 self.get_worker().send_ack(frame, (result.serialize(), ))175 return176 177 ntpdserver_moc = self.get_worker().get_mit_manager().gen_rdm("NtpdServerMOC") 178 ntpdserver_moc.serverip = msg.serverip 179 ret = self.get_worker().get_mit_manager().rdm_add(ntpdserver_moc)180 181 if ret.get_err_code()==err_code_mgr.ER_OBJECT_ADD_CONFLICT:182 result = ntpd_params.GetNtpdHandlerResult()183 result.return_code = err_code_mgr.ER_DUPLICATE_NTPD_SERVER_ERROR184 result.description = err_code_mgr.get_error_msg(err_code_mgr.ER_DUPLICATE_NTPD_SERVER_ERROR)185 self.get_worker().send_ack(frame, (result.serialize(), ))186 return187 if ret.get_err_code()!=err_code_mgr.ER_SUCCESS:188 result = ntpd_params.GetNtpdHandlerResult()189 result.return_code = ret.get_err_code()190 result.description = ret.get_msg()191 self.get_worker().send_ack(frame, (result.serialize(), ))192 return193 194 return_code, description = ntpd_set.ntpd_write(self.get_worker().get_mit_manager()) 195 response= ntpd_params.GetNtpdHandlerResult() 196 response.return_code = return_code197 response.description = description 198 self.get_worker().send_ack(frame, (response.serialize(), )) 199 200class GetSubnetHandler(bf.CmdHandler):201 """202 Class: GetSubnetHandler203 Description: »ñÈ¡NTPDµÄ×ÓÍø¶Î204 Base: CmdHandler205 Others: ÎÞ206 """207 def handle_cmd(self, frame):208 """209 Method: handle_cmd210 Description: »ñÈ¡NTPDµÄ×ÓÍø¶Î211 Parameter: 212 frame: ÊÕµ½µÄ´¦ÀíÏûÏ¢213 Return: ÎÞ214 Others: ÎÞ215 """216 records = self.get_worker().get_mit_manager().lookup_attrs("NtpdSubnetMOC", ['subnetip', 'mask'])217 218 results = ntpd_params.GetNtpdSubnetListResult()219 results.init_all_attr()220 results.ntpdsubnets = [] 221 222 for record in records:223 ntpdsubnet = ntpd_params.NtpdSubnet()224 ntpdsubnet.init_all_attr()225 ntpdsubnet.subnetip = record[0]226 ntpdsubnet.mask= record[1]227 results.ntpdsubnets.append(ntpdsubnet)228 229 results.return_code = err_code_mgr.ER_SUCCESS230 results.description = err_code_mgr.get_error_msg(err_code_mgr.ER_SUCCESS)231 self.get_worker().send_ack(frame, (results.serialize(), ))232 233class GetServerHandler(bf.CmdHandler):234 """235 Class: GetServerHandler236 Description: »ñÈ¡NTPD·þÎñÆ÷IPµØÖ·237 Base: CmdHandler238 Others: ÎÞ239 """240 def handle_cmd(self, frame):241 """242 Method: handle_cmd243 Description: »ñÈ¡NTPD·þÎñÆ÷IPµØÖ·244 Parameter: 245 frame: ÊÕµ½µÄ´¦ÀíÏûÏ¢246 Return: ÎÞ247 Others: ÎÞ248 """249 records = self.get_worker().get_mit_manager().lookup_attrs("NtpdServerMOC", ['serverip'])250 251 results = ntpd_params.GetNtpdServerListResult()252 results.init_all_attr()253 results.ntpdservers = [] 254 255 for record in records:256 ntpdserver = ntpd_params.NtpdServer()257 ntpdserver .init_all_attr()258 ntpdserver .serverip = record[0]259 results.ntpdservers.append(ntpdserver)260 261 results.return_code = err_code_mgr.ER_SUCCESS262 results.description = err_code_mgr.get_error_msg(err_code_mgr.ER_SUCCESS)263 self.get_worker().send_ack(frame, (results.serialize(), ))264 265class DelSubnetHandler(bf.CmdHandler):266 """267 Class: DelSubnetHandler268 Description: ɾ³ýNTPDµÄij¸ö×ÓÍø¶Î269 Base: CmdHandler270 Others: ÎÞ271 """272 def handle_cmd(self, frame):273 """274 Method: handle_cmd275 Description: ɾ³ýNTPDµÄij¸ö×ÓÍø¶Î276 Parameter: 277 frame: ÊÕµ½µÄ´¦ÀíÏûÏ¢278 dataÇøÒ»¸ö²ÎÊý£º279 msg£ºNtpdSubnet¶ÔÏó280 Return: ÎÞ281 Others: ÎÞ282 """283 try:284 msg = ntpd_params.NtpdSubnet().deserialize(frame.get_data())285 except:286 result = ntpd_params.GetNtpdHandlerResult()287 result.return_code = err_code_mgr.ER_NTPD_INVALID_DESERIALIZE_ERROR288 result.description = err_code_mgr.get_error_msg(err_code_mgr.ER_NTPD_INVALID_DESERIALIZE_ERROR)289 self.get_worker().send_ack(frame, (result.serialize(), ))290 return291 292 if msg.subnetip is None or msg.mask is None:293 result = ntpd_params.GetNtpdHandlerResult()294 result.return_code = err_code_mgr.ER_NTPD_INVALID_DESERIALIZE_ERROR295 result.description = err_code_mgr.get_error_msg(err_code_mgr.ER_NTPD_INVALID_DESERIALIZE_ERROR)296 self.get_worker().send_ack(frame, (result.serialize(), ))297 return298 ntpdsubnet_moc = self.get_worker().get_mit_manager().gen_rdm("NtpdSubnetMOC") 299 ntpdsubnet_moc.subnetip = msg.subnetip300 ntpdsubnet_moc.mask = msg.mask301 302 ret = self.get_worker().get_mit_manager().rdm_remove(ntpdsubnet_moc)303 if ret.get_err_code() == err_code_mgr.ER_OBJECT_NOT_EXIST:304 result = ntpd_params.GetNtpdHandlerResult()305 result.return_code = err_code_mgr.ER_NTPD_SUBNET_NOT_EXIST306 result.description = err_code_mgr.get_error_msg(err_code_mgr.ER_NTPD_SUBNET_NOT_EXIST)307 self.get_worker().send_ack(frame, (result.serialize(), ))308 return309 if ret.get_err_code()!=err_code_mgr.ER_SUCCESS:310 result = ntpd_params.GetNtpdHandlerResult()311 result.return_code = ret.get_err_code()312 result.description = ret.get_msg()313 self.get_worker().send_ack(frame, (result.serialize(), ))314 return315 return_code, description = ntpd_set.ntpd_write(self.get_worker().get_mit_manager()) 316 response= ntpd_params.GetNtpdHandlerResult() 317 response.return_code = return_code318 response.description = description 319 self.get_worker().send_ack(frame, (response.serialize(), )) 320 321class DelServerHandler(bf.CmdHandler):322 """323 Class: DelServerHandler324 Description: ɾ³ýNTPDµÄij¸ö·þÎñÆ÷IPµØÖ·325 Base: CmdHandler326 Others: ÎÞ327 """328 def handle_cmd(self, frame):329 """330 Method: handle_cmd331 Description: ɾ³ýNTPDµÄij¸ö·þÎñÆ÷IPµØÖ·332 Parameter: 333 frame: ÊÕµ½µÄ´¦ÀíÏûÏ¢334 dataÇøÒ»¸ö²ÎÊý335 msg£ºNtpdServer¶ÔÏó336 Return: ÎÞ337 Others: ÎÞ338 """339 try:340 msg = ntpd_params.NtpdServer().deserialize(frame.get_data())341 except:342 result = ntpd_params.GetNtpdHandlerResult()343 result.return_code = err_code_mgr.ER_NTPD_INVALID_DESERIALIZE_ERROR344 result.description = err_code_mgr.get_error_msg(err_code_mgr.ER_NTPD_INVALID_DESERIALIZE_ERROR)345 self.get_worker().send_ack(frame, (result.serialize(), ))346 return347 348 if msg.serverip is None:349 result = ntpd_params.GetNtpdHandlerResult()350 result.return_code = err_code_mgr.ER_NTPD_INVALID_DESERIALIZE_ERROR351 result.description = err_code_mgr.get_error_msg(err_code_mgr.ER_NTPD_INVALID_DESERIALIZE_ERROR)352 self.get_worker().send_ack(frame, (result.serialize(), ))353 return354 355 ntpdserver_moc = self.get_worker().get_mit_manager().gen_rdm("NtpdServerMOC") 356 ntpdserver_moc.serverip = msg.serverip357 358 ret = self.get_worker().get_mit_manager().rdm_remove(ntpdserver_moc)359 if ret.get_err_code() == err_code_mgr.ER_OBJECT_NOT_EXIST:360 result = ntpd_params.GetNtpdHandlerResult()361 result.return_code = err_code_mgr.ER_NTPD_SERVER_NOT_EXIST362 result.description = err_code_mgr.get_error_msg(err_code_mgr.ER_NTPD_SERVER_NOT_EXIST)363 self.get_worker().send_ack(frame, (result.serialize(), ))364 return 365 if ret.get_err_code()!=err_code_mgr.ER_SUCCESS:366 result = ntpd_params.GetNtpdHandlerResult()367 result.return_code = ret.get_err_code()368 result.description = ret.get_msg()369 self.get_worker().send_ack(frame, (result.serialize(), ))370 return 371 return_code, description = ntpd_set.ntpd_write(self.get_worker().get_mit_manager()) 372 response= ntpd_params.GetNtpdHandlerResult() 373 response.return_code = return_code374 response.description = description 375 self.get_worker().send_ack(frame, (response.serialize(), ))...
test_middleware.py
Source:test_middleware.py
...7class DummyWorker(object):8 def __init__(self, name=None):9 self.name = name10class TestGetWorker(unittest.TestCase):11 def test_get_worker(self):12 with patch('kobo.hub.middleware.Worker') as worker_mock:13 worker_mock.objects.get.return_value = DummyWorker()14 req = PropertyMock(user=PropertyMock(username='foo/bar'))15 worker = middleware.get_worker(req)16 self.assertIsInstance(worker, DummyWorker)17 worker_mock.objects.get.assert_called_once_with(name='bar')18 def test_get_worker_missing_hostname(self):19 req = PropertyMock(user=PropertyMock(username='username'))20 worker = middleware.get_worker(req)21 self.assertIsNone(worker)22 def test_get_worker_catch_exceptions(self):23 req = PropertyMock(user=Mock(side_effect=ValueError))24 worker = middleware.get_worker(req)25 self.assertIsNone(worker)26class TestLazyWorker(unittest.TestCase):27 def test_lazy_worker_set_cache_variable_if_not_set(self):28 with patch('kobo.hub.middleware.get_worker', return_value=DummyWorker()) as get_worker_mock:29 req = PropertyMock(30 spec=['user'],31 user=PropertyMock(username='foo/bar'),32 )33 cached_worker = middleware.LazyWorker().__get__(req)34 self.assertIsInstance(cached_worker, DummyWorker)35 get_worker_mock.assert_called_once_with(req)36 def test_lazy_worker_do_not_set_cache_variable_if_already_set(self):37 with patch('kobo.hub.middleware.get_worker', return_value=DummyWorker('new-worker')) as get_worker_mock:38 req = PropertyMock(...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!