Make maxtries for Rietveld configurable

R=machenbach
TBR=maruel

BUG=459855

Review URL: https://codereview.chromium.org/932333003

git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@294121 0039d316-1c4b-4281-b951-d872f2087c98
diff --git a/rietveld.py b/rietveld.py
index f5832de..c64235b 100644
--- a/rietveld.py
+++ b/rietveld.py
@@ -37,7 +37,7 @@
 
 class Rietveld(object):
   """Accesses rietveld."""
-  def __init__(self, url, email, password, extra_headers=None):
+  def __init__(self, url, email, password, extra_headers=None, maxtries=None):
     self.url = url.rstrip('/')
     # Email and password are accessed by commit queue, keep them.
     self.email = email
@@ -64,6 +64,8 @@
     self._xsrf_token = None
     self._xsrf_token_time = None
 
+    self._maxtries = maxtries or 40
+
   def xsrf_token(self):
     if (not self._xsrf_token_time or
         (time.time() - self._xsrf_token_time) > 30*60):
@@ -413,8 +415,7 @@
         old_error_exit(msg)
       upload.ErrorExit = trap_http_500
 
-      maxtries = 40
-      for retry in xrange(maxtries):
+      for retry in xrange(self._maxtries):
         try:
           logging.debug('%s' % request_path)
           result = self.rpc_server.Send(request_path, **kwargs)
@@ -422,7 +423,7 @@
           # How nice.
           return result
         except urllib2.HTTPError, e:
-          if retry >= (maxtries - 1):
+          if retry >= (self._maxtries - 1):
             raise
           flake_codes = [500, 502, 503]
           if retry_on_404:
@@ -430,14 +431,14 @@
           if e.code not in flake_codes:
             raise
         except urllib2.URLError, e:
-          if retry >= (maxtries - 1):
+          if retry >= (self._maxtries - 1):
             raise
           if (not 'Name or service not known' in e.reason and
               not 'EOF occurred in violation of protocol' in e.reason):
             # Usually internal GAE flakiness.
             raise
         except ssl.SSLError, e:
-          if retry >= (maxtries - 1):
+          if retry >= (self._maxtries - 1):
             raise
           if not 'timed out' in str(e):
             raise
@@ -575,7 +576,8 @@
                client_email,
                client_private_key_file,
                private_key_password=None,
-               extra_headers=None):
+               extra_headers=None,
+               maxtries=None):
 
     # These attributes are accessed by commit queue. Keep them.
     self.email = client_email
@@ -598,6 +600,8 @@
     self._xsrf_token = None
     self._xsrf_token_time = None
 
+    self._maxtries = 40 or maxtries
+
 
 class CachingRietveld(Rietveld):
   """Caches the common queries.