Mercurial > hg > easyhg
comparison easyhg.py @ 444:66ec8b2ee946
Provide auth key and file information to easyhg extension
author | Chris Cannam |
---|---|
date | Tue, 28 Jun 2011 15:59:13 +0100 |
parents | b616c9c6cfd2 |
children | ff6252986354 |
comparison
equal
deleted
inserted
replaced
443:459b140032d4 | 444:66ec8b2ee946 |
---|---|
88 except: | 88 except: |
89 return | 89 return |
90 pcfg.readfp(fp) | 90 pcfg.readfp(fp) |
91 fp.close() | 91 fp.close() |
92 | 92 |
93 def save_config(pcfg, pfile): | 93 def save_config(ui, pcfg, pfile): |
94 ofp = None | 94 ofp = None |
95 try: | 95 try: |
96 ofp = open(pfile, 'w') | 96 ofp = open(pfile, 'w') |
97 except: | 97 except: |
98 self.ui.write("failed to open authfile %s for writing\n" % pfile) | 98 ui.write("failed to open authfile %s for writing\n" % pfile) |
99 raise | 99 raise |
100 try: | 100 try: |
101 #!!! Windows equivalent? | 101 #!!! Windows equivalent? |
102 os.fchmod(ofp.fileno(), stat.S_IRUSR | stat.S_IWUSR) | 102 os.fchmod(ofp.fileno(), stat.S_IRUSR | stat.S_IWUSR) |
103 except: | 103 except: |
104 ofp.close() | 104 ofp.close() |
105 self.ui.write("failed to set permissions on authfile %s\n" % pfile) | 105 ui.write("failed to set permissions on authfile %s\n" % pfile) |
106 raise | 106 raise |
107 pcfg.write(ofp) | 107 pcfg.write(ofp) |
108 ofp.close() | 108 ofp.close() |
109 | 109 |
110 def get_from_config(pcfg, sect, key): | 110 def get_from_config(pcfg, sect, key): |
210 if authdata: | 210 if authdata: |
211 cachedpwd = decrypt_salted(authdata, authkey) | 211 cachedpwd = decrypt_salted(authdata, authkey) |
212 passwd_field.setText(cachedpwd) | 212 passwd_field.setText(cachedpwd) |
213 remember_field = QtGui.QCheckBox() | 213 remember_field = QtGui.QCheckBox() |
214 remember_field.setChecked(remember) | 214 remember_field.setChecked(remember) |
215 remember_field.setText(_('Remember this password until EasyMercurial exits')) | 215 remember_field.setText(_('Remember passwords while EasyMercurial is running')) |
216 layout.addWidget(remember_field, 3, 1) | 216 layout.addWidget(remember_field, 3, 1) |
217 | 217 |
218 bb = QtGui.QDialogButtonBox() | 218 bb = QtGui.QDialogButtonBox() |
219 ok = bb.addButton(bb.Ok) | 219 ok = bb.addButton(bb.Ok) |
220 cancel = bb.addButton(bb.Cancel) | 220 cancel = bb.addButton(bb.Cancel) |
248 if passwd and remember: | 248 if passwd and remember: |
249 authdata = encrypt_salted(passwd, authkey) | 249 authdata = encrypt_salted(passwd, authkey) |
250 set_to_config(authconfig, 'auth', remote_key(short_uri, user), authdata) | 250 set_to_config(authconfig, 'auth', remote_key(short_uri, user), authdata) |
251 else: | 251 else: |
252 set_to_config(authconfig, 'auth', remote_key(short_uri, user), '') | 252 set_to_config(authconfig, 'auth', remote_key(short_uri, user), '') |
253 save_config(authconfig, authfile) | 253 save_config(self.ui, authconfig, authfile) |
254 | 254 |
255 self.add_password(realm, authuri, user, passwd) | 255 self.add_password(realm, authuri, user, passwd) |
256 return (user, passwd) | 256 return (user, passwd) |
257 | 257 |
258 | 258 |