Change-Id: Ibbe7114af871b3cafc2dde6e4085b52e6737f20e
Signed-off-by: Hasan Wan <hasan.wan@intel.com>
return True
+@retry()
def _clone_gitproject(giturl, gerritprj, localdir, bare=False):
"""Clone gerrit project from remote to local dir"""
os.getenv('GERRIT_SSHPORT'))
- return retry(_clone_gitproject, giturl, gerritprj, localdir, bare)
+ return _clone_gitproject(giturl, gerritprj, localdir, bare)
def __exit__(self, _type, _value, _tb):
os.chdir(self._cwd)
-def retry(func, *opts):
+# Retry decorator
+def retry(retries=3):
"""This will try to execute one function 3 times(by default) until \
success."""
-
- retry_count = 3
- while retry_count > 0:
- if (lambda func, *args: func(*args))(func, *opts):
- return True
- else:
- print '%s failed, retrying...' % func
- retry_count -= 1
- if not retry_count:
- return False
+ def deco_retry(func):
+ def f_retry(*args):
+ retry_count = retries
+ f = func(*args)
+ while retry_count > 0:
+ if f == True:
+ return True
+ else:
+ print '%s failed, retrying...' % func.func_name
+ retry_count -= 1
+ return False
+ return f_retry
+ return deco_retry
def find_spec(workdir):
"""Return specfile list in workdir"""