python调用svn
A. svn的commit功能,怎么用python实现
真不太清楚你什么意思,好吧照我理解的来,给你个ci的def
def co_file(src):
co_cmd="svn co "+src
os.system(co_cmd)
#function: ci file with log comments
def ci_file():
current_path=os.getcwd()
svn_path=current_path+"/scm"
os.chdir(svn_path)
ci_cmd="svn ci -F comments.txt --force-log"
os.system(ci_cmd)
os.system("rm -f scm/*")
os.chdir(current_path)
B. python3如何将远端svn上的文件下载到本地
这还不简单, 根本不需要python, A机器上面ssh到B机器上面去, 执行svn up
PS: python也有ssh库, 也可以手动写程序去连
C. python popen如何执行ps -ef|grep svn命令
这个没有限制或者问题吧,直接:
os.popen('ps -ef | grep python').read()
就可以了
D. Python 获取SVN 文件,具体程序如何
可以用os.system来调用svn命令操作
E. python如何获取svn路径是文件还是文件夹
GetFilesFromSVN.py
#----------------------------------------------
# Author : Jeff Yu
# Date : 2012-8-13
# Function : get files from SVN
#----------------------------------------------
#----------------------------------
# Step1: Get INFO
#----------------------------------
import sys,ConfigParser
try:
configFile = open("config.ini","r")
except IOError:
print "config.ini is not found"
raw_input("")
sys.exit()
config = ConfigParser.ConfigParser()
config.readfp(configFile)
configFile.close()
# get baseurl
try:
baseurl = config.get("INFO","baseurl")
# incase last "/" is missing in baseurl
baseurl = baseurl.rstrip("/")
baseurl = "%s/"%baseurl
except ConfigParser.NoOptionError:
print "baseurl is not found under section INFO in config.ini."
raw_input("")
sys.exit()
# get user
try:
user = config.get("INFO","user")
except ConfigParser.NoOptionError:
meg = "user is not found under section INFO in config.ini."
raw_input("")
sys.exit()
# get passwd
try:
passwd = config.get("INFO","passwd")
except ConfigParser.NoOptionError:
meg = "passwd is not found under section INFO in config.ini."
raw_input("")
sys.exit()
# get fileList
try:
fileList = config.get("INFO","fileList")
except ConfigParser.NoOptionError:
meg = "fileList is not found under section INFO in config.ini."
raw_input("")
sys.exit()
#----------------------------------
# Step2: Auth
#----------------------------------
import urllib2
realm = "Subversion Repositories"
auth = urllib2.HTTPBasicAuthHandler()
auth.add_password(realm, baseurl, user, passwd)
opener = urllib2.build_opener(auth, urllib2.CacheFTPHandler)
urllib2.install_opener(opener)
#----------------------------------
# Step3: Create Folder
#----------------------------------
import os
folderName = "svnFile"
if not os.path.exists(folderName):
os.mkdir(folderName)
#----------------------------------
# Step4: Get Files
#----------------------------------
fr = open(fileList,'r')
for i in fr:
i = i.strip("\n")
i = i.strip(" ")
# ignore the blank line
if i != "":
url = "%s%s"%(baseurl,i)
try:
data = urllib2.urlopen(url)
fw = open("%s/%s"%(folderName,i),'w')
fw.write(data.read())
fw.close()
print "Download: %s."%i
except urllib2.HTTPError, e:
# HTTPError is a subclass of URLError
# need to catch this exception first
mesg = str(e).split(" ")
errCode = mesg[2].rstrip(":")
if errCode == "401":
# HTTP Error 401: basic auth failed
print "Can not login in, please check the user and passwd in config.ini."
break
elif errCode == "404":
# HTTP Error 404: Not Found
print "Not Found: %s"%i
else:
print e
print "Failed to download %s"%i
except urllib2.URLError:
# 1.SVN server is down
# 2.URL is not correct
print "Please check SVN Server status and baseurl in config.ini."
break
fr.close()
raw_input("")
config.ini
[INFO]
baseurl = https://xxx/xxx/xxx/xxx/
user = 用户名
passwd = 密码
fileList= fileList.txt
fileList.txt
aaaaa.txt
bbbbb.txt
ccccc.txt
使用方法:
1.配置config.ini,配置好需要check out文件所在文件夹的URL(baseurl),用户名(user),密码(passwd)和存储文件列表的文件名称(fileList)
2.将要check out的文件列表放在文本文件里面(fileList.txt),每一个文件占一行.
3.双击GetFilesFromSVN.py运行,下载的文件将放在当前文件夹下用过名为svnFile的文件夹里面.
PS:获取realm
在这个脚本中,我hardcode了一段代码(064行) realm = "Subversion Repositories"
关于这个realm,可以使用下面脚本获取:
import urllib2
import sys
url = '这里写URL'
username = '这里写用户名'
password = '这里写密码'
req = urllib2.Request(url)
try:
handle = urllib2.urlopen(req)
except IOError, e:
pass
else:
print "This page isn't protected by authentication."
sys.exit(1)
getrealm = e.headers['www-authenticate']
print getrealm
F. 求助关于python使用svn的问题
你是想使用python操作svn吧,你可以安装svn的第三方库。
https://pypi.python.org/pypi/svn/0.3.25
具体使用:
importsvn.local
importpprint
r=svn.local.LocalClient('/dev/repo')
r.export('/tmp/export')
pprint.pprint(r.info())
importsvn.remote
r=svn.remote.RemoteClient('https://repo.local/svn')
r.checkout('/tmp/working')
如果解决了您的问题请采纳!
如果未解决请继续追问!
G. python如何调用checkstyle插件
你的想法存在一个误区:
pre-commit hook是在svn服务器上触发的,而svn服务器中不是直接存储源代码文本,而是以svn自己的格式来存储(版本差异增量存储等)。所以checkstyle是检查不了的。实际上,你想做的事,应该是由自动构建工具来完成(svn是版本管理,不是构建工具)。
向你推荐一款开源的自动构建工具:jenkins,这个工具很方便。
另外,你所说的checkstyle检查,其实也不需要用python,直接用shell就可以做到的。
比如:在自动构建服务器上,做一个类似这样的脚本:
#!/bin/sh
#-*-coding:utf-8-*-
#-*-file:checkstyle.sh-*-
java-jar${CHECKSTYLE_HOME}/checkstyle-6.1-all.jar
-c${SCRIPT_HOME}/checkstyle.xml
-r${PROJECT_HOME}/myproject/moles
-r${PROJECT_HOME}/myproject/resources
-fxml
-o${REPORT_DIR}/checkstyle-report.xml||echo"checkstylefind$?bugs."
其中,checkstyle-6.1-all.jar是checkstyle 6.1的jar包;checkstyle.xml是为项目配置好的checkstyle规则;myproject是要检查的工程;checkstyle-report.xml是检查结果报告(xml格式)。
如果服务器是windows环境,只需要把以上内容改成.bat或.cmd批处理脚本即可。
H. 怎么用python更新SVN、获取SVN版本号、获取SVN两个版本号之间的修改日志。
1) 执行shell命令,最好用popen打开,不过中间会有一些交互,除非事先的鉴权信息保存在系统中了。参考buildbot中对这些版本管理软件的用法。
2)好像有个pySVN的库可以用。
I. python svn脚本如何进行文件删除
其中实现功能的核心代码写得太过冗长,其实很简单的4行代码就能达到目的,如下:
1 import os
2 for (p,d,f) in os.walk("要删除的目录路径"):
3 if p.find('.svn')>0:
4 os.popen('rd /s /q %s'%p)
J. python 判断svn分支是否存在
SVN是一个C/S架构的软件,使用时分服务器端和客户端,“本地”一般指的就是客户端
一般安装过程是先安装服务器端,把服务配通,然后安装客户端。
详细的安装过程可参见我的网络文库中的SVN安装指南。