Skip to content

Commit bb72bc0

Browse files
sbngrosssgross-emlix
authored andcommitted
remote/client: cleanup InteractiveCommandError
When handling InteractiveCommandError there is an implicit assumption that it has a field `exitcode`. This assumption holds since in all places it is raised there is the same repeated code block. Make this assumption more explicit by providing a proper constructor to InteractiveCommandError class. Signed-off-by: Sebastian Gross <[email protected]>
1 parent f63dfd7 commit bb72bc0

File tree

1 file changed

+10
-22
lines changed

1 file changed

+10
-22
lines changed

labgrid/remote/client.py

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,9 @@ class ServerError(Error):
6969

7070

7171
class InteractiveCommandError(Error):
72-
pass
72+
def __init__(self: Error, msg: str, exitcode: int):
73+
super(InteractiveCommandError, self).__init__(msg)
74+
self.exitcode = exitcode
7375

7476

7577
@attr.s(eq=False)
@@ -1049,9 +1051,7 @@ async def console(self, place, target):
10491051
break
10501052
if not self.args.loop:
10511053
if res:
1052-
exc = InteractiveCommandError("microcom error")
1053-
exc.exitcode = res
1054-
raise exc
1054+
raise InteractiveCommandError("microcom error", res)
10551055
break
10561056
await asyncio.sleep(1.0)
10571057

@@ -1251,27 +1251,21 @@ def ssh(self):
12511251

12521252
res = drv.interact(self.args.leftover)
12531253
if res:
1254-
exc = InteractiveCommandError("ssh error")
1255-
exc.exitcode = res
1256-
raise exc
1254+
raise InteractiveCommandError("ssh error", res)
12571255

12581256
def scp(self):
12591257
drv = self._get_ssh()
12601258

12611259
res = drv.scp(src=self.args.src, dst=self.args.dst)
12621260
if res:
1263-
exc = InteractiveCommandError("scp error")
1264-
exc.exitcode = res
1265-
raise exc
1261+
raise InteractiveCommandError("scp error", res)
12661262

12671263
def rsync(self):
12681264
drv = self._get_ssh()
12691265

12701266
res = drv.rsync(src=self.args.src, dst=self.args.dst, extra=self.args.leftover)
12711267
if res:
1272-
exc = InteractiveCommandError("rsync error")
1273-
exc.exitcode = res
1274-
raise exc
1268+
raise InteractiveCommandError("rsync error", res)
12751269

12761270
def sshfs(self):
12771271
drv = self._get_ssh()
@@ -1309,9 +1303,7 @@ def telnet(self):
13091303
args = ["telnet", str(ip)]
13101304
res = subprocess.call(args)
13111305
if res:
1312-
exc = InteractiveCommandError("telnet error")
1313-
exc.exitcode = res
1314-
raise exc
1306+
raise InteractiveCommandError("telnet error", res)
13151307

13161308
def video(self):
13171309
place = self.get_acquired_place()
@@ -1347,9 +1339,7 @@ def video(self):
13471339
else:
13481340
res = drv.stream(quality, controls=controls)
13491341
if res:
1350-
exc = InteractiveCommandError("gst-launch-1.0 error")
1351-
exc.exitcode = res
1352-
raise exc
1342+
raise InteractiveCommandError("gst-launch-1.0 error", res)
13531343

13541344
def audio(self):
13551345
place = self.get_acquired_place()
@@ -1358,9 +1348,7 @@ def audio(self):
13581348
drv = self._get_driver_or_new(target, "USBAudioInputDriver", name=name)
13591349
res = drv.play()
13601350
if res:
1361-
exc = InteractiveCommandError("gst-launch-1.0 error")
1362-
exc.exitcode = res
1363-
raise exc
1351+
raise InteractiveCommandError("gst-launch-1.0 error", res)
13641352

13651353
def _get_tmc(self):
13661354
place = self.get_acquired_place()

0 commit comments

Comments
 (0)