Skip to content

Commit 0725b33

Browse files
committed
Added exception handling for prettytable and serial modules - gracefuly handle missing imports.
1 parent 41a7dad commit 0725b33

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

workspace_tools/host_tests/host_test.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,14 @@
1515
limitations under the License.
1616
"""
1717

18+
# Check if 'serial' module is installed
19+
try:
20+
from serial import Serial
21+
except ImportError, e:
22+
print "Error: Can't import 'serial' module: %s"% e
23+
exit(-1)
24+
1825
from optparse import OptionParser
19-
from serial import Serial
2026
from time import sleep
2127
from sys import stdout
2228

workspace_tools/singletest.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,14 +70,27 @@
7070
7171
"""
7272

73+
# Check if 'prettytable' module is installed
74+
try:
75+
from prettytable import PrettyTable
76+
except ImportError, e:
77+
print "Error: Can't import 'prettytable' module: %s"% e
78+
exit(-1)
79+
80+
# Check if 'serial' module is installed
81+
try:
82+
from serial import Serial
83+
except ImportError, e:
84+
print "Error: Can't import 'serial' module: %s"% e
85+
exit(-1)
86+
7387
import sys
7488
import json
7589
import optparse
7690
import pprint
7791
import re
7892
import os
7993
from types import ListType
80-
from prettytable import PrettyTable
8194

8295
from os.path import join, abspath, dirname, exists, basename
8396
from shutil import copy

0 commit comments

Comments
 (0)