如何在没有第三方模块的情况下使用python脚本从SVN检出代码时提供用户名和密码

时间:2016-11-23 11:52:59

标签: python python-2.7 python-3.x svn svn-checkout

我能够使用" pysvn"写一个脚本来检查SVN问题的代码。模块,但只是想知道有没有办法,我可以做没有pysvn?因为pysvn是第三方库,我必须在linux和windows上单独安装,这些都是我不想要的。请帮助我获得替代方法,我不必安装任何第三方模块代码 -

import pysvn,os,shutil


def getLogin(realm, username, may_save):
    svn_user = '<my-username>'
    svn_pass = '<my-password>'
    return True, svn_user, svn_pass, False

def ssl_server_trust_prompt( trust_dict ):
    return (True    # server is trusted
           ,trust_dict["failures"]
           ,True)   # save the answer so that the callback is not called again

def checkOut(svn_url,dest_dir):
    if os.path.isdir(dest_dir):
        shutil.rmtree(dest_dir)
        os.mkdir(dest_dir)
        client = pysvn.Client()
    client.callback_ssl_server_trust_prompt = ssl_server_trust_prompt
        client.callback_get_login = getLogin
        client.checkout(svn_url,dest_dir)
    else:
        os.mkdir(dest_dir)
        client = pysvn.Client()
    client.callback_ssl_server_trust_prompt = ssl_server_trust_prompt
        client.callback_get_login = getLogin
        client.checkout(svn_url,dest_dir)


print "Checking out the code hang on...\n"
checkOut('<svn-repo>','ABC')
print "checked out the code \n"

print "Checking out the code hang on...\n"
checkOut('<svn-repo>','XYZ')
print "checked out the code\n"

print "Checking out the code hang on...\n"
checkOut('<svn-repo>','MNP')
print "checked out the code \n”

3 个答案:

答案 0 :(得分:1)

您可以将用户名和密码作为参数传递:

html

答案 1 :(得分:0)

我可以使用“pysvn”模块解决这个问题,但只是想知道我有没有办法在没有pysvn的情况下也可以做到?因为pysvn是第三方库,我必须分别在linux和windows上安装我不想要的。请帮助我获得替代方式,我不必安装任何第三方模块代码 -

import pysvn,os,shutil


def getLogin(realm, username, may_save):
    svn_user = '<my-username>'
    svn_pass = '<my-password>'
    return True, svn_user, svn_pass, False

def ssl_server_trust_prompt( trust_dict ):
    return (True    # server is trusted
           ,trust_dict["failures"]
           ,True)   # save the answer so that the callback is not called again

def checkOut(svn_url,dest_dir):
    if os.path.isdir(dest_dir):
        shutil.rmtree(dest_dir)
        os.mkdir(dest_dir)
        client = pysvn.Client()
    client.callback_ssl_server_trust_prompt = ssl_server_trust_prompt
        client.callback_get_login = getLogin
        client.checkout(svn_url,dest_dir)
    else:
        os.mkdir(dest_dir)
        client = pysvn.Client()
    client.callback_ssl_server_trust_prompt = ssl_server_trust_prompt
        client.callback_get_login = getLogin
        client.checkout(svn_url,dest_dir)


print "Checking out the code hang on...\n"
checkOut('<svn-repo>','ABC')
print "checked out the code \n"

print "Checking out the code hang on...\n"
checkOut('<svn-repo>','XYZ')
print "checked out the code\n"

print "Checking out the code hang on...\n"
checkOut('<svn-repo>','MNP')
print "checked out the code \n"

答案 2 :(得分:0)

您可以使ur脚本成为可执行文件,该脚本会将pysvn包含到二进制文件中,因此无需导入或pip安装任何库,您的代码也将在不使用python的计算机上运行