1
0
mirror of https://github.com/ARM-software/devlib.git synced 2025-05-05 07:34:34 +01:00
Marc Bonnici 8aa9d672a1 devlib: Replace errors when decoding output from subprocess
If an error occurs when attempting to decode the output from subprocess
replace the offending character rather than raising an error.
2018-06-28 12:48:00 +01:00

16 lines
401 B
Python

import os
import sys
from subprocess import Popen, PIPE
def get_commit():
p = Popen(['git', 'rev-parse', 'HEAD'], cwd=os.path.dirname(__file__),
stdout=PIPE, stderr=PIPE)
std, _ = p.communicate()
p.wait()
if p.returncode:
return None
if sys.version_info[0] == 3:
return std[:8].decode(sys.stdout.encoding, 'replace')
else:
return std[:8]