Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remote/client: consider acquired places on search #1608

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 14 additions & 5 deletions labgrid/remote/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -456,13 +456,24 @@ def _check_allowed(self, place):
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"
)

def get_place(self, place=None):
pattern = place or self.args.place
def get_place(self, place=None, only_acquired: bool = False):
pattern = place or self.args.place or ("" if only_acquired else None)
if pattern is None:
raise UserError("place pattern not specified")
places = self._match_places(pattern)
if not places:
raise UserError(f"place pattern {pattern} matches nothing")
if only_acquired:
acquired_places = []
for name in places:
try:
self._check_allowed(self.places[name])
acquired_places.append(name)
except UserError: # treat _check_allowed as an if condition, no need to raise error
pass # nosec try_except_pass
if not acquired_places:
raise UserError(f"place pattern {pattern} matches no acquired place")
places = acquired_places
if pattern in places:
return self.places[pattern]
if len(places) > 1:
Expand All @@ -479,9 +490,7 @@ def get_idle_place(self, place=None):
return place

def get_acquired_place(self, place=None):
place = self.get_place(place)
self._check_allowed(place)
return place
return self.get_place(place, only_acquired=True)

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