|
@@ -22,6 +22,7 @@ if __name__ == '__main__':
|
|
|
del sys.argv[-1]
|
|
del sys.argv[-1]
|
|
|
del magic
|
|
del magic
|
|
|
|
|
|
|
|
|
|
+import getpass
|
|
|
import netrc
|
|
import netrc
|
|
|
import optparse
|
|
import optparse
|
|
|
import os
|
|
import os
|
|
@@ -276,7 +277,25 @@ class _UserAgentHandler(urllib2.BaseHandler):
|
|
|
req.add_header('User-Agent', _UserAgent())
|
|
req.add_header('User-Agent', _UserAgent())
|
|
|
return req
|
|
return req
|
|
|
|
|
|
|
|
|
|
+def _AddPasswordFromUserInput(handler, msg, req):
|
|
|
|
|
+ # If repo could not find auth info from netrc, try to get it from user input
|
|
|
|
|
+ url = req.get_full_url()
|
|
|
|
|
+ user, password = handler.passwd.find_user_password(None, url)
|
|
|
|
|
+ if user is None:
|
|
|
|
|
+ print msg
|
|
|
|
|
+ try:
|
|
|
|
|
+ user = raw_input('User: ')
|
|
|
|
|
+ password = getpass.getpass()
|
|
|
|
|
+ except KeyboardInterrupt:
|
|
|
|
|
+ return
|
|
|
|
|
+ handler.passwd.add_password(None, url, user, password)
|
|
|
|
|
+
|
|
|
class _BasicAuthHandler(urllib2.HTTPBasicAuthHandler):
|
|
class _BasicAuthHandler(urllib2.HTTPBasicAuthHandler):
|
|
|
|
|
+ def http_error_401(self, req, fp, code, msg, headers):
|
|
|
|
|
+ _AddPasswordFromUserInput(self, msg, req)
|
|
|
|
|
+ return urllib2.HTTPBasicAuthHandler.http_error_401(
|
|
|
|
|
+ self, req, fp, code, msg, headers)
|
|
|
|
|
+
|
|
|
def http_error_auth_reqed(self, authreq, host, req, headers):
|
|
def http_error_auth_reqed(self, authreq, host, req, headers):
|
|
|
try:
|
|
try:
|
|
|
old_add_header = req.add_header
|
|
old_add_header = req.add_header
|
|
@@ -295,6 +314,11 @@ class _BasicAuthHandler(urllib2.HTTPBasicAuthHandler):
|
|
|
raise
|
|
raise
|
|
|
|
|
|
|
|
class _DigestAuthHandler(urllib2.HTTPDigestAuthHandler):
|
|
class _DigestAuthHandler(urllib2.HTTPDigestAuthHandler):
|
|
|
|
|
+ def http_error_401(self, req, fp, code, msg, headers):
|
|
|
|
|
+ _AddPasswordFromUserInput(self, msg, req)
|
|
|
|
|
+ return urllib2.HTTPDigestAuthHandler.http_error_401(
|
|
|
|
|
+ self, req, fp, code, msg, headers)
|
|
|
|
|
+
|
|
|
def http_error_auth_reqed(self, auth_header, host, req, headers):
|
|
def http_error_auth_reqed(self, auth_header, host, req, headers):
|
|
|
try:
|
|
try:
|
|
|
old_add_header = req.add_header
|
|
old_add_header = req.add_header
|