zoukankan      html  css  js  c++  java
  • 使用python 操作liunx的svn,方案一

    在服务器中要做几个操作,使用命令操作svn,svn文件的创建,svn文件更新,并把指定demo路径,移动到创建的文件夹中,进行提交,

    # -*- 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 + '
    ' + Author + '
    ' + Update + '
    ' + '-' * 32 + '
    ')
        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])
    

      

  • 相关阅读:
    uva 147 Dollars
    hdu 2069 Coin Change(完全背包)
    hdu 1708 Fibonacci String
    hdu 1568 Fibonacci
    hdu 1316 How Many Fibs?
    poj 1958 Strange Towers of Hanoi
    poj 3601Tower of Hanoi
    poj 3572 Hanoi Tower
    poj 1920 Towers of Hanoi
    筛选法——素数打表
  • 原文地址:https://www.cnblogs.com/chongyou/p/8336612.html
Copyright © 2011-2022 走看看