summaryrefslogtreecommitdiffstats
path: root/bitbake/lib/toaster/contrib/tts/shellutils.py
diff options
context:
space:
mode:
authorAlexandru DAMIAN <alexandru.damian@intel.com>2015-07-30 19:25:09 +0300
committerRichard Purdie <richard.purdie@linuxfoundation.org>2015-08-01 11:26:13 +0100
commit1640a65091c56eeed0f6bb1020fd156cdc279a6e (patch)
treeee36a0a10c1fea4d5e10e645b9077f80d6d67567 /bitbake/lib/toaster/contrib/tts/shellutils.py
parent160d610604fff0b119de2b70a9da8a5f73d93715 (diff)
downloadpoky-1640a65091c56eeed0f6bb1020fd156cdc279a6e.tar.gz
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 <alexandru.damian@intel.com> Signed-off-by: Ed Bartosh <ed.bartosh@linux.intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'bitbake/lib/toaster/contrib/tts/shellutils.py')
-rw-r--r--bitbake/lib/toaster/contrib/tts/shellutils.py64
1 files changed, 33 insertions, 31 deletions
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):
37 37
38 try: 38 try:
39 os.makedirs(directory) 39 os.makedirs(directory)
40 except OSError as e: 40 except OSError as exc:
41 if e.errno != errno.EEXIST: 41 if exc.errno != errno.EEXIST:
42 raise e 42 raise exc
43 43
44def lockfile(name, shared=False, retry=True): 44def lockfile(name, shared=False, retry=True):
45 """ 45 """
46 Use the file fn as a lock file, return when the lock has been acquired. 46 Use the file fn as a lock file, return when the lock has been acquired.
47 Returns a variable to pass to unlockfile(). 47 Returns a variable to pass to unlockfile().
48 """ 48 """
49 config.logger.debug("take lockfile %s" % name) 49 config.logger.debug("take lockfile %s", name)
50 dirname = os.path.dirname(name) 50 dirname = os.path.dirname(name)
51 mkdirhier(dirname) 51 mkdirhier(dirname)
52 52
@@ -55,11 +55,11 @@ def lockfile(name, shared=False, retry=True):
55 name) 55 name)
56 sys.exit(1) 56 sys.exit(1)
57 57
58 op = fcntl.LOCK_EX 58 operation = fcntl.LOCK_EX
59 if shared: 59 if shared:
60 op = fcntl.LOCK_SH 60 operation = fcntl.LOCK_SH
61 if not retry: 61 if not retry:
62 op = op | fcntl.LOCK_NB 62 operation = operation | fcntl.LOCK_NB
63 63
64 while True: 64 while True:
65 # If we leave the lockfiles lying around there is no problem 65 # If we leave the lockfiles lying around there is no problem
@@ -72,38 +72,40 @@ def lockfile(name, shared=False, retry=True):
72 # This implementation is unfair since the last person to request the 72 # This implementation is unfair since the last person to request the
73 # lock is the most likely to win it. 73 # lock is the most likely to win it.
74 74
75 # pylint: disable=broad-except
76 # we disable the broad-except because we want to actually catch all possible exceptions
75 try: 77 try:
76 lf = open(name, 'a+') 78 lock_file = open(name, 'a+')
77 fileno = lf.fileno() 79 fileno = lock_file.fileno()
78 fcntl.flock(fileno, op) 80 fcntl.flock(fileno, operation)
79 statinfo = os.fstat(fileno) 81 statinfo = os.fstat(fileno)
80 if os.path.exists(lf.name): 82 if os.path.exists(lock_file.name):
81 statinfo2 = os.stat(lf.name) 83 statinfo2 = os.stat(lock_file.name)
82 if statinfo.st_ino == statinfo2.st_ino: 84 if statinfo.st_ino == statinfo2.st_ino:
83 return lf 85 return lock_file
84 lf.close() 86 lock_file.close()
85 except Exception: 87 except Exception as exc:
86 try: 88 try:
87 lf.close() 89 lock_file.close()
88 except Exception: 90 except Exception as exc2:
89 pass 91 config.logger.error("Failed to close the lockfile: %s", exc2)
90 pass 92 config.logger.error("Failed to acquire the lockfile: %s", exc)
91 if not retry: 93 if not retry:
92 return None 94 return None
93 95
94def unlockfile(lf): 96def unlockfile(lock_file):
95 """ 97 """
96 Unlock a file locked using lockfile() 98 Unlock a file locked using lockfile()
97 """ 99 """
98 try: 100 try:
99 # If we had a shared lock, we need to promote to exclusive before 101 # If we had a shared lock, we need to promote to exclusive before
100 # removing the lockfile. Attempt this, ignore failures. 102 # removing the lockfile. Attempt this, ignore failures.
101 fcntl.flock(lf.fileno(), fcntl.LOCK_EX|fcntl.LOCK_NB) 103 fcntl.flock(lock_file.fileno(), fcntl.LOCK_EX|fcntl.LOCK_NB)
102 os.unlink(lf.name) 104 os.unlink(lock_file.name)
103 except (IOError, OSError): 105 except (IOError, OSError):
104 pass 106 pass
105 fcntl.flock(lf.fileno(), fcntl.LOCK_UN) 107 fcntl.flock(lock_file.fileno(), fcntl.LOCK_UN)
106 lf.close() 108 lock_file.close()
107 109
108#ENDOFCOPY 110#ENDOFCOPY
109 111
@@ -118,20 +120,20 @@ def mk_lock_filename():
118class ShellCmdException(Exception): 120class ShellCmdException(Exception):
119 pass 121 pass
120 122
121def run_shell_cmd(command, cwd = None): 123def run_shell_cmd(command, cwd=None):
122 if cwd is None: 124 if cwd is None:
123 cwd = os.getcwd() 125 cwd = os.getcwd()
124 126
125 config.logger.debug("_shellcmd: (%s) %s" % (cwd, command)) 127 config.logger.debug("_shellcmd: (%s) %s", cwd, command)
126 p = subprocess.Popen(command, cwd = cwd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) 128 process = subprocess.Popen(command, cwd=cwd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
127 (out,err) = p.communicate() 129 (out, err) = process.communicate()
128 p.wait() 130 process.wait()
129 if p.returncode: 131 if process.returncode:
130 if len(err) == 0: 132 if len(err) == 0:
131 err = "command: %s \n%s" % (command, out) 133 err = "command: %s \n%s" % (command, out)
132 else: 134 else:
133 err = "command: %s \n%s" % (command, err) 135 err = "command: %s \n%s" % (command, err)
134 config.logger.warn("_shellcmd: error \n%s\n%s" % (out, err)) 136 config.logger.warn("_shellcmd: error \n%s\n%s", out, err)
135 raise ShellCmdException(err) 137 raise ShellCmdException(err)
136 else: 138 else:
137 #config.logger.debug("localhostbecontroller: shellcmd success\n%s" % out) 139 #config.logger.debug("localhostbecontroller: shellcmd success\n%s" % out)