comparison svnwrap/svn_swig_wrapper.py @ 235:2969a20e0eef

Add support for user:pass@url repositories to be hg-like
author Daniel Tang <dytang@cs.purdue.edu>
date Mon, 06 Apr 2009 11:19:51 -0400
parents 33e885f5f86a
children e8b3ca865f93
comparison
equal deleted inserted replaced
234:33e885f5f86a 235:2969a20e0eef
3 import os 3 import os
4 import shutil 4 import shutil
5 import sys 5 import sys
6 import tempfile 6 import tempfile
7 import hashlib 7 import hashlib
8 import urlparse
8 9
9 from svn import client 10 from svn import client
10 from svn import core 11 from svn import core
11 from svn import delta 12 from svn import delta
12 from svn import ra 13 from svn import ra
89 client.get_simple_prompt_provider(user_pass_prompt, 2), 90 client.get_simple_prompt_provider(user_pass_prompt, 2),
90 ] 91 ]
91 92
92 return core.svn_auth_open(providers, pool) 93 return core.svn_auth_open(providers, pool)
93 94
95 def parse_url(url):
96 """Parse a URL and return a tuple (username, password, url)
97 """
98 scheme, netloc, path, params, query, fragment = urlparse.urlparse(url)
99 user, passwd = None, None
100 if '@' in netloc:
101 userpass, netloc = netloc.split('@')
102 if ':' in userpass:
103 user, passwd = userpass.split(':')
104 user, passwd = urlparse.unquote(user) or None, urlparse.unquote(passwd) or None
105 else:
106 user = urlparse.unquote(userpass) or None
107 url = urlparse.urlunparse((scheme, netloc, path, params, query, fragment))
108 return (user, passwd, url)
94 109
95 class Revision(object): 110 class Revision(object):
96 """Wrapper for a Subversion revision. 111 """Wrapper for a Subversion revision.
97 """ 112 """
98 def __init__(self, revnum, author, message, date, paths, strip_path=''): 113 def __init__(self, revnum, author, message, date, paths, strip_path=''):
117 132
118 This uses the SWIG Python bindings, and will only work on svn >= 1.4. 133 This uses the SWIG Python bindings, and will only work on svn >= 1.4.
119 It takes a required param, the URL. 134 It takes a required param, the URL.
120 """ 135 """
121 def __init__(self, url='', username='', password=''): 136 def __init__(self, url='', username='', password=''):
122 self.svn_url = url 137 parsed = parse_url(url)
123 self.username = username 138 # --username and --password override URL credentials
124 self.password = password 139 self.username = username or parsed[0]
140 self.password = password or parsed[1]
141 self.svn_url = parsed[2]
125 self.auth_baton_pool = core.Pool() 142 self.auth_baton_pool = core.Pool()
126 self.auth_baton = _create_auth_baton(self.auth_baton_pool) 143 self.auth_baton = _create_auth_baton(self.auth_baton_pool)
127 144
128 self.init_ra_and_client() 145 self.init_ra_and_client()
129 self.uuid = ra.get_uuid(self.ra, self.pool) 146 self.uuid = ra.get_uuid(self.ra, self.pool)