From 1640a65091c56eeed0f6bb1020fd156cdc279a6e Mon Sep 17 00:00:00 2001 From: Alexandru DAMIAN Date: Thu, 30 Jul 2015 19:25:09 +0300 Subject: bitbake: toaster: tts: fix pylint warnings This patch brings TTS to the pylint coding standards. Pylint was run with some disables: disable=logging-too-many-args,line-too-long,missing-docstring and achieved Your code has been rated at 10.00/10 There are no functional changes. (Bitbake rev: 2b40b412ff6a7e3fd4cc32707bd3cd713bc09ddb) Signed-off-by: Alexandru DAMIAN Signed-off-by: Ed Bartosh Signed-off-by: Richard Purdie --- bitbake/lib/toaster/contrib/tts/shellutils.py | 64 ++++++++++++++------------- 1 file changed, 33 insertions(+), 31 deletions(-) (limited to 'bitbake/lib/toaster/contrib/tts/shellutils.py') diff --git a/bitbake/lib/toaster/contrib/tts/shellutils.py b/bitbake/lib/toaster/contrib/tts/shellutils.py index 2b7f0f1d2e..c2012edf83 100644 --- a/bitbake/lib/toaster/contrib/tts/shellutils.py +++ b/bitbake/lib/toaster/contrib/tts/shellutils.py @@ -37,16 +37,16 @@ def mkdirhier(directory): try: os.makedirs(directory) - except OSError as e: - if e.errno != errno.EEXIST: - raise e + except OSError as exc: + if exc.errno != errno.EEXIST: + raise exc def lockfile(name, shared=False, retry=True): """ Use the file fn as a lock file, return when the lock has been acquired. Returns a variable to pass to unlockfile(). """ - config.logger.debug("take lockfile %s" % name) + config.logger.debug("take lockfile %s", name) dirname = os.path.dirname(name) mkdirhier(dirname) @@ -55,11 +55,11 @@ def lockfile(name, shared=False, retry=True): name) sys.exit(1) - op = fcntl.LOCK_EX + operation = fcntl.LOCK_EX if shared: - op = fcntl.LOCK_SH + operation = fcntl.LOCK_SH if not retry: - op = op | fcntl.LOCK_NB + operation = operation | fcntl.LOCK_NB while True: # If we leave the lockfiles lying around there is no problem @@ -72,38 +72,40 @@ def lockfile(name, shared=False, retry=True): # This implementation is unfair since the last person to request the # lock is the most likely to win it. + # pylint: disable=broad-except + # we disable the broad-except because we want to actually catch all possible exceptions try: - lf = open(name, 'a+') - fileno = lf.fileno() - fcntl.flock(fileno, op) + lock_file = open(name, 'a+') + fileno = lock_file.fileno() + fcntl.flock(fileno, operation) statinfo = os.fstat(fileno) - if os.path.exists(lf.name): - statinfo2 = os.stat(lf.name) + if os.path.exists(lock_file.name): + statinfo2 = os.stat(lock_file.name) if statinfo.st_ino == statinfo2.st_ino: - return lf - lf.close() - except Exception: + return lock_file + lock_file.close() + except Exception as exc: try: - lf.close() - except Exception: - pass - pass + lock_file.close() + except Exception as exc2: + config.logger.error("Failed to close the lockfile: %s", exc2) + config.logger.error("Failed to acquire the lockfile: %s", exc) if not retry: return None -def unlockfile(lf): +def unlockfile(lock_file): """ Unlock a file locked using lockfile() """ try: # If we had a shared lock, we need to promote to exclusive before # removing the lockfile. Attempt this, ignore failures. - fcntl.flock(lf.fileno(), fcntl.LOCK_EX|fcntl.LOCK_NB) - os.unlink(lf.name) + fcntl.flock(lock_file.fileno(), fcntl.LOCK_EX|fcntl.LOCK_NB) + os.unlink(lock_file.name) except (IOError, OSError): pass - fcntl.flock(lf.fileno(), fcntl.LOCK_UN) - lf.close() + fcntl.flock(lock_file.fileno(), fcntl.LOCK_UN) + lock_file.close() #ENDOFCOPY @@ -118,20 +120,20 @@ def mk_lock_filename(): class ShellCmdException(Exception): pass -def run_shell_cmd(command, cwd = None): +def run_shell_cmd(command, cwd=None): if cwd is None: cwd = os.getcwd() - config.logger.debug("_shellcmd: (%s) %s" % (cwd, command)) - p = subprocess.Popen(command, cwd = cwd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) - (out,err) = p.communicate() - p.wait() - if p.returncode: + config.logger.debug("_shellcmd: (%s) %s", cwd, command) + process = subprocess.Popen(command, cwd=cwd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + (out, err) = process.communicate() + process.wait() + if process.returncode: if len(err) == 0: err = "command: %s \n%s" % (command, out) else: err = "command: %s \n%s" % (command, err) - config.logger.warn("_shellcmd: error \n%s\n%s" % (out, err)) + config.logger.warn("_shellcmd: error \n%s\n%s", out, err) raise ShellCmdException(err) else: #config.logger.debug("localhostbecontroller: shellcmd success\n%s" % out) -- cgit v1.2.3-54-g00ecf