def call_raw(command, **kwds): cmd = String.split_safe(command) try: return subprocess.check_output(cmd, **kwds) except subprocess.CalledProcessError as e: raise ValueError('Couldn\'t execute "%s", errorcode=%s' % ' '.join(cmd), e.returncode)
def call_value(command, print=print, **kwds): cmd = String.split_safe(command) try: return 0, subprocess.check_output(cmd, **kwds) except subprocess.CalledProcessError as e: if print: print('ERROR2:' ' command =', ' '.join(cmd), ' code =', e.returncode) e.output and print(e.output) return e.returncode, ''
def call(command, callback=None, print=print, **kwds): cmd = String.split_safe(command) returncode = 0 error = '' if callback: try: callback(subprocess.check_output(cmd, **kwds)) except subprocess.CalledProcessError as e: returncode = e.returncode error = e.output else: returncode = subprocess.call(cmd, **kwds) if returncode and print: print('ERROR:' ' command =', ' '.join(cmd), ' code =', returncode) error and print(error) return returncode
def for_each(commands, before=None, after=None, **kwds): for command in filter(None, String.split_safe(commands, 'splitlines')): before and before(command) if call(command, **kwds): after and after(command)