[SCM] WebKit Debian packaging branch, debian/experimental, updated. upstream/1.3.3-9427-gc2be6fc

tony at chromium.org tony at chromium.org
Wed Dec 22 13:53:43 UTC 2010


The following commit has been merged in the debian/experimental branch:
commit 5220470a6e1266a8e44a805a36f11c1508b86738
Author: tony at chromium.org <tony at chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date:   Tue Sep 28 22:55:59 2010 +0000

    2010-09-28  Tony Chang  <tony at chromium.org>
    
            Reviewed by Eric Seidel.
    
            add python keyring support to webkit-patch
            https://bugs.webkit.org/show_bug.cgi?id=41269
    
            * Scripts/webkitpy/common/net/credentials.py: Add the ability to read passwords using
                the python keyring module
            * Scripts/webkitpy/common/net/credentials_unittest.py:
            * Scripts/webkitpy/common/system/user.py: Allow confirm() to default to no and add testing params.
            * Scripts/webkitpy/common/system/user_unittest.py:
            * Scripts/webkitpy/tool/mocktool.py:
    
    git-svn-id: http://svn.webkit.org/repository/webkit/trunk@68599 268f45cc-cd09-0410-ab3c-d52691b4dbfc

diff --git a/WebKitTools/ChangeLog b/WebKitTools/ChangeLog
index eb7c75e..c828c6c 100644
--- a/WebKitTools/ChangeLog
+++ b/WebKitTools/ChangeLog
@@ -1,3 +1,17 @@
+2010-09-28  Tony Chang  <tony at chromium.org>
+
+        Reviewed by Eric Seidel.
+
+        add python keyring support to webkit-patch
+        https://bugs.webkit.org/show_bug.cgi?id=41269
+
+        * Scripts/webkitpy/common/net/credentials.py: Add the ability to read passwords using
+            the python keyring module
+        * Scripts/webkitpy/common/net/credentials_unittest.py:
+        * Scripts/webkitpy/common/system/user.py: Allow confirm() to default to no and add testing params.
+        * Scripts/webkitpy/common/system/user_unittest.py:
+        * Scripts/webkitpy/tool/mocktool.py:
+
 2010-09-28  Martin Robinson  <mrobinson at igalia.com>
 
         Reviewed by Gustavo Noronha Silva.
diff --git a/WebKitTools/Scripts/webkitpy/common/net/credentials.py b/WebKitTools/Scripts/webkitpy/common/net/credentials.py
index 1d5f83d..1c3e6c0 100644
--- a/WebKitTools/Scripts/webkitpy/common/net/credentials.py
+++ b/WebKitTools/Scripts/webkitpy/common/net/credentials.py
@@ -39,14 +39,23 @@ from webkitpy.common.system.executive import Executive, ScriptError
 from webkitpy.common.system.user import User
 from webkitpy.common.system.deprecated_logging import log
 
+try:
+    # Use keyring, a cross platform keyring interface, as a fallback:
+    # http://pypi.python.org/pypi/keyring
+    import keyring
+except ImportError:
+    keyring = None
+
 
 class Credentials(object):
 
-    def __init__(self, host, git_prefix=None, executive=None, cwd=os.getcwd()):
+    def __init__(self, host, git_prefix=None, executive=None, cwd=os.getcwd(),
+                 keyring=keyring):
         self.host = host
         self.git_prefix = "%s." % git_prefix if git_prefix else ""
         self.executive = executive or Executive()
         self.cwd = cwd
+        self._keyring = keyring
 
     def _credentials_from_git(self):
         return [Git.read_git_config(self.git_prefix + "username"),
@@ -117,10 +126,19 @@ class Credentials(object):
         if not username or not password:
             (username, password) = self._credentials_from_keychain(username)
 
+        if username and not password and self._keyring:
+            password = self._keyring.get_password(self.host, username)
+
         if not username:
             username = User.prompt("%s login: " % self.host)
         if not password:
             password = getpass.getpass("%s password for %s: " % (self.host,
                                                                  username))
 
+            if self._keyring:
+                store_password = User().confirm(
+                    "Store password in system keyring?", User.DEFAULT_NO)
+                if store_password:
+                    self._keyring.set_password(self.host, username, password)
+
         return [username, password]
diff --git a/WebKitTools/Scripts/webkitpy/common/net/credentials_unittest.py b/WebKitTools/Scripts/webkitpy/common/net/credentials_unittest.py
index 9a42bdd..d30291b 100644
--- a/WebKitTools/Scripts/webkitpy/common/net/credentials_unittest.py
+++ b/WebKitTools/Scripts/webkitpy/common/net/credentials_unittest.py
@@ -113,5 +113,28 @@ password: "SECRETSAUCE"
         self.assertEqual(credentials.read_credentials(), ["test at webkit.org", "SECRETSAUCE"])
         os.rmdir(temp_dir_path)
 
+    def test_keyring_without_git_repo(self):
+        class MockKeyring(object):
+            def get_password(self, host, username):
+                return "NOMNOMNOM"
+
+        class FakeCredentials(Credentials):
+            def __init__(self, cwd):
+                Credentials.__init__(self, "fake.hostname", cwd=cwd,
+                                     keyring=MockKeyring())
+
+            def _is_mac_os_x(self):
+                return True
+
+            def _credentials_from_keychain(self, username):
+                return ("test at webkit.org", None)
+
+        temp_dir_path = tempfile.mkdtemp(suffix="not_a_git_repo")
+        credentials = FakeCredentials(temp_dir_path)
+        try:
+            self.assertEqual(credentials.read_credentials(), ["test at webkit.org", "NOMNOMNOM"])
+        finally:
+            os.rmdir(temp_dir_path)
+
 if __name__ == '__main__':
     unittest.main()
diff --git a/WebKitTools/Scripts/webkitpy/common/system/user.py b/WebKitTools/Scripts/webkitpy/common/system/user.py
index dffa027..240b67b 100644
--- a/WebKitTools/Scripts/webkitpy/common/system/user.py
+++ b/WebKitTools/Scripts/webkitpy/common/system/user.py
@@ -52,6 +52,9 @@ except ImportError:
 
 
 class User(object):
+    DEFAULT_NO = 'n'
+    DEFAULT_YES = 'y'
+
     # FIXME: These are @classmethods because bugzilla.py doesn't have a Tool object (thus no User instance).
     @classmethod
     def prompt(cls, message, repeat=1, raw_input=raw_input):
@@ -115,11 +118,14 @@ class User(object):
         except IOError, e:
             pass
 
-    def confirm(self, message=None):
+    def confirm(self, message=None, default=DEFAULT_YES, raw_input=raw_input):
         if not message:
             message = "Continue?"
-        response = raw_input("%s [Y/n]: " % message)
-        return not response or response.lower() == "y"
+        choice = {'y': 'Y/n', 'n': 'y/N'}[default]
+        response = raw_input("%s [%s]: " % (message, choice))
+        if not response:
+            response = default
+        return response.lower() == 'y'
 
     def can_open_url(self):
         try:
diff --git a/WebKitTools/Scripts/webkitpy/common/system/user_unittest.py b/WebKitTools/Scripts/webkitpy/common/system/user_unittest.py
index 23b546f..ae1bad5 100644
--- a/WebKitTools/Scripts/webkitpy/common/system/user_unittest.py
+++ b/WebKitTools/Scripts/webkitpy/common/system/user_unittest.py
@@ -75,5 +75,27 @@ class UserTest(unittest.TestCase):
         run_prompt_test(["  "], ["foo", "bar"], can_choose_multiple=True)
         run_prompt_test(["badinput", "all"], ["foo", "bar"], can_choose_multiple=True)
 
+    def test_confirm(self):
+        test_cases = (
+            (("Continue? [Y/n]: ", True), (User.DEFAULT_YES, 'y')),
+            (("Continue? [Y/n]: ", False), (User.DEFAULT_YES, 'n')),
+            (("Continue? [Y/n]: ", True), (User.DEFAULT_YES, '')),
+            (("Continue? [Y/n]: ", False), (User.DEFAULT_YES, 'q')),
+            (("Continue? [y/N]: ", True), (User.DEFAULT_NO, 'y')),
+            (("Continue? [y/N]: ", False), (User.DEFAULT_NO, 'n')),
+            (("Continue? [y/N]: ", False), (User.DEFAULT_NO, '')),
+            (("Continue? [y/N]: ", False), (User.DEFAULT_NO, 'q')),
+        )
+        for test_case in test_cases:
+            expected, inputs = test_case
+
+            def mock_raw_input(message):
+                self.assertEquals(expected[0], message)
+                return inputs[1]
+
+            result = User().confirm(default=inputs[0],
+                                    raw_input=mock_raw_input)
+            self.assertEquals(expected[1], result)
+
 if __name__ == '__main__':
     unittest.main()
diff --git a/WebKitTools/Scripts/webkitpy/tool/mocktool.py b/WebKitTools/Scripts/webkitpy/tool/mocktool.py
index 5084ed5..277bd08 100644
--- a/WebKitTools/Scripts/webkitpy/tool/mocktool.py
+++ b/WebKitTools/Scripts/webkitpy/tool/mocktool.py
@@ -491,8 +491,8 @@ class MockUser(object):
     def page(self, message):
         pass
 
-    def confirm(self, message=None):
-        return True
+    def confirm(self, message=None, default='y'):
+        return default == 'y'
 
     def can_open_url(self):
         return True

-- 
WebKit Debian packaging



More information about the Pkg-webkit-commits mailing list