def test_prompt_repeat(self): self.repeatsRemaining = 2 def mock_raw_input(message): self.repeatsRemaining -= 1 if not self.repeatsRemaining: return UserTest.example_user_response return None self.assertEqual(User.prompt("input", repeat=self.repeatsRemaining, raw_input=mock_raw_input), UserTest.example_user_response)
def prompt_for_component(self, components): log("Please pick a component:") i = 0 for name in components: i += 1 log("%2d. %s" % (i, name)) result = int(User.prompt("Enter a number: ")) - 1 return components[result]
def test_prompt_when_exceeded_repeats(self): self.repeatsRemaining = 2 def mock_raw_input(message): self.repeatsRemaining -= 1 return None self.assertEqual( User.prompt("input", repeat=self.repeatsRemaining, raw_input=mock_raw_input), None)
def __init__(self, path): MultiCommandTool.__init__(self) self._path = path self.bugs = Bugzilla() self.buildbot = BuildBot() self.executive = Executive() self._irc = None self.user = User() self._scm = None self._checkout = None self.status_server = StatusServer()
def prompt_for_bug_title_and_comment(self): bug_title = User.prompt("Bug title: ") print "Bug comment (hit ^D on blank line to end):" lines = sys.stdin.readlines() try: sys.stdin.seek(0, os.SEEK_END) except IOError: # Cygwin raises an Illegal Seek (errno 29) exception when the above # seek() call is made. Ignoring it seems to cause no harm. # FIXME: Figure out a way to get avoid the exception in the first # place. pass comment_text = "".join(lines) return (bug_title, comment_text)
class Credentials(object): def __init__(self, host, git_prefix=None, executive=None, cwd=os.getcwd()): self.host = host self.git_prefix = git_prefix self.executive = executive or Executive() self.cwd = cwd def _credentials_from_git(self): return [ self._read_git_config("username"), self._read_git_config("password") ] def _read_git_config(self, key): config_key = "%s.%s" % (self.git_prefix, key) if self.git_prefix \ else key return self.executive.run_command( ["git", "config", "--get", config_key], error_handler=Executive.ignore_error).rstrip('\n') def _keychain_value_with_label(self, label, source_text): match = re.search("%s\"(?P<value>.+)\"" % label, source_text, re.MULTILINE) if match: return match.group('value') def _is_mac_os_x(self): return platform.mac_ver()[0] def _parse_security_tool_output(self, security_output): username = self._keychain_value_with_label("^\s*\"acct\"<blob>=", security_output) password = self._keychain_value_with_label("^password: "******"/usr/bin/security", "find-internet-password", "-g", "-s", self.host, ] if username: security_command += ["-a", username] log("Reading Keychain for %s account and password. " "Click \"Allow\" to continue..." % self.host) try: return self.executive.run_command(security_command) except ScriptError: # Failed to either find a keychain entry or somekind of OS-related # error occured (for instance, couldn't find the /usr/sbin/security # command). log("Could not find a keychain entry for %s." % self.host) return None def _credentials_from_keychain(self, username=None): if not self._is_mac_os_x(): return [username, None] security_output = self._run_security_tool(username) if security_output: return self._parse_security_tool_output(security_output) else: return [None, None] def read_credentials(self): username = None password = None try: if Git.in_working_directory(self.cwd): (username, password) = self._credentials_from_git() except OSError, e: # Catch and ignore OSError exceptions such as "no such file # or directory" (OSError errno 2), which imply that the Git # command cannot be found/is not installed. pass if not username or not password: (username, password) = self._credentials_from_keychain(username) if not username: username = User.prompt("%s login: "******"%s password for %s: " % (self.host, username)) return [username, password]
def test_prompt_when_exceeded_repeats(self): self.repeatsRemaining = 2 def mock_raw_input(message): self.repeatsRemaining -= 1 return None self.assertEqual(User.prompt("input", repeat=self.repeatsRemaining, raw_input=mock_raw_input), None)