Skip to content

Commit 884a31c

Browse files
committed
remote/client: Split _check_allowed() into two methods
It is useful to be able to see if a place is allowed without raising an error and needing a try...except block. Add a function to handle this and update _check_allowed() to use it. This will be used by the updated terminal suport. Signed-off-by: Simon Glass <sjg@chromium.org>
1 parent e45780b commit 884a31c

1 file changed

Lines changed: 17 additions & 8 deletions

File tree

labgrid/remote/client.py

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -468,19 +468,28 @@ def _match_places(self, pattern):
468468
result.add(name)
469469
return list(result)
470470

471-
def _check_allowed(self, place):
471+
def is_allowed(self, place):
472+
"""Check if a place is acquired
473+
474+
Args:
475+
place (str): Place name to check
476+
477+
Returns:
478+
str: None if acquired, else error message
479+
"""
472480
if not place.acquired:
473-
raise UserError(f"place {place.name} is not acquired")
481+
return f"place {place.name} is not acquired"
474482
if f"{self.gethostname()}/{self.getuser()}" not in place.allowed:
475483
host, user = place.acquired.split("/")
476484
if user != self.getuser():
477-
raise UserError(
478-
f"place {place.name} is not acquired by your user, acquired by {user}. To work simultaneously, {user} can execute labgrid-client -p {place.name} allow {self.gethostname()}/{self.getuser()}"
479-
)
485+
return f"place {place.name} is not acquired by your user, acquired by {user}. To work simultaneously, {user} can execute labgrid-client -p {place.name} allow {self.gethostname()}/{self.getuser()}"
480486
if host != self.gethostname():
481-
raise UserError(
482-
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"
483-
)
487+
return 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"
488+
489+
def _check_allowed(self, place):
490+
err = self.is_allowed(place)
491+
if err:
492+
raise UserError(err)
484493

485494
def get_place(self, place=None):
486495
pattern = place or self.args.place

0 commit comments

Comments
 (0)