summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Pursehouse <david.pursehouse@sonymobile.com>2015-08-20 16:55:42 +0900
committerDavid Pursehouse <david.pursehouse@sonymobile.com>2015-08-20 17:05:17 +0900
commitba7bc738c1044b68574a28423751156003400362 (patch)
treeb79f78944b488436f09490ac2ef4f40c227e250a
parentf4599a2a3de5025088e4248ea47f62d5edba24fd (diff)
downloadgit-repo-ba7bc738c1044b68574a28423751156003400362.tar.gz
Sync: Refactor netrc parsing
Don't emit a message when the netrc file doesn't exist or couldn't be opened. Instead of trying to unpack the result of info.authenticators() and catching the resulting TypeError when it's None, first store it to a local and only unpack it if it has a value. Also remove an unused import. Change-Id: I5c404d91e48c261c1ab850c3e5f040c4f4c235cb
-rw-r--r--subcmds/sync.py19
1 files changed, 9 insertions, 10 deletions
diff --git a/subcmds/sync.py b/subcmds/sync.py
index 0fc493c4..6191a3c3 100644
--- a/subcmds/sync.py
+++ b/subcmds/sync.py
@@ -65,7 +65,7 @@ except ImportError:
65 multiprocessing = None 65 multiprocessing = None
66 66
67from git_command import GIT, git_require 67from git_command import GIT, git_require
68from git_config import GetSchemeFromUrl, GetUrlCookieFile 68from git_config import GetUrlCookieFile
69from git_refs import R_HEADS, HEAD 69from git_refs import R_HEADS, HEAD
70import gitc_utils 70import gitc_utils
71from project import Project 71from project import Project
@@ -586,19 +586,18 @@ later is required to fix a server side protocol bug.
586 try: 586 try:
587 info = netrc.netrc() 587 info = netrc.netrc()
588 except IOError: 588 except IOError:
589 print('.netrc file does not exist or could not be opened', 589 # .netrc file does not exist or could not be opened
590 file=sys.stderr) 590 pass
591 else: 591 else:
592 try: 592 try:
593 parse_result = urllib.parse.urlparse(manifest_server) 593 parse_result = urllib.parse.urlparse(manifest_server)
594 if parse_result.hostname: 594 if parse_result.hostname:
595 username, _account, password = \ 595 auth = info.authenticators(parse_result.hostname)
596 info.authenticators(parse_result.hostname) 596 if auth:
597 except TypeError: 597 username, _account, password = auth
598 # TypeError is raised when the given hostname is not present 598 else:
599 # in the .netrc file. 599 print('No credentials found for %s in .netrc'
600 print('No credentials found for %s in .netrc' 600 % parse_result.hostname, file=sys.stderr)
601 % parse_result.hostname, file=sys.stderr)
602 except netrc.NetrcParseError as e: 601 except netrc.NetrcParseError as e:
603 print('Error parsing .netrc file: %s' % e, file=sys.stderr) 602 print('Error parsing .netrc file: %s' % e, file=sys.stderr)
604 603