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
diff --git a/subcmds/sync.py b/subcmds/sync.py
index 0fc493c..6191a3c 100644
--- a/subcmds/sync.py
+++ b/subcmds/sync.py
@@ -65,7 +65,7 @@
   multiprocessing = None
 
 from git_command import GIT, git_require
-from git_config import GetSchemeFromUrl, GetUrlCookieFile
+from git_config import GetUrlCookieFile
 from git_refs import R_HEADS, HEAD
 import gitc_utils
 from project import Project
@@ -586,19 +586,18 @@
           try:
             info = netrc.netrc()
           except IOError:
-            print('.netrc file does not exist or could not be opened',
-                  file=sys.stderr)
+            # .netrc file does not exist or could not be opened
+            pass
           else:
             try:
               parse_result = urllib.parse.urlparse(manifest_server)
               if parse_result.hostname:
-                username, _account, password = \
-                  info.authenticators(parse_result.hostname)
-            except TypeError:
-              # TypeError is raised when the given hostname is not present
-              # in the .netrc file.
-              print('No credentials found for %s in .netrc'
-                    % parse_result.hostname, file=sys.stderr)
+                auth = info.authenticators(parse_result.hostname)
+                if auth:
+                  username, _account, password = auth
+                else:
+                  print('No credentials found for %s in .netrc'
+                        % parse_result.hostname, file=sys.stderr)
             except netrc.NetrcParseError as e:
               print('Error parsing .netrc file: %s' % e, file=sys.stderr)