<pre name="code" class="python">#清除文件夹下所有文件
def cleanAllFiles(rootdir):
if not os.path.isdir(rootdir):
return;
filelist=os.listdir(rootdir)
for f in filelist:
filepath = os.path.join( rootdir, f )
if os.path.isfile(filepath):
os.remove(filepath)
print(filepath+" removed!")
elif os.path.isdir(filepath):
shutil.rmtree(filepath,True)
print("dir "+filepath+" removed!")
第一步首先要清空导出到的文件夹
#更新SVN文件信息
def updateSvnInfo(svnUrl,localSvnInfoPath):
command ='svn info ' + svnUrl +' -R --xml > ' + localSvnInfoPath;
print("localSvnInfoPath:" + localSvnInfoPath);
print("svnUrl:" + svnUrl);
print("svn info update.....Please wait for a while")
os.system(command)
第二步需要更新svn信息到本地 以用作下一步比较(先确保SVN安装了命令行环境svn help *安装时候要自动点选)
#导出指定版本之上新增资源
#指定版本,输出文件夹路径,SVN版本数据
def importVersion(lastVersion,outPutPath,localSvnInfoPath):
dom = xml.dom.minidom.parse(localSvnInfoPath);
root = dom.documentElement
itemlist = root.getElementsByTagName('entry')
for item in itemlist:
filetype = item.getAttribute("kind");
path = item.getAttribute("path");
commitInfo = item.getElementsByTagName("commit");
vsn = int(commitInfo[0].getAttribute("revision"));
if(vsn > lastVersion):
if(filetype == "file"):
itemInfo = item.getElementsByTagName("url")[0];
itemUrl = itemInfo.childNodes[0].nodeValue;
pos = path.rfind("\\")
dirUrl = path[:pos]
print("dirUrl:" + dirUrl);
if not os.path.isdir(outPutPath +"\\" + dirUrl):
os.makedirs(outPutPath + "\\" + dirUrl)
command = "svn export " + itemUrl + " " + outPutPath + "\\" + dirUrl;
os.system(command)
第三步就可以导出指定版本以上的资源了
如果出现中文路径出错可以在 Python27\Lib\site-packages 下放置sitecustomize.py
import sys
sys.setdefaultencoding('utf-8')
或者在代码中对中文路径处理
type = sys.getfilesystemencoding()
svnGamePath = ("http://192.168.7.126:8080//svn//游戏//联运//客户端//Yxzg").decode('utf-8').encode(type)