From 7c0c3f67a6331661a87fbcece02fa6f76c0d9958 Mon Sep 17 00:00:00 2001 From: David Sansome Date: Sun, 18 Nov 2012 20:34:31 +1100 Subject: [PATCH] Read the user's google code password from ~/.netrc --- dist/googlecode_upload_all.py | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/dist/googlecode_upload_all.py b/dist/googlecode_upload_all.py index a5d2aafbb..e7def66e7 100644 --- a/dist/googlecode_upload_all.py +++ b/dist/googlecode_upload_all.py @@ -167,6 +167,30 @@ class VersionInfo(object): return labels +def get_google_code_password(username): + # Try to read it from the .netrc first + NETRC_REGEX = re.compile( + r'^machine\s+code\.google\.com\s+' + r'login\s+([^@]+)@[^\s]+\s+' + r'password\s+([^\s+])') + + try: + for line in open(os.path.expanduser("~/.netrc")): + match = NETRC_REGEX.match(line) + if match and match.group(1) == username: + print "Using password from ~/.netrc" + return match.group(2) + except IOError: + pass + + # Prompt the user + password = getpass.getpass("Google Code password (different to your Google account): ") + if not password: + return None + + return password + + def main(): dist_dir = os.path.dirname(os.path.abspath(__file__)) root_dir = os.path.normpath(os.path.join(dist_dir, "..")) @@ -205,11 +229,12 @@ def main(): if not username: return 1 - password = getpass.getpass("Google Code password (different to your Google account): ") - if not password: + password = get_google_code_password(username) + if password is None: return 1 print + return 0 # Upload everything for release in RELEASES: