예제 #1
0
 def initSvnLogDir(self):
     self.checkDir()
     try:
         entry = self.client.info(self.GlogDir)
         #print "entry:",entry.url
         #print "SvnLogUrl:",self.SvnLogUrl
         if entry.url != self.SvnLogUrl:
             LoadLog.LogMsg(self.sysLogName.info,
                            u"检测到全局日志%s有问题" % self.GlogDir)
             LoadLog.LogMsg(self.sysLogName.info,
                            u"删除全局日志 %s " % self.GlogDir)
             self.CleanDir(self.GlogDir)
             try:
                 netheck = self.ping(self.num)
                 if netheck is True:
                     LoadLog.LogMsg(self.sysLogName.info,
                                    u"重新Checkout 全局日志 %s " % self.GlogDir)
                     self.client.checkout(self.SvnLogUrl, self.GlogDir)
             except:
                 LoadLog.LogMsg(self.sysLogName.error,
                                u"网络不正常,checkout全局日志出错" % self.GlogDir)
                 GL.NetStatus = u"断开"
                 return True
         else:
             return False
     except:
         return False
예제 #2
0
 def rollback_cmd(self, flist, RemoteDir, BackupDir, rhost, rport=22):
     self.connect()
     self.OpenUpload(GL.RIPaddr, GL.MonitorDir, GL.Monitor_Upload_File,
                     GL.RPort)
     GL.rollbacked_list = []
     count = 0
     fnum = len(flist)
     #update_list = []
     #GL.backup_list = []
     dlg = wx.ProgressDialog(u"进程条",
                             u"正在上传更新,请稍等...",
                             maximum=fnum,
                             style=0
                             | wx.PD_APP_MODAL | wx.PD_CAN_ABORT
                             | wx.PD_ESTIMATED_TIME | wx.PD_REMAINING_TIME
                             | wx.PD_AUTO_HIDE)
     dlg.ShowModal()
     self.keepGoing = True
     for each_file in flist:
         if '_bak_' not in each_file:
             continue
         #print each_file.split('_bak_')[0]
         #print each_file.split('_bak_')[0].split(BackupDir)[1]
         ori_each = "".join(
             [RemoteDir,
              each_file.split('_bak_')[0].split(BackupDir)[1]])
         #print ori_each
         cmd_copy = "ssh -p %d  %s 'cp -a %s %s;chown -R www.www %s'" % (
             rport, rhost, each_file, ori_each, ori_each)
         stdin, stdout, stderr = self.client.exec_command(cmd_copy)
         message = stdout.readlines()
         error = stderr.readlines()
         if len(error) > 0:
             msg = u"还原文件 %s 失败,错误信息: %s" % (each_file, message)
             gmsg = u"%s, 失败" % each_file
             LoadLog.LogMsg(GL.logger_PubLog.warning, msg)
             GL.rollbacked_list.append(gmsg)
         else:
             exit_status = stdout.channel.recv_exit_status()
             if exit_status != 0:
                 msg = u"还原文件发生错误,文件 %s 不存在,请检查。" % each_file
                 gmsg = u"%s, 失败" % each_file
                 LoadLog.LogMsg(GL.logger_PubLog.error, msg)
                 GL.rollbacked_list.append(gmsg)
             else:
                 msg = u"已还原文件 %s" % each_file
                 gmsg = u"%s, 成功" % each_file
                 LoadLog.LogMsg(GL.logger_PubLog.info, msg)
                 GL.rollbacked_list.append(gmsg)
         count += 1
         (self.keepGoing, skip) = dlg.Update(count)
     dlg.Destroy()
     if self.keepGoing is True:
         wx.MessageBox(u"列表中的文件已还原! 详细请查看日志.",
                       u"完成确认",
                       style=wx.OK | wx.ICON_INFORMATION)
     else:
         wx.MessageBox(u"还原中止更新!", u"信息", style=wx.OK | wx.ICON_INFORMATION)
     GL.logger_PubLog.info("")
     self.ShutdownUpload(GL.RIPaddr, GL.Monitor_Upload_File, GL.RPort)
예제 #3
0
    def checkDir(self):
        if not os.path.exists(GL.LogDir):
            try:
                os.mkdir(GL.LogDir)
            except:
                pass
        if not os.path.exists(GL.dataDir):
            try:
                os.mkdir(GL.dataDir)
            except:
                pass

        if not os.path.exists(self.GlogDir):
            LoadLog.LogMsg(self.sysLogName.info, u"全局日志目录不存在")
            netcheck = self.ping(self.num)
            if netcheck is True:
                #print "netcheck",netcheck
                try:
                    self.client.callback_get_login = self.get_login
                    LoadLog.LogMsg(self.sysLogName.info,
                                   u"Checkout 全局日志 %s " % self.GlogDir)
                    self.client.checkout(self.SvnLogUrl, self.GlogDir)
                    #self.client.checkout("http://192.168.2.16/svn",self.GlogDir)
                except:
                    LoadLog.LogMsg(self.sysLogName.error,
                                   u"全局日志 %s 文件夹checkout出错" % self.GlogDir)
                    return True
            else:
                LoadLog.LogMsg(self.sysLogName.warning,
                               u"无法 ping 通 IP %s" % self.LIPaddr)
예제 #4
0
 def RefreshLog(self):
     self.client.callback_get_login = self.get_login
     Login, loginMsg = self.AuthUserPass(self.SvnLogUrl, self.SvnUser,
                                         self.SvnPass)
     if Login is False:
         wx.MessageBox(loginMsg, u"错误提示", style=wx.OK | wx.ICON_ERROR)
         LoadLog.LogMsg(self.sysLogName.error, loginMsg)
         return
     try:
         self.client.update(self.GlogDir)
         wx.MessageBox(u"完成全局日志同步到本地",
                       u"提示",
                       style=wx.OK | wx.ICON_INFORMATION)
         LoadLog.LogMsg(self.sysLogName.info, u"完成全局日志同步到本地")
         time.sleep(2)
     except:
         try:
             self.client.cleanup(self.GlogDir)
             self.client.update(self.GlogDir)
             wx.MessageBox(u"完成全局日志更新到本地",
                           u"提示",
                           style=wx.OK | wx.ICON_INFORMATION)
             LoadLog.LogMsg(self.sysLogName.info, u"完成全局日志同步到本地")
             time.sleep(2)
         except:
             msg = u"全局日志更新出错"
             wx.MessageBox(msg, style=wx.OK | wx.ICON_ERROR)
             LoadLog.LogMsg(self.sysLogName.error, msg)
예제 #5
0
    def writeGlobal_log(self, logdataList, handle, logName, logPanel):
        #print "write user:"******"错误提示", style=wx.OK|wx.ICON_ERROR)
            LoadLog.LogMsg(self.sysLogName.error, loginMsg)
            raise ValueError, loginMsg
        try:
            self.client.update(self.GlogDir)
        except:
            try:
                self.client.cleanup(self.GlogDir)
                self.client.update(self.GlogDir)
            except:
                LoadLog.LogMsg(self.sysLogName.error, u"全局日志更新出错")
                return
        tstr = time.strftime('%Y-%m-%d %H:%M:%S')
        msg = "\n".join(logdataList)
        if logPanel == "publish":
            msg2 = u"更新了如下文件:"
        elif logPanel == "backup":
            msg2 = u"备份了如下文件:"
        else:
            msg2 = u"还原了如下文件:"

        myformat = u"######## %s [%s] %s ########\n%s\n" % (tstr, self.SvnUser,
                                                            msg2, msg)
        handle.setFormatter(logging.Formatter(myformat))
        LoadLog.LogMsg(logName.info, msg)
        self.CommitToSvn(GL.GlogDir)
예제 #6
0
 def ShutdownUpload(self, rhost, monitor_upload_file, rport=22):
     cmd_shutdownUpload = """ssh -p %d %s  'echo "1">%s && chmod 640 %s'""" % (
         rport, rhost, monitor_upload_file, monitor_upload_file)
     stdin, stdout, stderr = self.client.exec_command(cmd_shutdownUpload)
     exit_status = stdout.channel.recv_exit_status()
     message = stdout.readlines()
     error = stderr.readlines()
     if len(error) > 0 or exit_status != 0:
         msg = u"未能正常关闭上传,错误信息:%s" % message
         LoadLog.LogMsg(GL.logger_sysLog.error, msg)
     else:
         LoadLog.LogMsg(GL.logger_sysLog.info, u"已经关闭上传选项")
예제 #7
0
 def OpenUpload(self, rhost, monitor_dir, monitor_upload_file, rport=22):
     cmd_openUpload = """ssh -p %d %s  'test ! -d %s && mkdir -pv %s;\
     echo "0">%s  && chmod 640 %s'""" \
                      %(rport,rhost,monitor_dir,monitor_dir,monitor_upload_file,monitor_upload_file)
     #LoadLog.LogMsg(GL.logger_sysLog.info,u"打开上传")
     stdin, stdout, stderr = self.client.exec_command(cmd_openUpload)
     exit_status = stdout.channel.recv_exit_status()
     message = stdout.readlines()
     error = stderr.readlines()
     print message, exit_status
     if len(error) > 0:
         msg = u"打开允许上传失败,错误信息:%s" % message
         LoadLog.LogMsg(GL.logger_sysLog.error, msg)
     else:
         LoadLog.LogMsg(GL.logger_sysLog.info, u"已经开启上传选项")
예제 #8
0
 def FileContents(self, filePath, fileCode):
     if not os.path.exists(filePath):
         msg = u"全局日志文件不存在."
         wx.MessageBox(msg, u"错误", style=wx.OK | wx.ICON_ERROR)
         LoadLog.LogMsg(GL.logger_sysLog.error, msg)
         return ""
     self.FileContentList = []
     try:
         import codecs
         with codecs.open(filePath, 'r', fileCode) as FileObj:
             [self.FileContentList.append(line) for line in FileObj]
     except UnicodeDecodeError, errorMsg:
         msg = u"读取全局日志文件出错." + errorMsg
         LoadLog.LogMsg(GL.logger_sysLog.error, msg)
         wx.MessageBox(msg, u"错误", style=wx.OK | wx.ICON_ERROR)
         return "codeError"
예제 #9
0
 def GetUserLogList(self, filelog, isFilter):
     if not os.path.exists(filelog):
         msg = u"读取全局日志文件出错."
         LoadLog.LogMsg(GL.logger_sysLog.error, msg)
         wx.MessageBox(msg, u"错误", style=wx.OK | wx.ICON_ERROR)
         FileContentList = []
         return FileContentList
     FileContentList = []
     with open(filelog, 'r') as f:
         if isFilter is True:
             bad = 0
             import codecs, re
             goodline = re.compile(ur'#+?.*\[%s\].*#$' % GL.SvnUser)
             badline = re.compile(ur'#+?.*\[((?!%s).)*#$' % GL.SvnUser)
             for line in f:
                 line = unicode(line, "utf8")
                 if goodline.search(line) is not None:
                     #print line
                     bad = 1
                     FileContentList.append(line.strip())
                     continue
                 if bad and badline.search(line) is None:
                     #print line
                     FileContentList.append(line.strip())
                     continue
                 else:
                     bad = 0
         else:
             [FileContentList.append(unicode(line, "utf8")) for line in f]
     return FileContentList
예제 #10
0
    def CommitToSvn(self, svnDir):
        try:
            f = open(GL.global_backup_logfile, "r")
            f.close()
            f = open(GL.gloabl_publish_logfile, "r")
            f.close()
        except:
            pass
        #time.sleep(1)
        #self.allCommitList = []
        #self.client.update(svnDir)
        #Login,loginMsg = self.AuthUserPass(self.SvnLogUrl,self.SvnUser,self.SvnPass)
        self.allCommitList = self.CheckSvnFile(svnDir)
        #print self.allCommitList

        for itemvalues in self.allCommitList:
            #for itemvalues in allCommitList:
            if itemvalues[1] == "conflicted":
                LoadLog.LogMsg(self.sysLogName.warning,
                               u"有svn冲突文件,请用TortoiseSVN操作")
                return
            if itemvalues[1] == "non-versioned":
                self.client.add(itemvalues[0])
            if itemvalues[1] == "missing":
                self.client.remove(itemvalues[0])

            self.client.checkin(itemvalues[0], " ")
예제 #11
0
 def TimeSync(self, ntpServers):
     import ntplib
     c = ntplib.NTPClient()
     if len(ntpServers) == 0:
         return
     ntpServers = ntpServers.split(",")
     for ntpServer in ntpServers:
         try:
             response = c.request(ntpServer)
         except ntplib.NTPException, e:
             if ntpServer == ntpServers[-1]:
                 msg = u"无法同步时间,请检测本地时间是否正确."
                 LoadLog.LogMsg(self.sysLogName.warning, msg)
                 break
             else:
                 continue
         except:
예제 #12
0
    def publish_cmd(self,
                    flist,
                    LocalDir,
                    BackupDir,
                    RemoteDir,
                    rhost,
                    rport=22):
        self.connect()
        self.OpenUpload(GL.RIPaddr, GL.MonitorDir, GL.Monitor_Upload_File,
                        GL.RPort)
        count = 0
        fnum = len(flist)
        #update_list = []
        GL.PublishList = []
        GL.backup_list = []
        dlg = wx.ProgressDialog(u"进程条",
                                u"正在上传更新,请稍等...",
                                maximum=fnum,
                                style=0
                                | wx.PD_APP_MODAL | wx.PD_CAN_ABORT
                                | wx.PD_ESTIMATED_TIME | wx.PD_REMAINING_TIME
                                | wx.PD_AUTO_HIDE)
        dlg.ShowModal()
        self.keepGoing = True
        for each_file in flist:
            #print self.keepGoing,count
            if self.keepGoing is False:
                break
            commands = []
            nowtime = time.strftime("%Y%m%d-%H%M%S", time.localtime())

            full_local_each_file = ''.join([LocalDir, each_file])
            full_remote_each_file = ''.join([RemoteDir, each_file])
            backup_file = "".join([BackupDir, each_file, '_bak_', nowtime])
            #print backup_file
            #print full_each_file
            predir = os.path.dirname(full_remote_each_file)
            #print predir
            cmd_testdir = "ssh -p %d %s 'test ! -d %s && mkdir -pv %s; \
                                   test ! -d %s && mkdir -pv %s'" \
                                   %(rport,rhost,predir,predir,os.path.dirname(backup_file),os.path.dirname(backup_file))
            cmd_backup = "ssh -p %d %s 'test -f %s && /bin/cp -a %s %s'" \
                         %(rport,rhost,full_remote_each_file,full_remote_each_file,backup_file)
            cmd_scp = "scp -P %d -r %s %s\:%s" % (rport, full_local_each_file,
                                                  rhost, full_remote_each_file)
            cmd_chown = "ssh -p %d %s 'chown www.www %s'" % (
                rport, rhost, full_remote_each_file)

            #print full_local_each_file,rhost,full_remote_each_file

            commands.append(cmd_testdir)
            commands.append(cmd_backup)
            commands.append(cmd_scp)
            commands.append(cmd_chown)
            for each_cmd in commands:
                stdin, stdout, stderr = self.client.exec_command(each_cmd)
                exit_status = stdout.channel.recv_exit_status()
                message = stdout.readlines()
                error = stderr.readlines()
                if each_cmd == cmd_backup:
                    #print stdout.readlines()
                    if len(error) > 0:
                        msg = u"备份文件 %s 失败,错误信息: %s" % (full_local_each_file,
                                                        message)
                        LoadLog.LogMsg(GL.logger_BakLog.warning, msg)
                    else:
                        if exit_status != 0:
                            msg = u"原文件 %s 不存在,未备份." % each_file
                        else:
                            msg = u"文件已备份为: %s" % backup_file
                            GL.backup_list.append(backup_file)
                    LoadLog.LogMsg(GL.logger_BakLog.info, msg)
                if each_cmd == cmd_scp:
                    if len(error) > 0:
                        msg = u"更新文件 %s 失败,错误信息: %s" % (full_local_each_file,
                                                        message)
                        gmsg = u"%s, 失败" % full_local_each_file
                        LoadLog.LogMsg(GL.logger_PubLog.warning, msg)
                        GL.PublishList.append(gmsg)
                    else:
                        msg = u"成功更新文件: %s" % full_local_each_file
                        gmsg = u"%s, 成功" % full_local_each_file
                        LoadLog.LogMsg(GL.logger_PubLog.info, msg)
                        GL.PublishList.append(gmsg)
            count += 1
            (self.keepGoing, skip) = dlg.Update(count)
        dlg.Destroy()
        if self.keepGoing is True:
            wx.MessageBox(u"完成文件的更新发布! 详细请查看日志.",
                          u"完成确认",
                          style=wx.OK | wx.ICON_INFORMATION)
        else:
            wx.MessageBox(u"已经中止更新!", u"信息", style=wx.OK | wx.ICON_INFORMATION)
            #update_list.append(msg)
        # for each_msg in update_list:
        # LoadLog.LogMsg(GL.loggera.warning,each_msg)
        # LoadLog.LogMsg(GL.loggera.warning,"")
        # #
        # for each_msg in backup_list:
        # LoadLog.LogMsg(GL.loggerb.warning,each_msg)
        GL.logger_PubLog.info("")
        GL.logger_BakLog.info("")
        self.ShutdownUpload(GL.RIPaddr, GL.Monitor_Upload_File, GL.RPort)