comparison easyhg.py @ 453:f2ab2cdd000b authfile_refactor

Associate username with pathless URL, as well as password
author Chris Cannam
date Wed, 29 Jun 2011 15:37:11 +0100
parents d0b7dbc3ba46
children 856da063d76e
comparison
equal deleted inserted replaced
452:d0b7dbc3ba46 453:f2ab2cdd000b
2 # 2 #
3 # EasyMercurial 3 # EasyMercurial
4 # 4 #
5 # Based on hgExplorer by Jari Korhonen 5 # Based on hgExplorer by Jari Korhonen
6 # Copyright (c) 2010 Jari Korhonen 6 # Copyright (c) 2010 Jari Korhonen
7 # Copyright (c) 2010 Chris Cannam 7 # Copyright (c) 2010-2011 Chris Cannam
8 # Copyright (c) 2010 Queen Mary, University of London 8 # Copyright (c) 2010-2011 Queen Mary, University of London
9 # 9 #
10 # This program is free software; you can redistribute it and/or 10 # This program is free software; you can redistribute it and/or
11 # modify it under the terms of the GNU General Public License as 11 # modify it under the terms of the GNU General Public License as
12 # published by the Free Software Foundation; either version 2 of the 12 # published by the Free Software Foundation; either version 2 of the
13 # License, or (at your option) any later version. See the file 13 # License, or (at your option) any later version. See the file
127 def pathless_url(self): 127 def pathless_url(self):
128 parsed = urlparse.urlparse(self.remote_url) 128 parsed = urlparse.urlparse(self.remote_url)
129 return "%s://%s" % (parsed.scheme, parsed.netloc) 129 return "%s://%s" % (parsed.scheme, parsed.netloc)
130 130
131 def load_config(self): 131 def load_config(self):
132 self.auth_config = ConfigParser.RawConfigParser() 132 if not self.auth_config:
133 self.auth_config = ConfigParser.RawConfigParser()
133 fp = None 134 fp = None
134 try: 135 try:
135 fp = open(self.auth_file) 136 fp = open(self.auth_file)
136 except: 137 except:
137 self.ui.write("unable to read authfile %s, ignoring\n" % self.auth_file) 138 self.ui.write("unable to read authfile %s, ignoring\n" % self.auth_file)
186 h.update(s) 187 h.update(s)
187 hx = h.hexdigest() 188 hx = h.hexdigest()
188 return hx 189 return hx
189 190
190 def remote_user_key(self): 191 def remote_user_key(self):
191 return self.remote_key(self.argless_url(), '') 192 return self.remote_key(self.pathless_url(), '')
192 193
193 def remote_passwd_key(self): 194 def remote_passwd_key(self):
194 return self.remote_key(self.pathless_url(), self.user) 195 return self.remote_key(self.pathless_url(), self.user)
195 196
196 def load_auth_data(self): 197 def load_auth_data(self):
211 if d: 212 if d:
212 self.passwd = self.decrypt(d) 213 self.passwd = self.decrypt(d)
213 214
214 def save_auth_data(self): 215 def save_auth_data(self):
215 216
217 self.load_config()
216 if not self.auth_config: return 218 if not self.auth_config: return
217 219
218 self.set_to_config('preferences', 'remember', self.remember) 220 self.set_to_config('preferences', 'remember', self.remember)
219 221
220 self.ui.write('aiming to store details for user %s\n' % self.user) 222 self.ui.write('aiming to store details for user %s\n' % self.user)
221 223
222 if self.remember and self.user: 224 if self.remember and self.user: