예제 #1
0
 def cr_topology_init_scene(self,
                            topo_data,
                            root_entity,
                            auto_arrange_root=True):
     """
     初始化拓扑地图
     :param topo_data: oj中的json网络描述
     :param root_entity: 定义一个根节点,展开topo
     :param auto_arrange_root:
     :return:
     """
     errors = 0
     self.topology = XojScene()
     self.topology.from_json(topo_data)
     self.topology.make_tree(root_entity, auto_arrange_root)
     bin_msg = self.topology.to_binary()
     if bin_msg:
         message = wrap_message(bin_msg)
         logging.info(self.topology.to_json())
         self.pub_state(WORLD_STATES.INIT_TOPO, topo_data, message)
     else:
         logging.error("Generating serialized topology error!")
         errors += 1
     # 发送proto2兼容数据
     bin_msg2 = self.topology.to_binary_2()
     if bin_msg2:
         message = wrap_message_2(bin_msg2)
         self.pub_state(WORLD_STATES.INIT_TOPO_PROTO2, topo_data, message)
     else:
         logging.error(
             "Generating proto2 version serialized topology error!")
         errors += 1
     return not bool(errors)
예제 #2
0
 def mk_sync_timing(display_countdown=True, countdown_time=0):
     # TODO:如果到0点以后,这个信息要更新到第二天
     # TODO:在回放时,应当关闭自动倒数
     d = datetime.datetime.now()
     weekday = d.weekday()
     the_week = u'星期' + [u'一', u'二', u'三', u'四', u'五', u'六', u'日'][weekday]
     the_date = d.strftime('%Y-%m-%d')
     server_time = int(time.time())
     msg = sysctrl_sync_timing_2(the_week=the_week,
                                 the_date=the_date,
                                 countdown_time=countdown_time,
                                 server_time=server_time,
                                 display_countdown=display_countdown)
     return wrap_message_2(msg)
예제 #3
0
 def mk_topology_guideline(switch=EnumOnoff.on,
                           src_obj_id="NOT_SET",
                           dest_obj_id="NOT_SET",
                           duration=5,
                           color="FFFFFF",
                           wrap=True):
     msg = topology_guide_line(switch=switch,
                               src_obj_id=src_obj_id,
                               dest_obj_id=dest_obj_id,
                               duration=duration,
                               color="#" + color)
     if wrap:
         return wrap_message_2(msg)
     else:
         return msg
예제 #4
0
 def mk_topology_entity_panel(src_obj_id="",
                              switch=EnumOnoff.on,
                              ip_address="",
                              os_name="",
                              status="",
                              duration=0,
                              wrap=True):
     msg = topology_entity_panel(src_obj_id=src_obj_id,
                                 switch=switch,
                                 ip_address=ip_address,
                                 os_name=os_name,
                                 status=status,
                                 duration=duration)
     if wrap:
         return wrap_message_2(msg)
     else:
         return msg
예제 #5
0
 def mk_topology_attack(switch=EnumOnoff.on,
                        intensity=EnumAttackIntensity.attack_moderate,
                        src_obj_id="",
                        dest_obj_id="",
                        color="#FFFFFF",
                        duration=4,
                        wrap=True):
     msg = topology_attack(switch=switch,
                           intensity=intensity,
                           src_obj_id=src_obj_id,
                           dest_obj_id=dest_obj_id,
                           color="#" + color,
                           duration=duration)
     if wrap:
         return wrap_message_2(msg)
     else:
         return msg
예제 #6
0
 def mk_topology_effect(switch=EnumOnoff.on,
                        effect=EnumTopologyEffect.blink,
                        src_obj_id="",
                        icon="",
                        color1="NOT_SET",
                        color2="NOT_SET",
                        duration=4,
                        wrap=True):
     if src_obj_id == "":
         src_obj_id = random.choice(topology_init_data)["obj_id"]
     msg = topology_effect(switch=switch,
                           effect=effect,
                           src_obj_id=src_obj_id,
                           icon=icon,
                           color1="#" + color1,
                           color2="#" + color2,
                           duration=duration)
     if wrap:
         return wrap_message_2(msg)
     else:
         return msg
예제 #7
0
 def mk_ui_toast(position=Enums.EnumPosition.left,
                 icon=Enums.EnumToastIcon.information,
                 text_title="untitled",
                 text_content="sample content",
                 switch=Enums.EnumOnoff.on,
                 duration=5,
                 color=""):
     if position == Enums.EnumPosition.top:
         alpha = 1.0
     else:
         alpha = 0.8
     if not color:
         color = color
     msg = sysctrl_toast(positon=position,
                         icon=icon,
                         text_title=text_title,
                         text_content=text_content,
                         switch=switch,
                         duration=duration,
                         message_id=str(time.time()),
                         color=color,
                         alpha=alpha)
     return wrap_message_2(msg)
예제 #8
0
 def mk_ui_set_message(message="", datetime=""):
     msg = sysctrl_set_message(message_text=message, datetime=datetime)
     return wrap_message_2(msg)
예제 #9
0
 def mk_ui_set_logo(logo_url=""):
     msg = sysctrl_set_logo(logo_url=logo_url)
     return wrap_message_2(msg)
예제 #10
0
 def mk_ui_set_title(title_text="untitled"):
     msg = sysctrl_set_title(title_text=title_text)
     return wrap_message_2(msg)