Skip to content

Commit 0f48aba

Browse files
committed
Split part of get_client into get_client_class
get_client_class gets the callable class for the given client name
1 parent d0f12f5 commit 0f48aba

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

hwilib/commands.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,29 @@
1111
from .descriptor import Descriptor
1212
from .devices import __all__ as all_devs
1313

14-
# Get the client for the device
15-
def get_client(device_type, device_path, password='', expert=False):
14+
def get_client_class(device_type):
1615
device_type = device_type.split('_')[0]
1716
class_name = device_type.capitalize()
1817
module = device_type.lower()
1918

20-
client = None
2119
try:
2220
imported_dev = importlib.import_module('.devices.' + module, __package__)
2321
client_constructor = getattr(imported_dev, class_name + 'Client')
24-
client = client_constructor(device_path, password, expert)
2522
except ImportError:
23+
raise UnknownDeviceError('Unknown device type specified')
24+
25+
return client_constructor
26+
27+
# Get the client for the device
28+
def get_client(device_type, device_path, password='', expert=False):
29+
client = None
30+
try:
31+
client_constructor = get_client_class(device_type)
32+
client = client_constructor(device_path, password, expert)
33+
except:
2634
if client:
2735
client.close()
28-
raise UnknownDeviceError('Unknown device type specified')
36+
raise
2937

3038
return client
3139

0 commit comments

Comments
 (0)