使用python 的svn,一

本文介绍了如何在服务器环境中利用Python进行SVN操作,包括创建 SVN 文件、更新文件、移动文件及提交更改。通过Python脚本自动化这些任务,提升工作效率。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

在服务器中要做几个操作,使用命令操作svn,svn文件创建,svn文件更新,文件移动和提交

# -*- coding:utf-8 -*-
import pysvn
import locale
import datetime
import os
import sys
 
def setlocale():
    language_code, encoding = locale.getdefaultlocale()
    if language_code is None:
        language_code = 'en_GB'
    if encoding is None:
        encoding = 'UTF-8'
    if encoding.lower == 'utf':
        encoding = 'UTF-8'
    locale.setlocale(locale.LC_ALL, '%s.%s' % (language_code, encoding))
 
 
def get_login(realm, username, may_save):
    return True, 'test', 'test', True
 
#获取svn地址,url指svn地址,path,指项目拉取到哪个地方
def svncheckout(url,path):
    client = pysvn.Client()
   # client.callback_get_login = get_login
    ret = client.checkout(url, path)
    print ret
 
#更新svn的地址
def svnupdate():
    client = pysvn.Client()
    ret = client.update(path)
    return ret
 
 
def svncheckin(url):
    client = pysvn.Client()
    #url=svnurl+"/"+projectname
   # os.makedirs(url)
    client.add(url)
    client.checkin(url,u'项目文件的创建')
 
 
#写入日志到本地,主要用于更新信息使用的
def svninfo(path):
    client = pysvn.Client()
    entry = client.info(path)
    Version = "Version: %s" % entry.commit_revision.number
    Author = "Author: %s" % entry.commit_author
    Update = "Update Date: %s" % str(datetime.datetime.fromtimestamp(entry.commit_time))[:-7]
    url=path + '\log.txt'
    print url
    f = file(url, 'a')
    f.write(Version + '\n' + Author + '\n' + Update + '\n' + '-' * 32 + '\n')
    f.close()
 
 
def copyFiles(sourceDir, targetDir):  #文件的复制
    if sourceDir.find(".svn") > 0:
        return
    for file in os.listdir(sourceDir):
        sourceFile = os.path.join(sourceDir, file)
        targetFile = os.path.join(targetDir, file)
        if os.path.isfile(sourceFile):
            if not os.path.exists(targetDir):
                os.makedirs(targetDir)
            if not os.path.exists(targetFile) or (
                os.path.exists(targetFile) and (os.path.getsize(targetFile) != os.path.getsize(sourceFile))):
                open(targetFile, "wb").write(open(sourceFile, "rb").read())
        if os.path.isdir(sourceFile):
            First_Directory = False
            copyFiles(sourceFile, targetFile)
 
def run(svnurl,path,projectname):
    #url为svn的仓库地址,path为本地路径,project为项目路径
   # svncheckout(svnurl, path)
    sourceDir=path+"/template"
    print sourceDir
    targetDir=path + "/" + projectname
    print targetDir
    copyFiles(sourceDir,targetDir)  #资源文件
    #svncheckin(targetDir)
 
 
 
if __name__ == "__main__":
    svnurl = "http://svn.egomsl.com/svn/repos/autotest.globalegrow.com/projectScript/uitest"
    #run(svnurl,"./script/ui",sys.argv[0]) #从控制台接收一个名称,进行文件夹的创建
    path='./script/ui';
    run(svnurl, path, sys.argv[0])
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值