Friday, February 9, 2007

pysvn - subversion python binding

Depois de muito penar para conseguir fazer um checkout em um servidor subversion com autenticação usando pysvn, hoje finalmente consegui. É um bocado difícil de entender como funciona esse negócio, deveria ser um pouco mais intuitivo. Pra facilitar a vida de quem venha utilizar o pysvn e não queira perder muito tempo pra entender tudo, aqui vai um codigo que fiz. Melhorias são bem vindas.

import os
import sys
import pysvn


class DownloadSubversion(object):

def __init__(self, source, dest, username, password):
self.source = source
self.dest = dest
self.username = username
self.password = password

def callback_ssl_server_trust_prompt(self, trust_data):
'''
trust_data: essa e' uma variavel, um dicionario, passado pelo pysvn
contendo informacoes sobre o certificado ssl do servidor.
Por exemplo: data de expiracao do certificado, empresa
certificadora, nome do responsavel, fingerprint e etc.

'''


#for key,value in trust_data.items():
# print '%s: %s' % (key, value)
#print
answer = 't'
#while answer.lower() not in ['p','t','r']:
# sys.stdout.write( '(P)ermanent accept, (T)emporary accept or (R)eject: ' )
# answer = sys.stdin.readline().strip()
if answer.lower() == 'p':
return True, trust_data['failures'], True
if answer.lower() == 't':
return True, trust_data['failures'], False
return False, 0, False


def callback_getLogin(self, realm, username, password, may_save):
'''
realm: essa variavel eh utilizado pelo pysvn pra informar o endereco do
servidor e o nome do servico, deixe ela ai'. Por exemplo:
"Subversion Repository" at http://111.222.333.444

username: usuario do subversion

password: senha do subversion

may_save: salvar ou nao o usuario e senha

'''


if len(username) == 0:
return False, '', '', False

return True, username, password, may_save


def downloadRepos(self):

client = pysvn.Client()
client.exception_style = 1
client.set_default_username(self.username)
client.set_default_password(self.password)
client.callback_get_login = self.callback_getLogin
client.callback_ssl_server_trust_prompt = self.callback_ssl_server_trust_prompt

if os.access(self.dest + '/.svn', os.F_OK):
client.update(self.dest)
else:
client.checkout(self.source, self.dest)


if __name__ == '__main__':


subversion = DownloadSubversion('https://www.com.br/svnroot/', '.', 'usuario', 'senha')
subversion.downloadRepos()

4 comments:

My Family said...

def crawl_filesystem_dir (root, directory, pool):
"""Recursively crawl DIRECTORY under ROOT in the filesystem, and return
a list of all the paths at or below DIRECTORY. Use POOL for all
allocations."""

# Get the directory entries for DIRECTORY.
entries = fs.dir_entries(root, directory, pool)
bola tangkas online
# Initialize our returned list with the directory path itself.
paths = [directory]

# Loop over the entries
names = entries.keys()
for name in names:
# Calculate the entry's full path.ผลบอล
full_path = os.path.join(basepath, name)

# If the entry is a directory, recurse. The recursion will return
# a list with the entry and all its children, which we will add to
# our running list of paths.
if fs.is_dir(fsroot, full_path, pool):
subpaths = crawl_filesystem_dir(root, full_path, pool)
paths.extend(subpaths)

Unknown said...

The moment magnitude scale (abbreviated as MMS; denoted as MW) is used by seismologists to measure the size of earthquakes in terms of the energy released. The magnitude is based on the seismic moment of the earthquake, which is equal to the rigidity of the Earth multiplied by the average amount of slip on the fault and the size of the area that slipped


Online Bingocasino spel online

Unknown said...

In 1968, under the management of Matt Busby, Manchester United was the first English football club to win the European Cup, ten years after the Munich air disaster that claimed the lives of eight players


Sightline Payments Kirk Sanfordvilla

Unknown said...

The Chinese name for dragon is pronounced "lóng" in Mandarin Chinese or "lùhng" in the Cantonese. Sometime after the 9th century AD, Japan adopted the Chinese dragon through the spread of Buddhism


ผลบอลSecret Service

 

Rodrigo Belem's journal. Powered By Blogger © 2009 Bombeli | Theme Design: ooruc