1. 首页
  2. 编程语言
  3. Python
  4. 批量更新目录下所有CVS和SVN项目的Python脚本

批量更新目录下所有CVS和SVN项目的Python脚本

上传者: 2021-04-27 18:17:53上传 PY文件 1.86KB 热度 10次
#!/usr/bin/python #coding=gb18030 # ============================================== # autoupdate - automate update cvs and svn repositories # ============================================== # by liude67596@126.com # 23:29 2008-9-21 from os.path import basename, isdir from os import chdir, getcwd, listdir, system def traverse(path, depth=0): status = 255 if (depth > 5): print "depth = ", depth, " > 5" return 254 prefix = depth * '| ' + '|_' if (isdir(path)): print prefix, basename(path) logging.info(prefix + basename(path)) if (isdir(path + "/cvs")): status = cvsupdate(path) elif (isdir(path + "/.svn")): status = svnupdate(path) else: for item in listdir(path): traverse(path + '/' + item, depth + 1) print depth * '.', status return status def cvsupdate(path): _curpath = getcwd() chdir(path) status = system("cvs update") chdir(_curpath) return status def svnupdate(path): _curpath = getcwd() chdir(path) #system("TortoiseProc.exe /command:update /path:\"" + path + "\" /notempfile /closeonend:1") status = system("svn update") chdir(_curpath) return status # 执行shell命令的方式1 # os.system(my_command) // it return 0 or 1 .. 1 on failure # 执行shell命令的方式2 # (stdout, stderr) = popen2.popen3(my_command) # stdout.read() // console output # stderr.read() // error output if __name__ == '__main__': #Well, to get the path + script file do something like: import os, sys print os.path.join(sys.path[0], sys.argv[0]) import logging logging.basicConfig(level=logging.DEBUG, format='%(asctime)s %(levelname)-8s %(message)s', filename='autoupdate.log', filemode='w') logging.debug('A debug message') logging.info('Some information') logging.warning('A shot across the bows') traverse('./')
用户评论