吾八哥博客

您现在的位置是:首页 > 码农手记 > Python > 正文

Python

使用Python实现一键批量更新SVN/Git模块的脚本

吾八哥2017-10-12Python7464

现在我们开发的过程中,大都是模块化的工作方式,咱们的工程源码结构就是N个模块,N个SVN/Git地址,如果需要更新就得手动一个个的操作,弄起来实在太麻烦了,之前我都是写批处理来实现批量更新的,现在来使用Python来实现一把,这里仅仅实现一下svn的批量更新模块的方法了,这里写的是在Windows环境下的使用哦,具体代码如下:

# Autor: 5bug
# WebSite: http://www.5bug.wang
# 吾八哥网技术交流QQ群: 643829693
import os
import sys
#列出当前目录下所有一级文件夹
def dirpathlist(lpath, outlist):
    filelist = os.listdir(lpath)
    for f in filelist:
        filename = os.path.join(lpath, f)
        if os.path.isdir(filename):
            outlist.append(filename)
    return outlist
#执行SVN更新
def svnupdate(path):
    cmd = 'TortoiseProc.exe /command:update /path:"{}" /closeonend:0'.format(path)
    os.system(cmd)
if __name__ == '__main__':
    outlist = dirpathlist(sys.path[0], [])
    for f in outlist:
        print('更新 {}'.format(f))
        svnupdate(f)

如果是git,把相应的命令行换成git的命令即可。