Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(100)

Unified Diff: gerrit_util.py

Issue 293113005: Provide diagnostic messages about netrc failures. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/depot_tools
Patch Set: Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: gerrit_util.py
diff --git a/gerrit_util.py b/gerrit_util.py
index 3a4cc07660b4cc8315a140d74b3dc2ecf236b607..62fc1b9ab53cac7ddbf60f3f1dc70fae8ba93afd 100755
--- a/gerrit_util.py
+++ b/gerrit_util.py
@@ -15,14 +15,33 @@ import logging
import netrc
import os
import re
+import stat
+import sys
import time
import urllib
from cStringIO import StringIO
+_netrc_file = '_netrc' if sys.platform.startswith('win') else '.netrc'
+_netrc_file = os.path.join(os.environ['HOME'], _netrc_file)
try:
- NETRC = netrc.netrc()
-except (IOError, netrc.NetrcParseError):
+ NETRC = netrc.netrc(_netrc_file)
+except IOError:
+ print >> sys.stderr, 'WARNING: Could not read netrc file %s' % _netrc_file
NETRC = netrc.netrc(os.devnull)
+except netrc.NetrcParseError as e:
+ _netrc_stat = os.stat(e.filename)
+ if _netrc_stat.st_mode & (stat.S_IRWXG | stat.S_IRWXO):
+ print >> sys.stderr, (
+ 'WARNING: netrc file %s cannot be used because its file permissions '
+ 'are insecure. netrc file permissions should be 600.' % _netrc_file)
+ else:
+ print >> sys.stderr, ('ERROR: Cannot use netrc file %s due to a parsing '
+ 'error.' % _netrc_file)
+ raise
+ del _netrc_stat
+ NETRC = netrc.netrc(os.devnull)
+del _netrc_file
+
LOGGER = logging.getLogger()
TRY_LIMIT = 5
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698