Exemplo n.º 1
0
    def OnChangeIpMode2(self, event):
        connection_name = self.m_choice8.GetStringSelection()
        if connection_name == "":
            return

        ip = self.m_textCtrl12.GetValue().strip()
        mask = self.m_textCtrl14.GetValue().strip()
        gateway = self.m_textCtrl15.GetValue().strip()

        if ip == "" or mask == "":
            util.ShowMessageDialog(self, u"ip地址或子网掩码不能为空", u"错误操作")
            return
        if gateway == "":
            cmd = "netsh interface ip set address name=\"%s\" source=static addr=%s mask=%s gateway=none 1" % (
                connection_name, ip, mask)
        else:
            cmd = "netsh interface ip set address name=\"%s\" source=static addr=%s mask=%s gateway=%s 1" % (
                connection_name, ip, mask, gateway)
        result = util.ExecuteCmd(cmd.encode('gbk')).strip()
        result_utf8 = result.decode('gbk')
        # print "result: [%s]" % (result)
        if result_utf8 == u'' or result_utf8 == u'\n' or result_utf8 == u'ok' or result_utf8 == u'确定':
            result = u'修改成功'
        util.ShowMessageDialog(self, result, u"执行结果")
        event.Skip()
Exemplo n.º 2
0
    def OnGenerateTemplate(self, event):
        if self.m_choice7.GetSelection() == wx.NOT_FOUND:
            # self.m_statusBar1.SetStatusText(u"请选择模板")
            util.ShowMessageDialog(self, u"请选择模板", u'提示')
            return
        device = self.m_listCtrl1.GetSelectedDevice()
        if device == None:
            # self.m_statusBar1.SetStatusText(u"请选择一条设备数据")
            util.ShowMessageDialog(self, u"请选择一条设备数据", u'提示')
            return

        if self.m_listCtrl1.GetRowLabelValue(
                self.m_listCtrl1.GetSelectedRows()[0]) == u'已配置':
            dlg = wx.MessageDialog(self, u'该设备已配置过,是否再次进行操作', u'提示',
                                   wx.OK | wx.CANCEL)
            if dlg.ShowModal() != wx.ID_OK:
                return

        content = u"您选择的设备数据如下:\n\t设备类型:       " + device.dev_type + \
                u"\n\t安装地址:       " + device.dev_addr + \
                u"\n\t管理地址:       " + device.mangr_ip + \
                u"\n\t子网掩码:       " + device.submask_ip + \
                u"\n\t默认网关:       " + device.gateway_ip + \
                u"\n\t管理vlan:       " + str(device.mangr_vlan) + \
                u"\n\t端口开始vlan: " + str(device.begin_vlan) + \
                u"\n\t端口结束vlan: " + str(device.end_vlan) + \
                u"\n\t进线口:          " + self.inline_dic.get(device.dev_type, "1") + \
                u"\n是否确定生成命令?"

        dlg = wx.MessageDialog(self, content, u"提示", wx.OK | wx.CANCEL)
        if dlg.ShowModal() == wx.ID_OK:
            # tpl_file = "templates/" + self.m_choice7.GetStringSelection() + ".tpl"
            tpl_file = os.path.join(
                self.temp_tpls_dir,
                self.m_choice7.GetStringSelection() + ".tpl")
            tpl_file = tpl_file.encode('gbk')
            # print tpl_file
            dict_data = {
                "mangr_vlan": device.mangr_vlan,
                "mangr_ip": device.mangr_ip,
                "submask_ip": device.submask_ip,
                "begin_vlan": device.begin_vlan,
                "end_vlan": device.end_vlan,
                "gateway_ip": device.gateway_ip
            }
            content = engine.render(tpl_file, dict_data)
            # util.ExecuteCmd('del .\\templates\\*.cache')
            self.m_textCtrl6.SetValue(content)
            self.is_clear_cmd = False
Exemplo n.º 3
0
    def __init__(self):
        super(MyttyFrame, self).__init__(None)

        self.m_choice8.AppendItems(self.InitPortSetting())
        self.m_choice7.AppendItems(self.InitCmdTemplates())

        # 去掉设计界面时测试用的session1和session2
        self.m_auinotebook2.DeletePage(
            self.m_auinotebook2.GetPageIndex(self.m_panel10))
        self.m_auinotebook2.DeletePage(
            self.m_auinotebook2.GetPageIndex(self.m_panel11))

        self.m_textCtrl71.Enable(False)

        # 外部工具的菜单链接
        self.InitExtralToolsMenu()

        self.m_listCtrl1.SetMainFrame(self)
        version = u"(版本:%s    剩余使用天数:%d)" % (license_mag.GetVersion(),
                                             license_mag.GetLeftDays())
        self.SetLabel(self.GetLabel() + version)

        self.icon = wx.Icon("my.png", wx.BITMAP_TYPE_ICO)
        self.SetIcon(self.icon)
        self.is_clear_cmd = False
        self.init_inline_datas()

        try:
            session_manager.session_manag.InitConfig()
        except Exception, e:
            os.system('copy /y config\\sessions config\\sessions.back')
            open('config/sessions', 'w').write('{}')
            util.ShowMessageDialog(
                None, u'读取会话文件sessions出错,已备份到session.back。错误:%s' % e, u'警告')
            session_manager.session_manag.InitConfig()
Exemplo n.º 4
0
 def AssertOpenSession(self):
     selected_tab = self.m_auinotebook2.GetSelection()
     if selected_tab == -1:
         self.m_statusBar1.SetStatusText(u"当前没有连接的会话")
         util.ShowMessageDialog(self, u"当前没有连接的会话", u'提示')
         return False
     return True
Exemplo n.º 5
0
    def OnOpenSerialPort(self, event):
        if self.m_comboBox1.GetSelection() == wx.NOT_FOUND:
            # self.m_statusBar1.SetStatusText(u"请选择端口")
            util.ShowMessageDialog(self, u"请选择端口", u'提示')
            return

        if self.m_choice8.GetSelection() == wx.NOT_FOUND:
            # self.m_statusBar1.SetStatusText(u"请选择端口设置")
            util.ShowMessageDialog(self, u"请选择端口设置", u'提示')
            return

        portstr = self.m_comboBox1.GetStringSelection()
        port_setting = self.setting_list[self.m_choice8.GetSelection()]

        session = SerialSession(portstr, port_setting)
        self.OpenSession(session)
Exemplo n.º 6
0
 def OnSaveSession(self, event):
     save_name = self.GetSessionSaveName()
     if save_name != self.session.GetSessionName():
         if session_manager.session_manag.IsNameExist(save_name):
             util.ShowMessageDialog(self, u"该会话名已存在!", u"信息")
         else:
             event.Skip()
     else:
         event.Skip()
Exemplo n.º 7
0
 def OnOpenSession(self, event):
     dlg = MyOpenSessionDialog(self)
     if dlg.ShowModal() == wx.ID_OK:
         session = dlg.GetSelectedSession()
         if session == None:
             util.ShowMessageDialog(self, u"没有找到保存的会话", u"信息")
             return
         self.OpenSession(session)
     dlg.Destroy()
Exemplo n.º 8
0
 def OnDeleteSession(self, event):
     session = self.GetSelectedSession()
     if session == None:
         return None
     session_name = session.GetSessionName()
     if session_manager.session_manag.DeleteSavedSessionByName(
             session_name):
         self.m_listCtrl2.DeleteItem(self.m_listCtrl2.GetFirstSelected())
     else:
         util.ShowMessageDialog(self, u"删除会话记录失败,可能已经不存在那个会话了", u"错误")
Exemplo n.º 9
0
 def OnChangeIpMode1(self, event):
     # 改为自动获取ip地址
     connection_name = self.m_choice8.GetStringSelection()
     print connection_name
     if connection_name == "":
         return
     cmd = u"netsh interface ip set address name=" + connection_name + u" source=dhcp"
     print cmd
     util.ShowMessageDialog(self, util.ExecuteCmd(cmd.encode('gbk')),
                            u"执行结果")
     event.Skip()
Exemplo n.º 10
0
 def OnGenerateClearCmd(self, event):
     if self.m_choice9.GetSelection() == wx.NOT_FOUND:
         # self.m_statusBar1.SetStatusText(u"请选择模板")
         util.ShowMessageDialog(self, u"请选择模板", u'提示')
         return
     device = self.m_listCtrl1.GetSelectedDevice()
     if device == None:
         # self.m_statusBar1.SetStatusText(u"请选择一条设备数据")
         util.ShowMessageDialog(self, u"请选择一条设备数据", u'提示')
         return
     content = u'此动作会生成清除设备中所有配置的命令,是否继续?'
     dlg = wx.MessageDialog(self, content, u"提示", wx.OK | wx.CANCEL)
     if dlg.ShowModal() == wx.ID_OK:
         # tpl_file = "templates/" + self.m_choice9.GetStringSelection() + ".tpl"
         tpl_file = os.path.join(
             self.temp_tpls_dir,
             self.m_choice9.GetStringSelection() + ".tpl")
         tpl_file = tpl_file.encode('gbk')
         fd = open(tpl_file, 'r')
         self.m_textCtrl6.SetValue(fd.read())
         self.is_clear_cmd = True
Exemplo n.º 11
0
    def OpenSession(self, session):
        if session.Open():
            session_manager.session_manag.AddSession(session)
            tabPanel = wx.Panel(self.m_auinotebook2, wx.ID_ANY,
                                wx.DefaultPosition, wx.DefaultSize,
                                wx.TAB_TRAVERSAL)
            # tabPanel = Terminal( self.m_auinotebook2, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, wx.TAB_TRAVERSAL )
            self.m_auinotebook2.AddPage(tabPanel, session.GetSessionName(),
                                        True, wx.NullBitmap)
            self.SetConnectionInfo(session)

            tabPanelSizer = wx.BoxSizer(wx.VERTICAL)
            self.terminate = wxTerm(tabPanel, "", session=session)
            tabPanelSizer.Add(self.terminate, 1, wx.ALL | wx.EXPAND, 1)
            tabPanel.SetSizer(tabPanelSizer)
            tabPanel.Layout()
            self.m_textCtrl71.Enable(True)
            util.ShowMessageDialog(self, u"连接成功", u"提示")
            session.Write('\n')
        else:
            util.ShowMessageDialog(self,
                                   u"连接:%s 打开失败" % session.GetSessionInfo(),
                                   u"错误")
Exemplo n.º 12
0
	def OnCellDataChange(self, event):
		print 'event.Col:', event.Col
		if event.Col == ENUM_DEVICE_DEV_TYPE:
			device_type = self.GetCellValue(event.Row, event.Col)
			print device_type
			self.FilterTemplateList(device_type)
			self.SetPromptForSend(device_type)
		elif event.Col == ENUM_DEVICE_MANGR_IP or event.Col == ENUM_DEVICE_SUBMASK_IP or event.Col == ENUM_DEVICE_GATEWAY_IP:
			if not util.IsValidIP(self.GetCellValue(event.Row, event.Col)):
				util.ShowMessageDialog(self, u"非法的ip地址", u"错误")
				event.Veto()
				return
		event.Skip()
		wx.CallAfter(self.AdjustSizeColumns)
Exemplo n.º 13
0
    def OnSendTemplate(self, event):
        tpl_content = self.m_textCtrl6.GetValue()
        if tpl_content == '':
            # self.m_statusBar1.SetStatusText(u"还没有生成命令")
            util.ShowMessageDialog(self, u"还没有生成命令", u'提示')
            return
        if not self.AssertOpenSession():
            return
        send_interval = self.GetSendInterval()

        cmd_list = tpl_content.split("\n")
        dlg = HtmlMessageDialog(
            self, u'提示',
            u'<font color="red"><p>请仔细比对发送提示和窗口输出</p><p>是否确认发送?</p></font>')
        if dlg.ShowModal() == wx.ID_OK:
            self.SendCommand(cmd_list, send_interval)
Exemplo n.º 14
0
    def OnSaveSession(self, event):
        session = self.GetCurActivatedSession()
        if session is None:
            return

        dlg = MySaveSessionDialog(self, session)
        if dlg.ShowModal() == wx.ID_OK:
            save_name = dlg.GetSessionSaveName()
            save_path = dlg.GetLogFileName()
            if session_manager.session_manag.SaveSession(
                    session, save_name, save_path):
                self.m_auinotebook2.SetPageText(
                    self.m_auinotebook2.GetSelection(),
                    session.GetSessionName())
            else:
                util.ShowMessageDialog(self, u"保存会话失败,已存在同名的会话了", u"信息")
                print u"save session failed!"
        dlg.Destroy()
Exemplo n.º 15
0
class MySendProgressDialog(SendProgressDialog.SendProgressDialog):
    """docstring for MySendProgressDialog"""
    def __init__(self, parent, cmd_list, send_interval, session, is_clear_cmd):
        super(MySendProgressDialog, self).__init__(parent)
        self.parent = parent
        self.cmd_list = cmd_list
        self.session = session
        self.send_interval = send_interval
        self.is_clear_cmd = is_clear_cmd
        self.current_count = 0
        self.total_count = len(self.cmd_list)
        self.m_gauge2.SetRange(self.total_count)
        self.m_staticText21.SetLabel(self.cmd_list[self.current_count])
        self.timer = wx.Timer(self, 1)
        self.Bind(wx.EVT_TIMER, self.OnTimer, self.timer)
        self.timer.Start(self.send_interval)

    def BeginSendProgress(self):
        cmd = self.cmd_list[self.current_count]
        cmd = cmd + '\n'
        cmd = cmd.encode('ascii')
        try:
            self.session.Write(cmd)
        except Exception, e:
            logging.error('send command: (%s) failed, exception: %s',
                          *(cmd, e))

        # time.sleep(self.send_interval)
        self.current_count = self.current_count + 1

        if self.current_count >= self.total_count:
            if self.is_clear_cmd:
                self.m_staticText24.SetLabel(u"清除设备配置完毕,请等待设备重启")
            else:
                self.m_button15.Enable(True)
                self.m_staticText24.SetLabel(u"命令发送完毕,请做好标签拔掉连接线更换配置设备")
        else:
            self.m_staticText21.SetLabel(self.cmd_list[self.current_count])
            if not self.session.IsAlive():
                util.ShowMessageDialog(self, u"连接已断开,发送模板数据已终止!", u"错误")
                self.timer.Stop()
Exemplo n.º 16
0
    def SendTplCmdThread(self, cmd_list, send_interval):
        session = self.GetCurActivatedSession()
        for cmd in cmd_list:
            cmd = cmd + '\n'
            # print "send cmd: [%s]end" % (cmd)
            cmd = cmd.encode('ascii')
            try:
                session.Write(cmd)
            except Exception, e:
                logging.error('send command: (%s) failed, exception: %s',
                              *(cmd, e))
            # event = wx.KeyEvent(eventType=wx.wxEVT_CHAR)
            # for ch in cmd:
            # 	event.m_keyCode = ord(ch)
            # 	# session.term.WriteText(ch)
            # 	session.term.OnTerminalChar(event)
            # 	# wx.PostEvent(self.terminate, event)
            time.sleep(send_interval / 1000.0)

            if not session.IsAlive():
                # self.m_statusBar1.SetStatusText(u"连接已断开,发送模板数据已终止!")
                util.ShowMessageDialog(self, u"连接已断开,发送模板数据已终止!", u'提示')
                break
Exemplo n.º 17
0
                self.reboot_timer.Start(1000)

    def OnDeviceRebootTimer(self, event):
        self.reboot_count = self.reboot_count + 1
        self.m_gauge2.SetValue(self.reboot_count)
        if self.reboot_count >= 50:
            self.reboot_timer.Stop()
            self.m_staticText24.SetLabel(u"设备重启完毕!")
            self.m_button15.Enable(True)


if __name__ == "__main__":
    app = wx.PySimpleApp(0)
    wx.InitAllImageHandlers()
    license_mag = LicenseManager()
    (val, msg) = license_mag.OpenLicense(u'./license.license')
    if val == 1:
        util.ShowMessageDialog(None, u'该软件没有正确的授权,无法使用!%s' % (msg), u'错误')
    elif val == 2:
        util.ShowMessageDialog(None, u'系统时间有问题,请您正确设置时间并合法使用该软件', u'错误')
    elif val == 3:
        util.ShowMessageDialog(None, u'软件使用已到期,要继续使用请联系商家', u'错误')
    elif val == 4:
        util.ShowMessageDialog(None, u'非授权的机器,无法使用该软件,请联系商家购买', u'错误')
    else:
        license_mag.AddUsingLog()
        frame_1 = MyttyFrame()
        app.SetTopWindow(frame_1)
        frame_1.Show()
        app.MainLoop()