Commit 4db490de authored by Trevor Cappallo's avatar Trevor Cappallo
Browse files

cleanup subprocess output

parent 58ead554
......@@ -167,7 +167,7 @@ def long_log(logging_level=logging.INFO, message=''):
"""
message_list = message.split("\n")
for msg in message_list:
logging.log(logging_level, msg)
logging.log(logging_level, ' :: ' + msg)
def long_critical(message):
......@@ -219,19 +219,23 @@ def logged_sub(arg_list, logging_level=logging.INFO, **kwargs):
logging.info('Child process of [p{}]'.format(os.getppid()))
logging.info('Attempting {}'.format(' '.join(arg_list)))
try:
results = ''
#results = ''
proc = subprocess.Popen(arg_list, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, **kwargs)
for line in iter(proc.stdout.readline, b''):
print " ::", line.rstrip()
results += line
except Exception as err:
logging.error('Unknown exception resulting from {}:{}'.format(' '.join(arg_list), str(err)))
if not line:
break
logging.info(" :: " + line.rstrip())
#results += line
return_code = proc.wait()
if return_code:
logging.warning('{} failed with exit code {}'.format(' '.join(arg_list), return_code))
return return_code
except OSError as err:
logging.error('Error resulting from {}:{}'.format(' '.join(arg_list), str(err)))
else:
#long_info(results)
logging.info('Successfully completed {}'.format(' '.join(arg_list)))
long_info(results)
return 0
logging.warning('Failure on {}'.format(' '.join(arg_list)))
return -1
def stack_trace(logging_level=logging.ERROR):
"""Log a stack trace at the given level."""
......@@ -257,6 +261,7 @@ if __name__ == '__main__':
#long_error(test)
logging.error(test)
c = ['find', '.', '-name', '*.py']
c = ['diff', 'a', 'b']
logged_subprocess(c)
logged_sub(c)
try:
......
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