-
Notifications
You must be signed in to change notification settings - Fork 3
/
helper.py
45 lines (33 loc) · 1.16 KB
/
helper.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/usr/bin/python3
# -*- coding: utf-8
"""Helper functions for letscode."""
import subprocess
def print_info(*objs):
"""Prints INFO level messages"""
# print('INFO:', *objs, file=sys.stdout)
print('INFO: %s' % (objs))
def print_error(*objs):
"""Prints ERROR level messages"""
# print('ERROR:', *objs, file=sys.stderr)
print('ERROR: %s' % (objs))
def print_warning(*objs):
"""Prints WARNING level messages"""
# print('WARNING:', *objs, file=sys.stderr)
print('WARNING: %s' % (objs))
def print_debug(*objs):
"""Prints DEBUG level messages"""
print('DEBUG: %s' % (objs))
def subprocess_call_wrapper(lst, stdin=None):
"""Wrapper around the subprocess.call functions."""
print_debug('About to run "%s"' % ' '.join(lst))
try:
ret = subprocess.call(lst, stdin=stdin)
except (OSError, IOError):
ret = 127 # an error code
except IndexError:
ret = 127 # an error code
except KeyboardInterrupt:
ret = 127 # an error code
print_debug('Command "%s" returned %d' % (lst[0] if lst else '', ret))
return ret == 0
# vim: filetype=python tabstop=8 expandtab shiftwidth=4 softtabstop=4