#!/usr/bin/python
# coding=utf-8
import shutil,os
isCover = True
newName = ""
# needCheckDir = "G:\\G116Project\\gui" #需要检查的路径
needCheckDir = "C:\\file1" #需要检查的路径
createfile = "C:\\file2" #需要拷贝到的目录
#路径初始化
def pathInit(path):
if path == "":
path = ".\\img"
else:
findS = "\\" in path
if not findS:
path = ".\\" + path
return path
#输入文件路径判断是否存在,如果不存在就创建
def findPathAndCreate(pathName):
global createfile
path = os.path.abspath(createfile)
splitStr = pathName.split(":", 1)
splitStr = os.path.dirname(splitStr[1])
splitStr = splitStr.split("\\", -1)
for x in splitStr:
if x != "":
path = path + "\\" + x
if not os.path.exists(path):
os.mkdir(path)
def execCmd(cmd):
r = os.popen(cmd)
text = r.read()
r.close()
return text
def findStrPath(path):
strP = ""
isPath = False
attrBefore = None
for attr in path:
if attrBefore and attr == ":":
isPath = True
strP = attrBefore + attr
elif isPath :
if attr != " ":
strP = strP + attr
else:
isPath = False
attrBefore = attr
return strP
#复制图片
def copyImg(_createfile):
global isCover
global needCheckDir
fileNum = 0
print("start copying files ... ...")
copyList = []
changeFileStr = getCmdInfo(needCheckDir)
changeFileInfo = changeFileStr.split("\n")
g = os.walk(needCheckDir, topdown=True)
for path,dir_list,file_list in g:
for file_name in file_list:
if path == _createfile:
continue
isChangeFile = False
pathName = os.path.join(path, file_name)
for changeName in changeFileInfo:
changeName = findStrPath(changeName)
if changeName == pathName:
isChangeFile = True
findPathAndCreate(pathName)
break
if isChangeFile:
pathName2 = _createfile+pathName.split(":")[1]
if pathName != pathName2:
fileNum = fileNum + 1
shutil.copy(pathName, pathName2)
copyList.append("copy:" + pathName + " To " + pathName2)
else:
print("unchanged file:" + pathName)
print("\ncopy file info:")
for x in copyList:
print(x)
endStr = "File successfully copied: "
print(("\n"+endStr+_createfile+" , Total number of copied files: %d"+"\n")%(fileNum))
def getCmdInfo(path):
cmd = "svn status " + path
return execCmd(cmd)
if __name__ == '__main__':
createfile = pathInit(createfile)
copyImg(createfile)
导出SVN中修改过和新增的未提交的文件
最新推荐文章于 2023-05-22 22:45:00 发布