test: fix pylint errors in u_boot_spawn.py
* don't inherit from object * imports should be on the top level * avoid unused variable names * avoid unnecessary else after raise Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com> Reviewed-by: Simon Glass <sjg@chromium.org>
This commit is contained in:
parent
09e409810a
commit
67e9b64701
@ -1,7 +1,9 @@
|
|||||||
# SPDX-License-Identifier: GPL-2.0
|
# SPDX-License-Identifier: GPL-2.0
|
||||||
# Copyright (c) 2015-2016, NVIDIA CORPORATION. All rights reserved.
|
# Copyright (c) 2015-2016, NVIDIA CORPORATION. All rights reserved.
|
||||||
|
|
||||||
# Logic to spawn a sub-process and interact with its stdio.
|
"""
|
||||||
|
Logic to spawn a sub-process and interact with its stdio.
|
||||||
|
"""
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
@ -9,12 +11,12 @@ import pty
|
|||||||
import signal
|
import signal
|
||||||
import select
|
import select
|
||||||
import time
|
import time
|
||||||
|
import traceback
|
||||||
|
|
||||||
class Timeout(Exception):
|
class Timeout(Exception):
|
||||||
"""An exception sub-class that indicates that a timeout occurred."""
|
"""An exception sub-class that indicates that a timeout occurred."""
|
||||||
pass
|
|
||||||
|
|
||||||
class Spawn(object):
|
class Spawn:
|
||||||
"""Represents the stdio of a freshly created sub-process. Commands may be
|
"""Represents the stdio of a freshly created sub-process. Commands may be
|
||||||
sent to the process, and responses waited for.
|
sent to the process, and responses waited for.
|
||||||
|
|
||||||
@ -58,14 +60,14 @@ class Spawn(object):
|
|||||||
os.execvp(args[0], args)
|
os.execvp(args[0], args)
|
||||||
except:
|
except:
|
||||||
print('CHILD EXECEPTION:')
|
print('CHILD EXECEPTION:')
|
||||||
import traceback
|
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
finally:
|
finally:
|
||||||
os._exit(255)
|
os._exit(255)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
self.poll = select.poll()
|
self.poll = select.poll()
|
||||||
self.poll.register(self.fd, select.POLLIN | select.POLLPRI | select.POLLERR | select.POLLHUP | select.POLLNVAL)
|
self.poll.register(self.fd, select.POLLIN | select.POLLPRI | select.POLLERR |
|
||||||
|
select.POLLHUP | select.POLLNVAL)
|
||||||
except:
|
except:
|
||||||
self.close()
|
self.close()
|
||||||
raise
|
raise
|
||||||
@ -106,7 +108,7 @@ class Spawn(object):
|
|||||||
elif os.WIFSIGNALED(status):
|
elif os.WIFSIGNALED(status):
|
||||||
signum = os.WTERMSIG(status)
|
signum = os.WTERMSIG(status)
|
||||||
self.exit_code = -signum
|
self.exit_code = -signum
|
||||||
self.exit_info = 'signal %d (%s)' % (signum, signal.Signals(signum))
|
self.exit_info = 'signal %d (%s)' % (signum, signal.Signals(signum).name)
|
||||||
self.waited = True
|
self.waited = True
|
||||||
return False, self.exit_code, self.exit_info
|
return False, self.exit_code, self.exit_info
|
||||||
|
|
||||||
@ -196,13 +198,11 @@ class Spawn(object):
|
|||||||
# shouldn't and explain why. This is much more friendly than
|
# shouldn't and explain why. This is much more friendly than
|
||||||
# just dying with an I/O error
|
# just dying with an I/O error
|
||||||
if err.errno == 5: # Input/output error
|
if err.errno == 5: # Input/output error
|
||||||
alive, exit_code, info = self.checkalive()
|
alive, _, info = self.checkalive()
|
||||||
if alive:
|
if alive:
|
||||||
raise
|
raise err
|
||||||
else:
|
raise ValueError('U-Boot exited with %s' % info)
|
||||||
raise ValueError('U-Boot exited with %s' % info)
|
raise err
|
||||||
else:
|
|
||||||
raise
|
|
||||||
if self.logfile_read:
|
if self.logfile_read:
|
||||||
self.logfile_read.write(c)
|
self.logfile_read.write(c)
|
||||||
self.buf += c
|
self.buf += c
|
||||||
@ -227,7 +227,7 @@ class Spawn(object):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
os.close(self.fd)
|
os.close(self.fd)
|
||||||
for i in range(100):
|
for _ in range(100):
|
||||||
if not self.isalive():
|
if not self.isalive():
|
||||||
break
|
break
|
||||||
time.sleep(0.1)
|
time.sleep(0.1)
|
||||||
|
Loading…
Reference in New Issue
Block a user