當前位置:首頁 » 編程語言 » python調用svn

python調用svn

發布時間: 2022-06-26 07:34:40

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安裝指南。

熱點內容
c語言中的temp 發布:2025-02-05 02:43:08 瀏覽:123
阿里雲伺服器共享電腦 發布:2025-02-05 02:42:18 瀏覽:417
伺服器有多少台電腦 發布:2025-02-05 02:40:41 瀏覽:447
安卓手機為什麼最新微信安裝不了 發布:2025-02-05 02:31:03 瀏覽:106
安卓手機什麼時候開售 發布:2025-02-05 02:14:15 瀏覽:660
編程車模型 發布:2025-02-05 02:09:55 瀏覽:681
雅馬哈天劍哪個配置好 發布:2025-02-05 02:00:35 瀏覽:170
我的世界國際服推薦118伺服器 發布:2025-02-05 01:50:48 瀏覽:46
普通電腦做伺服器怎麼操作 發布:2025-02-05 01:46:22 瀏覽:628
原神為什麼同伺服器加不起好友 發布:2025-02-05 01:41:03 瀏覽:337