更新目录下SVN项目的python脚本

#!/usr/bin/python
#coding=gb18030
# ==============================================
# autoupdate - automate update cvs and svn repositories
# ==============================================
# by [email protected]
# 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('./')




你可能感兴趣的:(更新目录下SVN项目的python脚本)