Beispiel #1
0
    def DoMonitor(self):
        if gen.IsItemChanged is True:
            rf = DataHandle(self.filename)
            self.pdata = rf.ReadData()
        gen.IsItemChanged = False
        ####获取监控中的路径列表 和 全部 kid 列表
        self.ProPathList = []
        self.ProKidList = []
        allProList = []
        monProList = []
        runProList = []

        for kid in self.pdata.keys():
            ProPath = self.pdata[kid]["programe"]
            proNum = self.pdata[kid]["processNum"]
            Pro_Argument = self.pdata[kid]["logfile"]
            Operator = gen.operatorDict[self.pdata[kid]["operator"]]
            runAs = self.pdata[kid]["runAs"]
            allProList.append(kid)
            if self.pdata[kid]["monitor"] is True:
                monProList.append(kid)
                ProName = os.path.basename(ProPath)

                if self.GetProcessCount(ProName) == 0:
                    LoadLog.LogMsg(gen.logger.warning,
                                   u"未发现项目进程%s,启动进程%s" % (ProName, ProName))
                    self.StartPro(kid, ProPath, Pro_Argument, runAs)
                    if self.GetProcessCount(ProName) == 0:
                        LoadLog.LogMsg(gen.logger.warning,
                                       u"启动进程%s失败" % ProName)
                elif self.OperatorExpress(Operator, ProName, proNum):
                    runProList.append(kid)
                    self.pdata[kid]["status"] = True
                else:
                    LoadLog.LogMsg(
                        gen.logger.warning,
                        u"发现项目的%s进程不满足条件给定条件,结束%s进程" % (ProName, ProName))
                    self.StopPro(kid, ProName)
            else:
                self.pdata[kid]["status"] = ""

        gen.allProNum = len(allProList)
        gen.monProNum = len(monProList)
        gen.runProNum = len(runProList)
        #self.SetStatusInformation(allProNum,monProNum,runProNum)
        list_data = self.rf.handleList(self.pdata)
        self.ProgrameList.SetObjects(list_data)
Beispiel #2
0
    def SetDialogData(self, filename, item):
        ReadFromFile = DataHandle(filename)
        self.pdata = ReadFromFile.ReadData()
        print self.pdata[str(item)]
        self.name = self.pdata[str(item)]["name"]

        # if os.path.abspath(self.pdata[str(item)]["programe"]) is not True:
        #     self.programe = os.path.join(os.path.split(__file__)[0],self.pdata[str(item)]["name"])
        # else:
        #self.programe = self.pdata[str(item)]["name"]

        self.programe = os.path.abspath(self.pdata[str(item)]["programe"])

        self.logfile = self.pdata[str(item)]["logfile"]
        if os.path.isfile(self.logfile):
            self.logfile = os.path.abspath(self.logfile)

        self.note = self.pdata[str(item)]["note"]
        self.monitor = self.pdata[str(item)]["monitor"]
        self.status = self.pdata[str(item)]["status"]
        self.operator = self.pdata[str(item)]["operator"]
        self.processNum = self.pdata[str(item)]["processNum"]
        self.runAs = self.pdata[str(item)]["runAs"]
        LoadLog.LogMsg(gen.logger.debug, u"获取对应项目的数据内容")
        #print "&&&&&&&&:",self.runAs

        LoadLog.LogMsg(gen.logger.debug, u"将取得项目的数据内容设定到编辑对话框")
        self.name_t.SetValue(self.name)
        self.fpath_t.SetValue(self.programe)
        self.logpath_t.SetValue(self.logfile)
        self.operatorBox.SetValue(self.operator)
        self.proNum_t.SetValue(self.processNum)
        #self.runAsRadio.SetSelection(0)
        self.runAsRadio.SetSelection(int(self.runAs))

        ProName = str(os.path.basename(self.programe))
        p = os.popen('tasklist /FI "IMAGENAME eq %s"' % ProName)
        GetProNum = p.read().count(ProName)
        #print "######### process Number: ###############",ProName,GetProNum,type(GetProNum)
        if GetProNum != 0:
            self.runAsRadio.EnableItem(0, enable=False)
            self.runAsRadio.EnableItem(1, enable=False)
        self.note_t.SetValue(self.note)
        #print u"监控状态===>",self.monitor
        if self.monitor is True:
            self.monitor_t.SetValue(self.monitor)
Beispiel #3
0
 def setResults(self, filename):
     self.plist.SetColumns([
         ColumnDefn(u"序号", "center", 40, "id"),
         ColumnDefn(u"名称", "left", 80, "name"),
         ColumnDefn(u"程序", "left", 120, "programe"),
         ColumnDefn(u"备注", "left", 100, "note"),
     ])
     self.plist.CreateCheckStateColumn()
     self.list_data = DataHandle(filename).handleList()
     self.plist.SetObjects(self.list_data)
Beispiel #4
0
    def handleExportDlg(self):
        allobj = self.plist.GetObjects()
        tbool = []
        LoadLog.LogMsg(gen.logger.debug,u"检测选项")
        for obj in allobj:
            if self.plist.IsChecked(obj) == True:
                tbool.append(self.plist.IsChecked(obj))
        if tbool.count(True) == 0:
            LoadLog.LogMsg(gen.logger.warning,u"未选取任何要导出的项目")
            wx.MessageBox(u"未选取内容,没有数据导出", u'警告', wx.OK|wx.ICON_WARNING,parent=self.panel)
            return
        else:
            newDataDict = {}
            #print u"=====读取的文件:",self.filename
            readFileData = DataHandle(self.filename)

            pdata = readFileData.ReadData()
            #print u"====导出对话框从文件读取的字典:",pdata
            for obj in allobj:
                if self.plist.IsChecked(obj) == True:
                    kid = obj.kid
                    #print u"###选中的kid",kid
                    #print u"###字典,kid 对应的项",pdata[kid]
                    newDataDict[kid] = pdata[kid]
            try:
                print newDataDict
                exportObj = DataHandle(self.filepath)
                exportObj.WriteData(newDataDict)
                wx.MessageBox(u"数据文件成功导出!", u'信息', wx.OK|wx.ICON_INFORMATION)
                LoadLog.LogMsg(gen.logger.info,u"成功导出数据到文件")
            except:
                wx.MessageBox(u"保存文件出错,请检查文件权限", u'错误', wx.OK|wx.ICON_ERROR)
                LoadLog.LogMsg(gen.logger.warning,u"导出文件出错")
                return
Beispiel #5
0
    def OnImportDlog(self, event):
        LoadLog.LogMsg(gen.logger.info, u"打开导入对话框")
        wildcard = "Json File (*.json)|*.json|" \
                   "All files (*.*)|*.*"

        importDlg = wx.FileDialog(None, u"选择导入的文件", os.getcwd(), "", wildcard,
                                  wx.OPEN)
        if importDlg.ShowModal() == wx.ID_OK:
            ipathfile = importDlg.GetPath()
            importObj = DataHandle(ipathfile)
            pdata = importObj.ReadData()
            #print u"===从导入文件读取到的字典: ",pdata
            if pdata != None:
                for eachKey in pdata.keys():
                    if eachKey.isdigit():
                        break
                subkeys = [
                    "status", "name", "runAs", "note", "programe",
                    "processNum", "kid", "logfile", "monitor"
                ]
                for kid in pdata.keys():
                    if len(pdata[kid].keys()) != len(subkeys):
                        break
                    for eachsubKey in subkeys:
                        if eachsubKey not in pdata[kid]:
                            break
                #print u"===从导入文件读取到,并通过的字典:",pdata
                writeDlg = wx.MessageDialog(self.ProgrameList,
                                            u"导入的文件数据将覆盖现在程序的数据,是否继续?",
                                            u'确认提示',
                                            wx.YES_NO | wx.ICON_QUESTION)
                if writeDlg.ShowModal() == wx.ID_YES:
                    saveObj = DataHandle(self.filename)
                    saveObj.WriteData(pdata)
                    LoadLog.LogMsg(gen.logger.info, u"成功导入")
                    list_data = self.datahandle.handleList()
                    LoadLog.LogMsg(gen.logger.info, u"刷新控件列表")
                    self.ProgrameList.SetObjects(list_data)
                else:
                    LoadLog.LogMsg(gen.logger.info, u"取消导入")
                    return
            else:
                wx.MessageBox(u"无法导入,类型或错误的文件结构", u'错误', wx.OK | wx.ICON_ERROR)
                LoadLog.LogMsg(gen.logger.error, u"无法导入,类型或错误的文件结构")
        importDlg.Destroy()
Beispiel #6
0
 def __init__(self, filename=None, plist=None):
     self.filename = filename
     ##传入列表控件对象
     self.ProgrameList = plist
     self.datahandle = DataHandle(self.filename)
Beispiel #7
0
class EventHandle(object):
    def __init__(self, filename=None, plist=None):
        self.filename = filename
        ##传入列表控件对象
        self.ProgrameList = plist
        self.datahandle = DataHandle(self.filename)

    def OnAdd_Edit_Dialog(self, event):
        #print "add_edit_dialog"
        if event.GetId() == wx.ID_ADD:
            self.dlg = AddProgramDialog(u"增加项目", u"请输入添加项目的相关内容:")
            LoadLog.LogMsg(gen.logger.info, u"打开增加对话框")
            self.kid = None
        elif event.GetId() == wx.ID_EDIT:
            self.kid = self.CheckEdit()
            if self.kid is None:
                return
            self.dlg = EditProgramDialog(u"编辑项目", u"请输入编辑项目的相关内容:")
            LoadLog.LogMsg(gen.logger.info, u"打开编辑对话框")
            self.dlg.SetDialogData(self.filename, self.kid)

        ########## 双击事件 #############
        elif event.GetId() == wx.ID_VIEW_LIST:
            rowObj = self.ProgrameList.GetSelectedObject()
            self.kid = rowObj.kid
            ##清空选择
            self.OnSelectAll()
            ##在双击的行上选择
            allobj = self.ProgrameList.GetObjects()
            self.ProgrameList.SetCheckState(rowObj, True)
            ##需要刷新对象
            self.ProgrameList.RefreshObjects(allobj)

            self.dlg = EditProgramDialog(u"编辑项目", u"请输入编辑程序的相关内容:")
            LoadLog.LogMsg(gen.logger.info, u"打开编辑对话框")
            #kid = "5"
            self.dlg.SetDialogData(self.filename, self.kid)
        else:
            return
        #addpdlg.ShowModal()
        ##增加程序数据
        if self.dlg.ShowModal() == wx.ID_OK:
            ##对话框获取返回的数据
            name, programe, logfile, monitor, operator, processNum, runAs, note = self.dlg.GetDialogData(
            )
            kid = self.kid

            ##对话框返回的数据,调用增加数据的方法来处理
            #print "#####processNum:",processNum
            #print "#####runAs:",runAs
            LoadLog.LogMsg(gen.logger.debug, u"取得对话框的数据")
            self.datahandle.Add_Edit_Data(kid, name, programe, logfile,
                                          monitor, operator, processNum, runAs,
                                          note)
            ##调用handleList()方法,得到给列表控件显示的数据
            gen.IsRunStatusChanged = True
            list_data = self.datahandle.handleList()
            #print u"handle_list处理后显示给列表控件的值",list_data
            ##设置列表控件数据显示
            LoadLog.LogMsg(gen.logger.debug, u"刷新控件列表")
            self.ProgrameList.SetObjects(list_data)
            gen.IsItemChanged = True

        self.dlg.Destroy()

    def OnDelDialog(self, evnt):
        allobj = self.ProgrameList.GetObjects()
        tbool = []
        for obj in allobj:
            tbool.append(self.ProgrameList.IsChecked(obj))
        if tbool.count(True) == 0:
            LoadLog.LogMsg(gen.logger.info, u"未选择删除项")
            wx.MessageBox(u"至少选择一行进行删除!",
                          u'信息',
                          wx.OK | wx.ICON_INFORMATION,
                          parent=self.ProgrameList)
            return
        else:
            pdata = self.datahandle.ReadData()
            #print u"==删除字典项前,从文件读取的字典数据:",pdata
            delList = []
            for obj in allobj:
                if self.ProgrameList.IsChecked(obj) == True:
                    kid = obj.kid
                    #print u"==删除选中的kid ====> ",kid
                    #print pdata[kid]
                    delList.append(kid)
            ##提示是否要删除
            delQuestionDlg = wx.MessageDialog(self.ProgrameList,
                                              u"是否确认要删除所选内容?", u'确认提示',
                                              wx.YES_NO | wx.ICON_QUESTION)
            if delQuestionDlg.ShowModal() == wx.ID_YES:
                LoadLog.LogMsg(gen.logger.warning, u"删除数据项")
                for keyid in delList:
                    ##从列表中删除选中字典项
                    del pdata[keyid]
                self.datahandle.WriteData(pdata)
                list_data = self.datahandle.handleList()
                self.ProgrameList.SetObjects(list_data)
                gen.IsItemChanged = True
            else:
                LoadLog.LogMsg(gen.logger.debug, u"取消删除项")
                self.OnSelectAll()
                del delList
            #self.ProgrameList.RefreshObjects(allobj)
            return
            #datahandle = DataHandle(self.filename)
            #datahandle.WriteData()

    def OnExportDlg(self, event):
        #print "=== onExport dialog ==="
        self.dlg = exportDialog(u"导出数据", self.filename)
        if self.dlg.ShowModal() == wx.ID_OK:
            self.dlg.handleExportDlg()
        self.dlg.Destroy()

    def OnImportDlog(self, event):
        LoadLog.LogMsg(gen.logger.info, u"打开导入对话框")
        wildcard = "Json File (*.json)|*.json|" \
                   "All files (*.*)|*.*"

        importDlg = wx.FileDialog(None, u"选择导入的文件", os.getcwd(), "", wildcard,
                                  wx.OPEN)
        if importDlg.ShowModal() == wx.ID_OK:
            ipathfile = importDlg.GetPath()
            importObj = DataHandle(ipathfile)
            pdata = importObj.ReadData()
            #print u"===从导入文件读取到的字典: ",pdata
            if pdata != None:
                for eachKey in pdata.keys():
                    if eachKey.isdigit():
                        break
                subkeys = [
                    "status", "name", "runAs", "note", "programe",
                    "processNum", "kid", "logfile", "monitor"
                ]
                for kid in pdata.keys():
                    if len(pdata[kid].keys()) != len(subkeys):
                        break
                    for eachsubKey in subkeys:
                        if eachsubKey not in pdata[kid]:
                            break
                #print u"===从导入文件读取到,并通过的字典:",pdata
                writeDlg = wx.MessageDialog(self.ProgrameList,
                                            u"导入的文件数据将覆盖现在程序的数据,是否继续?",
                                            u'确认提示',
                                            wx.YES_NO | wx.ICON_QUESTION)
                if writeDlg.ShowModal() == wx.ID_YES:
                    saveObj = DataHandle(self.filename)
                    saveObj.WriteData(pdata)
                    LoadLog.LogMsg(gen.logger.info, u"成功导入")
                    list_data = self.datahandle.handleList()
                    LoadLog.LogMsg(gen.logger.info, u"刷新控件列表")
                    self.ProgrameList.SetObjects(list_data)
                else:
                    LoadLog.LogMsg(gen.logger.info, u"取消导入")
                    return
            else:
                wx.MessageBox(u"无法导入,类型或错误的文件结构", u'错误', wx.OK | wx.ICON_ERROR)
                LoadLog.LogMsg(gen.logger.error, u"无法导入,类型或错误的文件结构")
        importDlg.Destroy()

    def CheckEdit(self):
        allobj = self.ProgrameList.GetObjects()
        tbool = []
        for obj in allobj:
            tbool.append(self.ProgrameList.IsChecked(obj))
        if tbool.count(True) == 0:
            LoadLog.LogMsg(gen.logger.info, u"未选取项目进行编辑")
            wx.MessageBox(u"请选择一行进行编辑",
                          u'信息',
                          wx.OK | wx.ICON_INFORMATION,
                          parent=self.ProgrameList)
            self.kid = None
        elif tbool.count(True) > 1:
            LoadLog.LogMsg(gen.logger.info, u"不能选取多项同时进行编辑")
            wx.MessageBox(u"一次只能选择一行进行编辑",
                          u'信息',
                          wx.OK | wx.ICON_INFORMATION,
                          parent=self.ProgrameList)
            ##清空选择
            self.OnSelectAll()
            self.kid = None
        else:
            rowObj = self.ProgrameList.GetObjects()
            for obj in rowObj:
                if self.ProgrameList.IsChecked(obj) == True:
                    self.kid = obj.kid
        return self.kid

    def OnSelectAll(self, event=None):
        objects = self.ProgrameList.GetObjects()
        for obj in objects:
            if event == None:
                self.ProgrameList.SetCheckState(obj, False)
            elif event.GetId() == wx.ID_SELECTALL:
                self.ProgrameList.SetCheckState(obj, True)
            else:
                self.ProgrameList.SetCheckState(obj, False)
        self.ProgrameList.RefreshObjects(objects)

    def OnOperationPro(self, event):
        processKidList = []
        objects = self.ProgrameList.GetObjects()
        for obj in objects:
            if self.ProgrameList.IsChecked(obj):
                kid = obj.kid
                processKidList.append(kid)

        if len(processKidList) == 0:
            wx.MessageBox(u"请选择一项进行操作",
                          u'信息',
                          wx.OK | wx.ICON_INFORMATION,
                          parent=self.ProgrameList)
            LoadLog.LogMsg(gen.logger.info, u"未选取项目")
            return

        pdata = self.datahandle.ReadData()
        for kid in processKidList:
            pLastName = pdata[kid]["programe"]
            Pro_Argument = pdata[kid]["logfile"]

            #print u"获取到可执行的程序名称",pLastName
            ProName = str(os.path.basename(pLastName))
            p = os.popen('tasklist /FI "IMAGENAME eq %s"' % ProName)
            GetProNum = p.read().count(ProName)
            if GetProNum == "":
                GetProNum = 0
            LoadLog.LogMsg(gen.logger.debug,
                           u"获取%s进程数为 %d" % (ProName, GetProNum))

            if event.GetId() == gen.ID_START:
                if GetProNum == pdata[kid]["processNum"]:
                    wx.MessageBox(u"该项目的进程已经在运行中",
                                  u'提示信息',
                                  wx.OK | wx.ICON_INFORMATION,
                                  parent=self.ProgrameList)
                    LoadLog.LogMsg(gen.logger.info,
                                   u"该项目的进程%s已经在运行中" % pLastName)
                else:
                    LoadLog.LogMsg(gen.logger.info, u"启动进程%s" % pLastName)
                    try:
                        a = win32api.ShellExecute(0, 'open', pLastName,
                                                  Pro_Argument, '', 1)
                        #self.UpdateRunStatus(kid,True)
                        gen.IsRunStatusChanged = True
                        pdata[kid]["status"] = True
                        list_data = self.datahandle.handleList(pdata)
                        self.ProgrameList.SetObjects(list_data)
                    except:
                        LoadLog.LogMsg(gen.logger.warning,
                                       u"启动进程: %s失败" % ProName)

            elif event.GetId() == gen.ID_STOP:
                #print "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa::::::",pdata[kid]["monitor"]
                if GetProNum != 0:
                    StopDlg = wx.MessageDialog(self.ProgrameList,
                                               u"您确定要结束该进程吗?", u'确认提示',
                                               wx.YES_NO | wx.YES_NO)
                    if StopDlg.ShowModal() == wx.ID_YES:
                        try:
                            LoadLog.LogMsg(gen.logger.warning,
                                           u"结束进程: %s" % ProName)
                            subprocess.Popen("taskkill /F /im  %s" %
                                             os.path.basename(pLastName),
                                             shell=True)
                            #self.UpdateRunStatus(kid,False)
                            gen.IsRunStatusChanged = True
                            pdata[kid]["status"] = False
                            list_data = self.datahandle.handleList(pdata)
                            self.ProgrameList.SetObjects(list_data)
                        except:
                            LoadLog.LogMsg(gen.logger.warning,
                                           u"结束进程: %s失败" % ProName)
                    StopDlg.Destroy()
                else:
                    LoadLog.LogMsg(gen.logger.info, u"当前项目未运行,没有进程可结束")
            else:
                RestartDlg = wx.MessageDialog(self.ProgrameList,
                                              u"您确定要重启该进程吗?", u'确认提示',
                                              wx.YES_NO | wx.ICON_QUESTION)
                if RestartDlg.ShowModal() == wx.ID_YES:
                    if GetProNum != 0:
                        LoadLog.LogMsg(gen.logger.info, u"当前项目未运行,没有进程可结束")
                    try:
                        LoadLog.LogMsg(gen.logger.warning,
                                       u"重启进程: %s" % ProName)
                        subprocess.Popen("taskkill /F /im  %s" %
                                         os.path.basename(pLastName),
                                         shell=True)
                        gen.IsRunStatusChanged = True
                        pdata[kid]["status"] = False
                        time.sleep(2)
                        self.a = win32api.ShellExecute(0, 'open', pLastName,
                                                       Pro_Argument, '', 1)
                        pdata[kid]["status"] = True
                        list_data = self.datahandle.handleList(pdata)
                        self.ProgrameList.SetObjects(list_data)

                    except:
                        LoadLog.LogMsg(gen.logger.warning,
                                       u"重启进程: %s失败" % ProName)
                RestartDlg.Destroy()
        processKidList = []

    # def UpdateRunStatus(self,kid,isRun):
    #     LoadLog.LogMsg(gen.logger.debug,u"更新运行状态")
    #     datahandle = DataHandle(self.filename)
    #     pdata = datahandle.ReadData()
    #     if pdata[kid]["monitor"] == True:
    #         pdata[kid]["status"] = isRun
    #         list_data = datahandle.handleList(pdata)
    #         self.ProgrameList.SetObjects(list_data)
    #     #gen.IsItemRunChanged = False

    def OnOpenLogFile(self, event):
        LoadLog.LogMsg(gen.logger.info, u"打开日志文件%s" % gen.LOGFILE)
        try:
            subprocess.Popen("C:\\windows\\system32\\notepad.exe %s" %
                             gen.LOGFILE,
                             shell=True)
        except:
            LoadLog.LogMsg(gen.logger.warning, u"打开日志文件%s 失败" % gen.LOGFILE)

    def OnHelp(self, event):
        html = HtmlDocDlg(None)
        html.ShowModal()
        html.Destroy()
Beispiel #8
0
 def __init__(self,filename=None,plist=None):
     self.filename = filename
     ##传入列表控件对象
     self.ProgrameList = plist
     self.datahandle = DataHandle(self.filename)
Beispiel #9
0
class EventHandle(object):
    def __init__(self,filename=None,plist=None):
        self.filename = filename
        ##传入列表控件对象
        self.ProgrameList = plist
        self.datahandle = DataHandle(self.filename)

    def OnAdd_Edit_Dialog(self,event):
        #print "add_edit_dialog"
        if event.GetId() == wx.ID_ADD:
            self.dlg = AddProgramDialog(u"增加项目",u"请输入添加项目的相关内容:")
            LoadLog.LogMsg(gen.logger.info,u"打开增加对话框")
            self.kid = None
        elif event.GetId() == wx.ID_EDIT:
            self.kid = self.CheckEdit()
            if self.kid is None:
                return
            self.dlg = EditProgramDialog(u"编辑项目",u"请输入编辑项目的相关内容:")
            LoadLog.LogMsg(gen.logger.info,u"打开编辑对话框")
            self.dlg.SetDialogData(self.filename,self.kid)

        ########## 双击事件 #############
        elif event.GetId() == wx.ID_VIEW_LIST:
            rowObj = self.ProgrameList.GetSelectedObject()
            self.kid = rowObj.kid
            ##清空选择
            self.OnSelectAll()
            ##在双击的行上选择
            allobj = self.ProgrameList.GetObjects()
            self.ProgrameList.SetCheckState(rowObj, True)
            ##需要刷新对象
            self.ProgrameList.RefreshObjects(allobj)

            self.dlg = EditProgramDialog(u"编辑项目",u"请输入编辑程序的相关内容:")
            LoadLog.LogMsg(gen.logger.info,u"打开编辑对话框")
            #kid = "5"
            self.dlg.SetDialogData(self.filename,self.kid)
        else:
            return
        #addpdlg.ShowModal()
        ##增加程序数据
        if self.dlg.ShowModal() == wx.ID_OK:
            ##对话框获取返回的数据
            name,programe,logfile,monitor,operator,processNum,runAs,note = self.dlg.GetDialogData()
            kid = self.kid

            ##对话框返回的数据,调用增加数据的方法来处理
            #print "#####processNum:",processNum
            #print "#####runAs:",runAs
            LoadLog.LogMsg(gen.logger.debug,u"取得对话框的数据")
            self.datahandle.Add_Edit_Data(kid,name,programe,logfile,monitor,operator,processNum,runAs,note)
            ##调用handleList()方法,得到给列表控件显示的数据
            gen.IsRunStatusChanged = True
            list_data = self.datahandle.handleList()
            #print u"handle_list处理后显示给列表控件的值",list_data
            ##设置列表控件数据显示
            LoadLog.LogMsg(gen.logger.debug,u"刷新控件列表")
            self.ProgrameList.SetObjects(list_data)
            gen.IsItemChanged = True

        self.dlg.Destroy()

    def OnDelDialog(self,evnt):
        allobj = self.ProgrameList.GetObjects()
        tbool = []
        for obj in allobj:
            tbool.append(self.ProgrameList.IsChecked(obj))
        if tbool.count(True) == 0:
            LoadLog.LogMsg(gen.logger.info,u"未选择删除项")
            wx.MessageBox(u"至少选择一行进行删除!", u'信息', wx.OK | wx.ICON_INFORMATION,parent=self.ProgrameList)
            return
        else:
            pdata = self.datahandle.ReadData()
            #print u"==删除字典项前,从文件读取的字典数据:",pdata
            delList = []
            for obj in allobj:
                if self.ProgrameList.IsChecked(obj) == True:
                    kid = obj.kid
                    #print u"==删除选中的kid ====> ",kid
                    #print pdata[kid]
                    delList.append(kid)
            ##提示是否要删除
            delQuestionDlg =  wx.MessageDialog(self.ProgrameList,u"是否确认要删除所选内容?", u'确认提示',
                                               wx.YES_NO|wx.ICON_QUESTION)
            if delQuestionDlg.ShowModal() == wx.ID_YES:
                LoadLog.LogMsg(gen.logger.warning,u"删除数据项")
                for keyid in delList:
                    ##从列表中删除选中字典项
                    del pdata[keyid]
                self.datahandle.WriteData(pdata)
                list_data = self.datahandle.handleList()
                self.ProgrameList.SetObjects(list_data)
                gen.IsItemChanged = True
            else:
                LoadLog.LogMsg(gen.logger.debug,u"取消删除项")
                self.OnSelectAll()
                del delList
            #self.ProgrameList.RefreshObjects(allobj)
            return
            #datahandle = DataHandle(self.filename)
            #datahandle.WriteData()

    def OnExportDlg(self,event):
        #print "=== onExport dialog ==="
        self.dlg = exportDialog(u"导出数据",self.filename)
        if self.dlg.ShowModal() == wx.ID_OK:
            self.dlg.handleExportDlg()
        self.dlg.Destroy()

    def OnImportDlog(self,event):
        LoadLog.LogMsg(gen.logger.info,u"打开导入对话框")
        wildcard = "Json File (*.json)|*.json|" \
                   "All files (*.*)|*.*"

        importDlg = wx.FileDialog(None, u"选择导入的文件",os.getcwd(), "", wildcard, wx.OPEN)
        if importDlg.ShowModal() == wx.ID_OK:
            ipathfile = importDlg.GetPath()
            importObj = DataHandle(ipathfile)
            pdata = importObj.ReadData()
            #print u"===从导入文件读取到的字典: ",pdata
            if pdata != None:
                for eachKey in pdata.keys():
                    if eachKey.isdigit():
                        break
                subkeys = ["status","name","runAs","note","programe","processNum","kid","logfile","monitor"]
                for kid in pdata.keys():
                    if len(pdata[kid].keys()) != len(subkeys):
                        break
                    for eachsubKey in subkeys:
                        if eachsubKey not in pdata[kid]:
                            break
                #print u"===从导入文件读取到,并通过的字典:",pdata
                writeDlg = wx.MessageDialog(self.ProgrameList,u"导入的文件数据将覆盖现在程序的数据,是否继续?", u'确认提示',
                                               wx.YES_NO|wx.ICON_QUESTION)
                if writeDlg.ShowModal() == wx.ID_YES:
                    saveObj = DataHandle(self.filename)
                    saveObj.WriteData(pdata)
                    LoadLog.LogMsg(gen.logger.info,u"成功导入")
                    list_data = self.datahandle.handleList()
                    LoadLog.LogMsg(gen.logger.info,u"刷新控件列表")
                    self.ProgrameList.SetObjects(list_data)
                else:
                    LoadLog.LogMsg(gen.logger.info,u"取消导入")
                    return
            else:
                wx.MessageBox(u"无法导入,类型或错误的文件结构", u'错误', wx.OK | wx.ICON_ERROR)
                LoadLog.LogMsg(gen.logger.error,u"无法导入,类型或错误的文件结构")
        importDlg.Destroy()

    def CheckEdit(self):
        allobj = self.ProgrameList.GetObjects()
        tbool = []
        for obj in allobj:
            tbool.append(self.ProgrameList.IsChecked(obj))
        if tbool.count(True) == 0:
            LoadLog.LogMsg(gen.logger.info,u"未选取项目进行编辑")
            wx.MessageBox(u"请选择一行进行编辑", u'信息', wx.OK | wx.ICON_INFORMATION,parent=self.ProgrameList)
            self.kid = None
        elif tbool.count(True) > 1:
            LoadLog.LogMsg(gen.logger.info,u"不能选取多项同时进行编辑")
            wx.MessageBox(u"一次只能选择一行进行编辑", u'信息', wx.OK | wx.ICON_INFORMATION,parent=self.ProgrameList)
            ##清空选择
            self.OnSelectAll()
            self.kid = None
        else:
            rowObj = self.ProgrameList.GetObjects()
            for obj in rowObj:
                if self.ProgrameList.IsChecked(obj) == True:
                    self.kid = obj.kid
        return self.kid

    def OnSelectAll(self,event=None):
        objects = self.ProgrameList.GetObjects()
        for obj in objects:
            if event == None:
                self.ProgrameList.SetCheckState(obj, False)
            elif event.GetId() == wx.ID_SELECTALL:
                self.ProgrameList.SetCheckState(obj, True)
            else:
                self.ProgrameList.SetCheckState(obj,False)
        self.ProgrameList.RefreshObjects(objects)


    def OnOperationPro(self,event):
        processKidList = []
        objects = self.ProgrameList.GetObjects()
        for obj in objects:
            if self.ProgrameList.IsChecked(obj):
                kid = obj.kid
                processKidList.append(kid)

        if len(processKidList) == 0:
             wx.MessageBox(u"请选择一项进行操作", u'信息', wx.OK | wx.ICON_INFORMATION,parent=self.ProgrameList)
             LoadLog.LogMsg(gen.logger.info,u"未选取项目")
             return

        pdata = self.datahandle.ReadData()
        for kid in processKidList:
            pLastName = pdata[kid]["programe"]
            Pro_Argument = pdata[kid]["logfile"]

            #print u"获取到可执行的程序名称",pLastName
            ProName = str(os.path.basename(pLastName))
            p = os.popen('tasklist /FI "IMAGENAME eq %s"' % ProName)
            GetProNum = p.read().count(ProName)
            if GetProNum == "":
                GetProNum = 0
            LoadLog.LogMsg(gen.logger.debug,u"获取%s进程数为 %d" % (ProName,GetProNum))

            if event.GetId() == gen.ID_START:
                if GetProNum == pdata[kid]["processNum"] :
                    wx.MessageBox(u"该项目的进程已经在运行中", u'提示信息', wx.OK | wx.ICON_INFORMATION,parent=self.ProgrameList)
                    LoadLog.LogMsg(gen.logger.info,u"该项目的进程%s已经在运行中" % pLastName)
                else:
                    LoadLog.LogMsg(gen.logger.info,u"启动进程%s" % pLastName)
                    try:
                        a = win32api.ShellExecute(0, 'open', pLastName, Pro_Argument,'',1)
                        #self.UpdateRunStatus(kid,True)
                        gen.IsRunStatusChanged = True
                        pdata[kid]["status"] = True
                        list_data = self.datahandle.handleList(pdata)
                        self.ProgrameList.SetObjects(list_data)
                    except:
                         LoadLog.LogMsg(gen.logger.warning,u"启动进程: %s失败" % ProName)

            elif event.GetId() == gen.ID_STOP:
                #print "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa::::::",pdata[kid]["monitor"]
                if GetProNum != 0 :
                    StopDlg =  wx.MessageDialog(self.ProgrameList,u"您确定要结束该进程吗?", u'确认提示',
                                               wx.YES_NO|wx.YES_NO)
                    if StopDlg.ShowModal() == wx.ID_YES:
                        try:
                            LoadLog.LogMsg(gen.logger.warning,u"结束进程: %s" % ProName)
                            subprocess.Popen("taskkill /F /im  %s" % os.path.basename(pLastName) , shell=True)
                            #self.UpdateRunStatus(kid,False)
                            gen.IsRunStatusChanged = True
                            pdata[kid]["status"] = False
                            list_data = self.datahandle.handleList(pdata)
                            self.ProgrameList.SetObjects(list_data)
                        except:
                             LoadLog.LogMsg(gen.logger.warning,u"结束进程: %s失败" % ProName)
                    StopDlg.Destroy()
                else:
                    LoadLog.LogMsg(gen.logger.info,u"当前项目未运行,没有进程可结束")
            else:
                RestartDlg =  wx.MessageDialog(self.ProgrameList,u"您确定要重启该进程吗?", u'确认提示',
                                                   wx.YES_NO|wx.ICON_QUESTION)
                if RestartDlg.ShowModal() == wx.ID_YES:
                    if GetProNum != 0 :
                        LoadLog.LogMsg(gen.logger.info,u"当前项目未运行,没有进程可结束")
                    try:
                        LoadLog.LogMsg(gen.logger.warning,u"重启进程: %s" % ProName)
                        subprocess.Popen("taskkill /F /im  %s" % os.path.basename(pLastName) , shell=True)
                        gen.IsRunStatusChanged = True
                        pdata[kid]["status"] = False
                        time.sleep(2)
                        self.a = win32api.ShellExecute(0, 'open', pLastName, Pro_Argument,'',1)
                        pdata[kid]["status"] = True
                        list_data = self.datahandle.handleList(pdata)
                        self.ProgrameList.SetObjects(list_data)

                    except:
                        LoadLog.LogMsg(gen.logger.warning,u"重启进程: %s失败" % ProName)
                RestartDlg.Destroy()
        processKidList = []

    # def UpdateRunStatus(self,kid,isRun):
    #     LoadLog.LogMsg(gen.logger.debug,u"更新运行状态")
    #     datahandle = DataHandle(self.filename)
    #     pdata = datahandle.ReadData()
    #     if pdata[kid]["monitor"] == True:
    #         pdata[kid]["status"] = isRun
    #         list_data = datahandle.handleList(pdata)
    #         self.ProgrameList.SetObjects(list_data)
    #     #gen.IsItemRunChanged = False

    def OnOpenLogFile(self,event):
        LoadLog.LogMsg(gen.logger.info,u"打开日志文件%s" % gen.LOGFILE)
        try:
            subprocess.Popen("C:\\windows\\system32\\notepad.exe %s" % gen.LOGFILE, shell=True)
        except:
            LoadLog.LogMsg(gen.logger.warning,u"打开日志文件%s 失败" % gen.LOGFILE)

    def OnHelp(self,event):
        html = HtmlDocDlg(None)
        html.ShowModal()
        html.Destroy()
Beispiel #10
0
 def SetDataInListctrl(self, filename):
     LoadLog.LogMsg(gen.logger.info, u"加载控件列表,初始化数据")
     ##获取数据列表
     self.list_data = DataHandle(filename).handleList()
     ##设置数据列表到列表控件
     self.ProgrameList.SetObjects(self.list_data)
Beispiel #11
0
 def LoadData(self):
     self.rf = rf = DataHandle(gen._filedata)
     self.pdata = rf.ReadData()