Skip to content

Commit b49d93f

Browse files
committed
remote/client: consider acquired places on search
When requesting an acquired place, match the pattern only to the acquired places and not to every place. This also allows to skip the place on the commandline if only one place is acquired by the current user.
1 parent e8aadae commit b49d93f

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

labgrid/remote/client.py

+14-5
Original file line numberDiff line numberDiff line change
@@ -456,13 +456,24 @@ def _check_allowed(self, place):
456456
f"place {place.name} is not acquired on this computer, acquired on {host}. To allow this host, use labgrid-client -p {place.name} allow {self.gethostname()}/{self.getuser()} on the other host"
457457
)
458458

459-
def get_place(self, place=None):
460-
pattern = place or self.args.place
459+
def get_place(self, place=None, only_acquired: bool = False):
460+
pattern = place or self.args.place or ("" if only_acquired else None)
461461
if pattern is None:
462462
raise UserError("place pattern not specified")
463463
places = self._match_places(pattern)
464464
if not places:
465465
raise UserError(f"place pattern {pattern} matches nothing")
466+
if only_acquired:
467+
acquired_places = []
468+
for name in places:
469+
try:
470+
self._check_allowed(self.places[name])
471+
acquired_places.append(name)
472+
except UserError: # treat _check_allowed as an if condition, no need to raise error
473+
pass # nosec try_except_pass
474+
if not acquired_places:
475+
raise UserError(f"place pattern {pattern} matches no acquired place")
476+
places = acquired_places
466477
if pattern in places:
467478
return self.places[pattern]
468479
if len(places) > 1:
@@ -479,9 +490,7 @@ def get_idle_place(self, place=None):
479490
return place
480491

481492
def get_acquired_place(self, place=None):
482-
place = self.get_place(place)
483-
self._check_allowed(place)
484-
return place
493+
return self.get_place(place, only_acquired=True)
485494

486495
async def print_place(self):
487496
"""Print out the current place and related resources"""

0 commit comments

Comments
 (0)