diff options
Diffstat (limited to 'extra/tigertool/ecusb/tiny_servo_common.py')
-rw-r--r-- | extra/tigertool/ecusb/tiny_servo_common.py | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/extra/tigertool/ecusb/tiny_servo_common.py b/extra/tigertool/ecusb/tiny_servo_common.py index 0e650a2d1d..dbbe42fea8 100644 --- a/extra/tigertool/ecusb/tiny_servo_common.py +++ b/extra/tigertool/ecusb/tiny_servo_common.py @@ -4,6 +4,8 @@ """Utilities for using lightweight console functions.""" +# Note: This is a py2/3 compatible file. + import datetime import errno import os @@ -12,10 +14,18 @@ import subprocess import sys import time +import six + from . import pty_driver from . import stm32uart +def get_subprocess_args(): + if six.PY3: + return {'encoding': 'utf-8'} + return {} + + class TinyServoError(Exception): """Exceptions.""" @@ -41,7 +51,7 @@ def check_usb(vidpid, serialname=None): """ if serialname: output = subprocess.check_output(['lsusb', '-v', '-d', vidpid], - encoding='utf-8') + **get_subprocess_args()) m = re.search(r'^\s*iSerial\s+\d+\s+%s$' % serialname, output, flags=re.M) if m: return True @@ -65,7 +75,7 @@ def check_usb_sn(vidpid): Returns: string serial number if found, None otherwise. """ output = subprocess.check_output(['lsusb', '-v', '-d', vidpid], - encoding='utf-8') + **get_subprocess_args()) m = re.search(r'^\s*iSerial\s+(.*)$', output, flags=re.M) if m: return m.group(1) |