AutoGenSystem
#coding=utf-8 #
# AutoGenSystem
# 声明:
# 该软件主要是为了解决Android系统更新时,由于版本很多,管理起来复杂,容易出错,于是采用软件
# 自动对系统软件进行组合,目前该软件还没有对生成的文件夹加入命名规范。
#
# 2016-1-2 深圳 南山平山村 曾剑锋
# 参考文档:
# 1. PySide : How to get the clicked QPushButton object in the QPushButton clicked slot?
# http://stackoverflow.com/questions/20320298/pyside-how-to-get-the-clicked-qpushbutton-object-in-the-qpushbutton-clicked-sl
# 2. python 字符串split的用法分享
# http://www.jb51.net/article/34998.htm
# 3. Python中使用定时器Sleep定时秒及毫秒。
# http://jingyan.baidu.com/article/4b07be3c65263a48b380f3b4.html
# 4. 去空格及特殊符号
# http://www.cnblogs.com/huangcong/archive/2011/08/29/2158268.html
# 5. Python中函数的参数定义和可变参数
# http://www.cnblogs.com/tqsummer/archive/2011/01/25/1944416.html
# 6. python 多线程就这么简单
# http://www.cnblogs.com/fnng/p/3670789.html
# 7. python threads can only be started once
# http://zhidao.baidu.com/link?url=8x7GpDdNmcL3TQZ0iDibdkx5Y2MdgcxnlATPkvMX4EwXsR2ZxJ37lDapbeehaHNvGmQxjupjnx4ynsxfAuGipC1wbOUoTaHqmzyLcmcffza
#
# import sys
import os
import shutil
import time
import threading
from PyQt4.QtCore import *
from PyQt4.QtGui import * from ui_AutoGenSystem import Ui_GenSystemUI class AutoGenSystem(QDialog): def __init__(self): QDialog.__init__(self) self.ui = Ui_GenSystemUI()
self.ui.setupUi(self) self.setWindowTitle("AutoGenSystem")
self.setFixedHeight(self.height())
self.setFixedWidth(self.width())
self.setWindowFlags(self.windowFlags() & ~Qt.WindowContextHelpButtonHint); # 连接信号与槽
self.ui.chooseUbootPath.clicked.connect(lambda :self.dealWithPushButton(self.ui.chooseUbootPath))
self.ui.chooseRecoveryPath.clicked.connect(lambda :self.dealWithPushButton(self.ui.chooseRecoveryPath))
self.ui.chooseBootingPath.clicked.connect(lambda :self.dealWithPushButton(self.ui.chooseBootingPath))
self.ui.chooseFileSystemPath.clicked.connect(lambda :self.dealWithPushButton(self.ui.chooseFileSystemPath))
self.ui.clean.clicked.connect(self.cleanOnClicked)
self.ui.current.clicked.connect(self.currentOnClicked)
self.ui.autoAll.clicked.connect(self.autoAllOnClicked) #初始化一些全局变量,compound是指合成,也就合成的目录
self.ubootImagePath = "image/uboot/"
self.fileSystemImagePath = "image/file_system/"
self.recoveryImagePath = "image/recovery/"
self.bootingImagePath = "image/booting/"
self.readmeFilePath = "image/readme.txt"
self.compoundPath = "compound/"
self.ubootName = "uboot.img"
self.bootingNmae = "boot.img"
self.fileSystemName = "system.img"
self.recoveryName = "recovery.img" # 检查这些文件路径是否存在
self.checkImagePathExist(self.ubootImagePath, self.fileSystemImagePath, self.recoveryImagePath, self.bootingImagePath, self.readmeFilePath) # 读取readme文件
if os.path.exists(self.readmeFilePath) :
readme = open(self.readmeFilePath)
self.ui.readme.setPlainText(QString.fromUtf8(readme.read()))
readme.close() def currentOnClicked(self): # 检查文本框是否为空
if ( (len(self.ui.ubootPath.text()) == 0)
or (len(self.ui.recoveryPath.text()) == 0)
or (len(self.ui.bootingPath.text()) == 0)
or (len(self.ui.fileSystemPath.text()) == 0) ):
QMessageBox.about(self, "mesg", "Please choose all The image files on the left side.")
return # 删除之前合成的目录,并重新创建合成目录
self.remakeCompoundDir() # 文件拷贝,并显示进度条、提示信息,5个文件,每次拷贝完一个文件,进度条往前跑20个点,跑完最后一个点就是100了
# 这里的self.compound字符串最后添加了"/",所以生成distPath的时候可以直接字符串连接。
i = 0;
i += 1
self.copyImageFile(self.ui.ubootPath.text(), self.compoundPath + self.ubootName, 20 * i, "Copying uboot.img")
i += 1
self.copyImageFile(self.ui.recoveryPath.text(), self.compoundPath + self.recoveryName, 20 * i, "Copying recovery.img")
i += 1
self.copyImageFile(self.ui.bootingPath.text(), self.compoundPath + self.bootingNmae, 20 * i, "Copying boot.img")
i += 1
self.copyImageFile(self.ui.fileSystemPath.text(), self.compoundPath + self.fileSystemName, 20 * i, "Copying system.img")
i += 1
self.saveReadMeFile(self.compoundPath + "readme.txt", 20 * i, "Copying readme.txt.") self.ui.info.setText("Current copying is over.") def autoAllOnClicked(self): # 获取文件列表
ubootFiles = os.listdir(self.ubootImagePath)
recoveryFiles = os.listdir(self.recoveryImagePath)
bootingFiles = os.listdir(self.bootingImagePath)
fileSystemFiles = ""
if self.ui.systemType.currentIndex() == 0 :
fileSystemFiles = os.listdir(self.fileSystemImagePath + "RES")
else:
fileSystemFiles = os.listdir(self.fileSystemImagePath + "PTC") # 删除之前合成的目录,并重新创建合成目录
self.remakeCompoundDir() # 拷贝文件,并计算进度条每次跳跃的阶数值,总循环次数allFilesCount,每套系统里面需要生成5个文件
# 设置进度条进度,Information tips信息
allFilesCount = len(ubootFiles) * len(recoveryFiles) * len(bootingFiles) * len(fileSystemFiles)
processBarStep = 100.0 / allFilesCount / 5 # 每个文件夹5个文件 i = 0
for ubootFile in ubootFiles:
for recoveryFile in recoveryFiles:
for bootingFile in bootingFiles:
for fileSystemFile in fileSystemFiles: newPath = self.compoundPath + ubootFile+"_"+recoveryFile+"_"+bootingFile+"_"+fileSystemFile + "/"
os.mkdir(newPath) i += 1
self.copyImageFile(self.ubootImagePath + ubootFile, newPath + self.ubootName, processBarStep * i, "Copying uboot.img")
i += 1
self.copyImageFile(self.recoveryImagePath + recoveryFile, newPath + self.recoveryName, processBarStep * i, "Copying recovery.img")
i += 1
self.copyImageFile(self.bootingImagePath + bootingFile, newPath + self.bootingNmae, processBarStep * i, "Copying boot.img")
i += 1
if self.ui.systemType.currentIndex() == 0 :
self.copyImageFile(self.fileSystemImagePath + "RES/" + fileSystemFile, newPath + self.fileSystemName, processBarStep * i, "Copying system.img")
else:
self.copyImageFile(self.fileSystemImagePath + "PTC/" + fileSystemFile, newPath + self.fileSystemName, processBarStep * i, "Copying system.img")
i += 1
self.saveReadMeFile("%s/readme.txt" % newPath, processBarStep * i, "Saving readme.txt.") self.ui.info.setText("AutoAll copying is over.")
self.ui.progressBar.setValue(100) def cleanOnClicked(self): self.ui.systemType.setCurrentIndex(0)
self.ui.ubootPath.setText("")
self.ui.recoveryPath.setText("")
self.ui.bootingPath.setText("")
self.ui.fileSystemPath.setText("")
self.ui.readme.setPlainText("")
self.ui.progressBar.setValue(0)
self.ui.info.setText("Information Tips.") def dealWithPushButton(self, button): filePath = ""
if button.objectName() == "chooseUbootPath" :
filePath = self.ubootImagePath
elif button.objectName() == "chooseRecoveryPath" :
filePath = self.recoveryImagePath
elif button.objectName() == "chooseBootingPath" :
filePath = self.bootingImagePath
elif button.objectName() == "chooseFileSystemPath" :
filePath = self.fileSystemImagePath
if self.ui.systemType.currentIndex() == 0 :
filePath += "/RES"
else :
filePath += "/PTC" # 检查文件路径是否存在
self.checkImagePathExist(filePath) # 获取文件路径,并将文件路径保存在UI界面的控件里去
choosePathString = QFileDialog.getOpenFileName(self, "Select file", filePath, "*")
if len(choosePathString) == 0 :
return
self.setUIControlsPath(button, choosePathString) def checkImagePathExist(self, *paths): # 由于这里传入的参数可以是多个,可能有些路径有效,有些无效,在这里进行检查,将无效的路径提取出来,并给出提示
unexistPath = ""
for path in paths :
if not os.path.exists(path) :
unexistPath += "\n\t"
unexistPath += path unexistPath = unexistPath.strip() # 剔除字符串行头行尾的不显示字符,用于下面的比较和分割
if len(unexistPath) != 0 :
if len(unexistPath.split("\n\t")) == 1 :
QMessageBox.about(self, "mesg", "Please create this path in current software path:\n\t" + unexistPath + ".")
else :
QMessageBox.about(self, "mesg", "Please create those path in current software path:\n\t" + unexistPath + ".")
exit() def copyImageFile(self, srcPath, distPath, progressBarValue, informationTips): self.ui.info.setText(informationTips)
QFile.copy(srcPath, distPath) # 拷贝文件
self.ui.progressBar.setValue(progressBarValue) def copyASystemFile(self, ubootSrcPath, ubootDistPath, bootingSrcPath, bootingDistPath,
recoverySrcPath, recoveryDistPath, fileSystemSrcPath, fileSystemDistPath, readmePath, processBarStep, index):
# 文件拷贝,并显示进度条、提示信息,5个文件,每次拷贝完一个文件
# 这里的self.compound字符串最后添加了"/",所以生成distPath的时候可以直接字符串连接。
index
self.copyImageFile(ubootSrcPath, ubootDistPath, processBarStep * index, "Copying uboot.img")
index += 1
self.copyImageFile(bootingSrcPath, bootingDistPath, processBarStep * index, "Copying recovery.img")
index += 1
self.copyImageFile(recoverySrcPath, recoveryDistPath, processBarStep * index, "Copying boot.img")
index += 1
self.copyImageFile(fileSystemSrcPath, fileSystemDistPath, processBarStep * index, "Copying system.img")
index += 1
self.saveReadMeFile(readmePath, processBarStep * index, "Copying readme.txt.") def saveReadMeFile(self, distPath, progressBarValue, informationTips): self.ui.info.setText(informationTips)
readme = open( distPath, "w" )
readme.write(self.ui.readme.toPlainText().toUtf8()) # 保存的时候用Utf8,读的时候也是Utf8
readme.flush()
readme.close()
self.ui.progressBar.setValue(progressBarValue) def remakeCompoundDir(self): # 删除文件夹,创建文件夹,这个过程时间太短貌似有问题,所以加了延时,但目前没有摸清楚这个延时情况该如何解决
if os.path.exists("compound") :
shutil.rmtree("compound")
time.sleep(1)
os.mkdir("compound") def disableAllControls(self): self.ui.systemType.setDisabled(True)
self.ui.ubootPath.setDisabled(True)
self.ui.recoveryPath.setDisabled(True)
self.ui.bootingPath.setDisabled(True)
self.ui.fileSystemPath.setDisabled(True)
self.ui.readme.setDisabled(True)
self.ui.clean.setDisabled(True)
self.ui.current.setDisabled(True)
self.ui.autoAll.setDisabled(True) def enableAllControls(self): self.ui.systemType.setDisabled(False)
self.ui.ubootPath.setDisabled(False)
self.ui.recoveryPath.setDisabled(False)
self.ui.bootingPath.setDisabled(False)
self.ui.fileSystemPath.setDisabled(False)
self.ui.readme.setDisabled(False)
self.ui.clean.setDisabled(False)
self.ui.current.setDisabled(False)
self.ui.autoAll.setDisabled(False) def setUIControlsPath(self, button, choosePathString): # 设置UI界面
if button.objectName() == "chooseUbootPath" :
self.ui.ubootPath.setText(choosePathString)
elif button.objectName() == "chooseRecoveryPath" :
self.ui.recoveryPath.setText(choosePathString)
elif button.objectName() == "chooseBootingPath" :
self.ui.bootingPath.setText(choosePathString)
elif button.objectName() == "chooseFileSystemPath" :
self.ui.fileSystemPath.setText(choosePathString)
AutoGenSystem的更多相关文章
- pycharm Working directory error
/***************************************************************************** * pycharm Working dir ...
- Windows pyqt4 bat自动转换UI文件-->.pyw文件
/***************************************************************************** * Windows pyqt4 bat自动 ...
随机推荐
- 让Word2007、word2003中的GIF图片动起来
在PPT中插入会动的GIF图片,播放是生动有趣:可是GIF图片插入Word2007文档后却变成了静态画面,表现效果大打折扣.让我们装一个小控件,让图片动起来! 第一步:下载AniGIF.ocx控件,解 ...
- YAPF:Google开源的Python代码格式化工具
点这里 现在的大多数 Python 代码格式化工具(比如:autopep8 和 pep8ify)是可以移除代码中的 lint 错误.这显然有些局限性.比如:遵循 PEP 8 指导的代码可能就不会被格式 ...
- Logstash最佳实践
http://udn.yyuap.com/doc/logstash-best-practice-cn/index.html
- POJ 1947 Rebuilding Roads(树形DP)
题目链接 题意 : 给你一棵树,问你至少断掉几条边能够得到有p个点的子树. 思路 : dp[i][j]代表的是以i为根的子树有j个节点.dp[u][i] = dp[u][j]+dp[son][i-j] ...
- 机器学习之神经网络模型-上(Neural Networks: Representation)
在这篇文章中,我们一起来讨论一种叫作"神经网络"(Neural Network)的机器学习算法,这也是我硕士阶段的研究方向.我们将首先讨论神经网络的表层结构,在之后再具体讨论神经网 ...
- 妙味课堂——HTML+CSS(第一课)
一句话,还记忆不如烂笔头,何况还这么笨,记下笔记,也是记录这一路学习的过程. 妙味课堂第一课并未一味地先讲HTML,而是穿插着CSS讲解,这一点不同于一些其他视频,这一点挺特别的!所以这一课涉及到HT ...
- YARN集群维护部分问题汇总
云梯开发人员在云梯Yarn集群的搭建和维护过程中做了许多工作,本文选择这期间部分较为典型的问题,通过对这些问题的分析和解决方案,为大家分享分布式系统问题调查的经验. 调查的问题 1. 2013年初引入 ...
- 编写基于outlook显示的html邮件需要注意的问题
outlook对于html的支持是有限制的,在编写这些html的时候注意遵循以下规则: Never use colspans or rowspans. Always set correct dimen ...
- Linux命令行通配符
如果我们想对一类文件批量操作,例如批量查看硬盘文件属性,那么正常命令是如下所示: [root@localhost Desktop]# ls /dev/sda1 [root@localhost Desk ...
- jboss5优化
1.调整JVM在bin.bat或bin/run.cfg文件里. -Xms设置堆的最小值:-Xmx设置堆的最大值:-XX:Newsize= 设置年轻代的最小值:-XX:MaxNewsize=设置年轻代的 ...