From cd1a36dc28e07560bd71de63360fca0de2c071cf Mon Sep 17 00:00:00 2001 From: Lingchaox Xin Date: Fri, 14 Jun 2013 10:20:10 +0800 Subject: [PATCH] Pylint for common/utils.py Replace apply() with the extended call syntax: function(*args, **keywords). Fix no RuntimeException found error. Change-Id: I6dbe96c23e982726d4ac0281cb2075288d5f24b9 --- common/git.py | 2 +- common/utils.py | 14 +++++++++----- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/common/git.py b/common/git.py index 0539fa6..e73e8b2 100644 --- a/common/git.py +++ b/common/git.py @@ -196,4 +196,4 @@ def clone_gitproject(gerritprj, localdir, giturl=None): os.getenv('GERRIT_SSHPORT')) - return retry(_clone_gitproject, (giturl, gerritprj, localdir)) + return retry(_clone_gitproject, giturl, gerritprj, localdir) diff --git a/common/utils.py b/common/utils.py index 2ee51aa..9050af6 100644 --- a/common/utils.py +++ b/common/utils.py @@ -24,6 +24,10 @@ import subprocess from common import runner +class RuntimeException(Exception): + """Local error handler""" + pass + class Workdir(object): """A class which supports with statement""" @@ -39,13 +43,13 @@ class Workdir(object): def __exit__(self, _type, _value, _tb): os.chdir(self._cwd) -def retry(func, opts): +def retry(func, *opts): """This will try to execute one function 3 times(by default) until \ success.""" retry_count = 3 while retry_count > 0: - if apply(func, opts): + if (lambda func, *args: func(*args))(func, *opts): return True else: print '%s failed, retrying...' % func @@ -100,16 +104,16 @@ def sync(source, destination): # Through rsync protocol if destination.startswith('rsync:'): - cmd = "rsync -av %s/ %s" %(source, destination) + cmd = "rsync -av %s/ %s" % (source, destination) # Through ssh protocol elif destination.startswith('ssh:'): destination = destination.replace("ssh://", "") - cmd = "scp -r %s/* %s" %(source, destination) + cmd = "scp -r %s/* %s" % (source, destination) # Try to take the destination as local path else: - cmd = "mv -v %s/* %s/" %(source, destination) + cmd = "mv -v %s/* %s/" % (source, destination) try: ret_code = subprocess.call(cmd, shell = True) except OSError as err: -- 2.7.4