python3 写的一个通过ftp远程批量处理的工具__界面处理代码详解编程语言

# -*- coding: utf-8 -*- 
from PyQt5 import QtCore, QtGui, QtWidgets 
from PyQt5.Qt import Qt, QFileDialog, QMessageBox, QStandardItemModel,/ 
    QModelIndex, QAbstractItemView, QThread, QProgressDialog 
from ftpFun import ftpInterface 
from ftpXML import ftpXml 
import os 
class PGThread(QThread): 
    _signal = QtCore.pyqtSignal(int) 
    pgValue = 0 
    def __init__(self, parent = None): 
        QThread.__init__(self, parent) 
        self._signal.connect(self.parent().setPgValue) 
     
    def initTask(self, curInfoL, taskID): 
        self.curInfo = curInfoL 
        self.taskID = taskID 
        '''taskID = 1 upload  taskID = 2 remove  taskID = 3 rename''' 
        #self.pgdlg.exec_() 
         
    def run(self): 
        row = 0 
        strInfo = '' 
        step = int(100 / len(self.curInfo)) 
        tmpValue = step 
        isContinue = True 
        for cur in self.curInfo: 
            print(cur) 
            if(isContinue):         
                ftpObj = ftpInterface(cur['ip'], 21, 'xxx', 'xxxxx') 
                ftpObj.setlocalPath('') 
                if(self.taskID == 1): 
                    upFilePath = self.parent().folderLineEdit.text() 
                    print(upFilePath) 
                    ret = ftpObj.ftpUpLoadFile(upFilePath) 
                    if(ret == -1): 
                        isContinue = False 
                        strInfo = "未找到/voicePrompt/1文件夹" 
                    elif(ret == -3): 
                        isContinue = False 
                        strInfo = "请检查输入路径下无文件数据" 
                    elif(ret == -2): 
                        strInfo = "上传时出现异常" 
                    else: 
                        strInfo = "文件已上传请检查" 
                elif(self.taskID == 2): 
                    removePath = self.parent().folderLineEdit.text() 
                    ret = ftpObj.ftpRemoveFile(removePath) 
                    if(ret == -1): 
                        isContinue = False 
                        strInfo = "未找到/voicePrompt/1文件夹" 
                    elif(ret == -2): 
                        strInfo = "删除时出现异常有可能文件不存在" 
                    else: 
                        strInfo = "文件已删除请检查" 
                elif(self.taskID == 3): 
                    beforeName = self.parent().beforeLineEdit.text() 
                    afterName = self.parent().afterLineEdit.text() 
                    tmpName = os.path.basename(afterName) 
                    dirName = os.path.dirname(beforeName) 
                    aName = dirName + '//' + tmpName 
                    ret = ftpObj.ftpRenameFile(beforeName, aName) 
                    if(ret == -1): 
                        isContinue = False 
                        strInfo = "未找到/voicePrompt/1文件夹" 
                    elif(ret == -2): 
                        strInfo = "修改时出现异常有可能文件不存在" 
                    else: 
                        strInfo = "文件已修改请检查" 
            self.parent().Model.setData(self.parent().Model.index(row, 0, QModelIndex()), cur['name']) 
            self.parent().Model.setData(self.parent().Model.index(row, 1, QModelIndex()), strInfo) 
            row += 1 
            tmpValue += step 
            tmpValue += 1 
            self._signal.emit(tmpValue) 
            print(tmpValue) 
        self.parent().logTbView.setModel(self.parent().Model) 
class Ui_Ftp(object): 
    def setupUi(self, Ftp):         
        self.retranslateUi(Ftp) 
        QtCore.QMetaObject.connectSlotsByName(Ftp) 
         
        '''设置最小化按钮''' 
        self.setWindowFlags(Qt.Widget) 
        #self.setWindowFlags(Qt.WindowMaximizeButtonHint) 
        self.radioButton.setChecked(True) 
        self.ftpPathLineEdit.setText("/voicePrompt/1") 
        #self.ftpPathLineEdit.setDisabled(True) 
        self.ftpPathLineEdit.setReadOnly(True) 
        self.hideRenameElemt(False) 
         
        self.ckBoxList = []; 
        self.checkBoxSignal() 
         
        '''信号和槽''' 
        self.allCheckBtn.clicked.connect(self.allCheckBtnClicked) 
        self.clearBtn.clicked.connect(self.clearBtnClicked) 
        self.isShowArea = False 
        self.areaShwoBtn.clicked.connect(self.areaShowBtnClicked) 
        self.openBtn.clicked.connect(self.openBtnClicked) 
        self.execBtn.clicked.connect(self.execBtnClicked) 
         
         
        '''operator''' 
        self.radioButton.clicked['bool'].connect(self.upLoadSetting) 
        self.radioButton_2.clicked['bool'].connect(self.RemoveFileSetting) 
        self.radioButton_3.clicked['bool'].connect(self.RenameFileSetting) 
         
        '''ftp ip info''' 
        ftpX = ftpXml() 
        self.ipInfo = ftpX.getServerInfo() 
         
        '''exec log''' 
        '''设置qtabview''' 
        self.Model = QStandardItemModel() 
    def setPgValue(self, value): 
        if(value >= 100): 
            self.pg.close() 
            return 
        self.pg.setValue(value) 
     
    '''具体执行操作''' 
    def execBtnClicked(self): 
        ret = self.execLimit() 
        if(ret == -1): 
            return 
        curInfoL = self.getAreaIpInfo() 
        if(not curInfoL): 
            QMessageBox.warning(self, '错误', '请检查serverinfo.xml是否存在', QMessageBox.Ok) 
            return 
         
        pt = PGThread(self) 
        self.pg = QProgressDialog() 
        self.pg.setModal(True) 
        self.pg.show() 
         
        self.Model.clear() 
        self.Model.setRowCount(len(curInfoL)) 
        self.Model.setColumnCount(2) 
        self.Model.setHorizontalHeaderLabels(['地区', '执行情况']) 
        self.logTbView.setEditTriggers(QAbstractItemView.NoEditTriggers) 
        self.logTbView.update() 
        taskId = 0 
        pgTitle = '' 
        if(self.radioButton.isChecked()): 
            taskId = 1 
            pgTitle = "正在上传..." 
        elif(self.radioButton_2.isChecked()): 
            taskId = 2 
            pgTitle = "正在上传..." 
        elif(self.radioButton_3.isChecked()): 
            taskId = 3 
            pgTitle = "正在修改..." 
        self.pg.setWindowTitle(pgTitle) 
        self.pg.setLabelText("请稍后...") 
        self.pg.setCancelButton(None) 
        self.pg.setWindowFlags(Qt.WindowMinimizeButtonHint) 
        pt.initTask(curInfoL, taskId) 
        pt.start() 
             
             
    def getAreaIpInfo(self): 
        areaStr = self.areaLineEdit.text() 
        areaList = areaStr.split('、') 
        '''find areaIp in self.ipinfo''' 
        curInfo = [] 
        for area in areaList: 
            for ftpArea in self.ipInfo: 
                if(area == ftpArea['name']): 
                    ip = ftpArea['ip'] 
                    curInfo.append(ftpArea) 
                    break 
        return curInfo 
     
    def execLimit(self): 
        if(self.areaLineEdit.text() == ""): 
            QMessageBox.information(self, "提示", "请输入地区,多个地区用'、'隔开", QMessageBox.Ok)

原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/8099.html

(0)
上一篇 2021年7月18日
下一篇 2021年7月18日

相关推荐

发表回复

登录后才能评论