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

Side by Side Diff: third_party/gsutil/boto/tests/integration/gs/util.py

Issue 12317103: Added gsutil to depot tools (Closed) Base URL: https://chromium.googlesource.com/chromium/tools/depot_tools.git@master
Patch Set: added readme Created 7 years, 9 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 unified diff | Download patch
OLDNEW
(Empty)
1 import time
2
3 from boto.provider import Provider
4
5
6 _HAS_GOOGLE_CREDENTIALS = None
7
8
9 def has_google_credentials():
10 global _HAS_GOOGLE_CREDENTIALS
11 if _HAS_GOOGLE_CREDENTIALS is None:
12 provider = Provider('google')
13 if provider.access_key is None or provider.secret_key is None:
14 _HAS_GOOGLE_CREDENTIALS = False
15 else:
16 _HAS_GOOGLE_CREDENTIALS = True
17 return _HAS_GOOGLE_CREDENTIALS
18
19
20 def retry(ExceptionToCheck, tries=4, delay=3, backoff=2, logger=None):
21 """Retry calling the decorated function using an exponential backoff.
22
23 Taken from:
24 https://github.com/saltycrane/retry-decorator
25 Licensed under BSD:
26 https://github.com/saltycrane/retry-decorator/blob/master/LICENSE
27
28 :param ExceptionToCheck: the exception to check. may be a tuple of
29 exceptions to check
30 :type ExceptionToCheck: Exception or tuple
31 :param tries: number of times to try (not retry) before giving up
32 :type tries: int
33 :param delay: initial delay between retries in seconds
34 :type delay: int
35 :param backoff: backoff multiplier e.g. value of 2 will double the delay
36 each retry
37 :type backoff: int
38 :param logger: logger to use. If None, print
39 :type logger: logging.Logger instance
40 """
41 def deco_retry(f):
42 def f_retry(*args, **kwargs):
43 mtries, mdelay = tries, delay
44 try_one_last_time = True
45 while mtries > 1:
46 try:
47 return f(*args, **kwargs)
48 try_one_last_time = False
49 break
50 except ExceptionToCheck, e:
51 msg = "%s, Retrying in %d seconds..." % (str(e), mdelay)
52 if logger:
53 logger.warning(msg)
54 else:
55 print msg
56 time.sleep(mdelay)
57 mtries -= 1
58 mdelay *= backoff
59 if try_one_last_time:
60 return f(*args, **kwargs)
61 return
62 return f_retry # true decorator
63 return deco_retry
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698