Show More
@@ -0,0 +1,27 b'' | |||
|
1 | #!/usr/bin/python | |
|
2 | # | |
|
3 | # mercurial - scalable distributed SCM | |
|
4 | # | |
|
5 | # Copyright 2005-2007 Matt Mackall <mpm@selenic.com> | |
|
6 | # | |
|
7 | # This software may be used and distributed according to the terms of the | |
|
8 | # GNU General Public License version 2, incorporated herein by reference. | |
|
9 | ||
|
10 | # enable importing on demand to reduce startup time | |
|
11 | try: | |
|
12 | from mercurial import demandimport; demandimport.enable() | |
|
13 | except ImportError: | |
|
14 | import sys | |
|
15 | sys.stderr.write("abort: couldn't find mercurial libraries in [%s]\n" % | |
|
16 | ' '.join(sys.path)) | |
|
17 | sys.stderr.write("(check your install and PYTHONPATH)\n") | |
|
18 | sys.exit(-1) | |
|
19 | ||
|
20 | import sys | |
|
21 | import mercurial.util | |
|
22 | import mercurial.dispatch | |
|
23 | ||
|
24 | for fp in (sys.stdin, sys.stdout, sys.stderr): | |
|
25 | mercurial.util.set_binary(fp) | |
|
26 | ||
|
27 | mercurial.dispatch.run() |
@@ -63,15 +63,15 b' class PasswordStore(object):' | |||
|
63 | 63 | """ |
|
64 | 64 | def __init__(self): |
|
65 | 65 | self.cache = dict() |
|
66 |
def |
|
|
67 | self.cache[url] = (username, password) | |
|
68 | # TODO: keyring save | |
|
69 |
def |
|
|
70 | r = self.cache.get(url) | |
|
71 | if r: | |
|
72 | return r | |
|
73 | # TODO: keyring restore | |
|
74 | return None, None | |
|
66 | def get_password(self, url, username): | |
|
67 | return keyring.get_password(KEYRING_SERVICE, | |
|
68 | self._format_key(url, username)) | |
|
69 | def set_password(self, url, username, password): | |
|
70 | keyring.set_password(KEYRING_SERVICE, | |
|
71 | self._format_key(url, username), | |
|
72 | password) | |
|
73 | def _format_key(self, url, username): | |
|
74 | return "%s@@%s" % (username, url) | |
|
75 | 75 | |
|
76 | 76 | password_store = PasswordStore() |
|
77 | 77 | |
@@ -123,23 +123,28 b' def find_user_password(self, realm, auth' | |||
|
123 | 123 | local_passwordmgr = passwordmgr(local_ui) |
|
124 | 124 | auth_token = local_passwordmgr.readauthtoken(base_url) |
|
125 | 125 | if auth_token: |
|
126 | user, pwd = auth.get('username'), auth.get('password') | |
|
127 | ||
|
128 | ||
|
129 | ||
|
130 | ||
|
131 | user, pwd = password_store.get_password(base_url) | |
|
132 | if user and pwd: | |
|
133 | return user, pwd | |
|
126 | user, pwd = auth_token.get('username'), auth_token.get('password') | |
|
134 | 127 | |
|
135 | if not self.ui.interactive(): | |
|
136 | raise util.Abort(_('mercurial_keyring: http authorization required')) | |
|
137 | self.ui.write(_("http authorization required\n")) | |
|
138 | self.ui.status(_("realm: %s, url: %s\n" % (realm, base_url))) | |
|
139 | user = self.ui.prompt(_("user:"), default = user) | |
|
140 |
|
|
|
128 | # username still not known? Asking | |
|
129 | if not user: | |
|
130 | if not self.ui.interactive(): | |
|
131 | raise util.Abort(_('mercurial_keyring: http authorization required')) | |
|
132 | self.ui.write(_("http authorization required\n")) | |
|
133 | self.ui.status(_("realm: %s\n") % realm) | |
|
134 | user = self.ui.prompt(_("user:"), default=None) | |
|
135 | ||
|
136 | # username known and still no password? Time to check keyring | |
|
137 | if user and not pwd: | |
|
138 | pwd = password_store.get_password(base_url, user) | |
|
141 | 139 | |
|
142 | password_store.save_password(base_url, user, pwd) | |
|
140 | # password still not known? Asking | |
|
141 | if not pwd: | |
|
142 | if not self.ui.interactive(): | |
|
143 | raise util.Abort(_('mercurial_keyring: http authorization required')) | |
|
144 | pwd = self.ui.getpass(_("password: ")) | |
|
145 | password_store.set_password(base_url, user, pwd) | |
|
146 | ||
|
147 | self._pwd_cache[cache_key] = (user, pwd) | |
|
143 | 148 | |
|
144 | 149 | return user, pwd |
|
145 | 150 | #return None, None |
General Comments 0
You need to be logged in to leave comments.
Login now