Commits

Marcin Kasperski committed 6f5398b

Working version. Password is actually saved and restored,
still errors are not handled.

Comments (0)

Files changed (2)

+#!/usr/bin/python
+#
+# mercurial - scalable distributed SCM
+#
+# Copyright 2005-2007 Matt Mackall <mpm@selenic.com>
+#
+# This software may be used and distributed according to the terms of the
+# GNU General Public License version 2, incorporated herein by reference.
+
+# enable importing on demand to reduce startup time
+try:
+    from mercurial import demandimport; demandimport.enable()
+except ImportError:
+    import sys
+    sys.stderr.write("abort: couldn't find mercurial libraries in [%s]\n" %
+                     ' '.join(sys.path))
+    sys.stderr.write("(check your install and PYTHONPATH)\n")
+    sys.exit(-1)
+
+import sys
+import mercurial.util
+import mercurial.dispatch
+
+for fp in (sys.stdin, sys.stdout, sys.stderr):
+    mercurial.util.set_binary(fp)
+
+mercurial.dispatch.run()

mercurial_keyring.py

     """
     def __init__(self):
         self.cache = dict()
-    def save_password(self, url, username, password):
-        self.cache[url] = (username, password)
-        # TODO: keyring save
-    def get_password(self, url):
-        r = self.cache.get(url)    
-        if r:
-           return r
-        # TODO: keyring restore
-        return None, None
+    def get_password(self, url, username):
+        return keyring.get_password(KEYRING_SERVICE,
+                                    self._format_key(url, username))
+    def set_password(self, url, username, password):
+        keyring.set_password(KEYRING_SERVICE,
+                             self._format_key(url, username),
+                             password)
+    def _format_key(self, url, username):
+        return "%s@@%s" % (username, url)
 
 password_store = PasswordStore()
 
           local_passwordmgr = passwordmgr(local_ui)
           auth_token = local_passwordmgr.readauthtoken(base_url)
           if auth_token:
-             user, pwd = auth.get('username'), auth.get('password')
+             user, pwd = auth_token.get('username'), auth_token.get('password')
 
+    # username still not known? Asking
+    if not user:
+       if not self.ui.interactive():
+          raise util.Abort(_('mercurial_keyring: http authorization required'))
+       self.ui.write(_("http authorization required\n"))
+       self.ui.status(_("realm: %s\n") % realm)
+       user = self.ui.prompt(_("user:"), default=None)
+    
+    # username known and still no password? Time to check keyring
+    if user and not pwd:
+       pwd = password_store.get_password(base_url, user)
 
+    # password still not known? Asking
+    if not pwd:
+       if not self.ui.interactive():
+          raise util.Abort(_('mercurial_keyring: http authorization required'))
+       pwd = self.ui.getpass(_("password: "))
+       password_store.set_password(base_url, user, pwd)
 
-    
-    user, pwd = password_store.get_password(base_url)
-    if user and pwd:
-       return user, pwd
-
-    if not self.ui.interactive():
-       raise util.Abort(_('mercurial_keyring: http authorization required'))
-    self.ui.write(_("http authorization required\n"))
-    self.ui.status(_("realm: %s, url: %s\n" % (realm, base_url)))
-    user = self.ui.prompt(_("user:"), default = user)
-    pwd = self.ui.getpass(_("password: "))
-
-    password_store.save_password(base_url, user, pwd)
+    self._pwd_cache[cache_key] = (user, pwd)
 
     return user, pwd
     #return None, None