Python学习—— 导出SVN中指定版本后增加的资源

<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)




  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值