Commit 43a2ae00 authored by Raphael Defosseux's avatar Raphael Defosseux

style(ci): using and debugging the new LocalCmd class

Signed-off-by: default avatarRaphael Defosseux <raphael.defosseux@eurecom.fr>
parent 6905159a
...@@ -74,32 +74,27 @@ class Cmd(metaclass=abc.ABCMeta): ...@@ -74,32 +74,27 @@ class Cmd(metaclass=abc.ABCMeta):
class LocalCmd(Cmd): class LocalCmd(Cmd):
def __init__(self, d = None): def __init__(self, d = None):
self.cwd = d self.cwd = d
if self.cwd is not None:
logging.debug(f'Working dir will be {self.cwd}')
self.cp = sp.CompletedProcess(args='', returncode=0, stdout='') self.cp = sp.CompletedProcess(args='', returncode=0, stdout='')
def run(self, line, timeout=300, silent=False, reportNonZero=True): def run(self, line, timeout=300, silent=False, reportNonZero=True):
if type(line) is str:
line = [s for s in line.split(' ') if len(s) > 0]
if not silent: if not silent:
logging.debug(' '.join(line)) logging.info(line)
try: try:
ret = sp.run(line, cwd=self.cwd, stdout=sp.PIPE, stderr=sp.STDOUT, timeout=timeout) ret = sp.run(line, shell=True, cwd=self.cwd, stdout=sp.PIPE, stderr=sp.STDOUT, timeout=timeout)
except Exception as e: except Exception as e:
ret = sp.CompletedProcess(args=line, returncode=255, stdout=f'Exception: {str(e)}'.encode('utf-8')) ret = sp.CompletedProcess(args=line, returncode=255, stdout=f'Exception: {str(e)}'.encode('utf-8'))
if ret.stdout is None: if ret.stdout is None:
ret.stdout = b'' ret.stdout = b''
ret.stdout = ret.stdout.decode('utf-8').strip() ret.stdout = ret.stdout.decode('utf-8').strip()
if reportNonZero and ret.returncode != 0: if reportNonZero and ret.returncode != 0:
cmd = ' '.join(ret.args) logging.warning(f'command "{ret.args}" returned non-zero returncode {ret.returncode}: output:\n{ret.stdout}')
logging.warning(f'command "{cmd}" returned non-zero returncode {ret.returncode}: output:\n{ret.stdout}')
self.cp = ret self.cp = ret
return ret return ret
def command(self, commandline, expectedline=None, timeout=300, silent=False, resync=False): def command(self, commandline, expectedline=None, timeout=300, silent=False, resync=False):
line = [s for s in commandline.split(' ') if len(s) > 0] self.run(commandline, timeout, silent)
if line[0] == 'cd':
self.cd(line[1], silent)
else:
self.run(line, timeout, silent)
return 0 return 0
def close(self): def close(self):
......
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment