Skip to content

Commit b00baf0

Browse files
committed
remote/client: Move initial-state code into a function
Put this code into a function to reduce the size of the _get_target() function. Signed-off-by: Simon Glass <sjg@chromium.org>
1 parent 5bd897f commit b00baf0

1 file changed

Lines changed: 10 additions & 7 deletions

File tree

labgrid/remote/client.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -875,6 +875,15 @@ def _prepare_manager(self):
875875
manager.session = self
876876
manager.loop = self.loop
877877

878+
def set_initial_state(self, target):
879+
if self.args.state:
880+
strategy = target.get_driver("Strategy")
881+
if self.args.initial_state:
882+
print(f"Setting initial state to {self.args.initial_state}")
883+
strategy.force(self.args.initial_state)
884+
logging.info("Transitioning into state %s", self.args.state)
885+
strategy.transition(self.args.state)
886+
878887
def _get_target(self, place):
879888
self._prepare_manager()
880889
target = None
@@ -885,13 +894,7 @@ def _get_target(self, place):
885894
print(f"Selected role {self.role} from configuration file")
886895
target = self.env.get_target(self.role)
887896
if target:
888-
if self.args.state:
889-
strategy = target.get_driver("Strategy")
890-
if self.args.initial_state:
891-
print(f"Setting initial state to {self.args.initial_state}")
892-
strategy.force(self.args.initial_state)
893-
logging.info("Transitioning into state %s", self.args.state)
894-
strategy.transition(self.args.state)
897+
self.set_initial_state(target)
895898
else:
896899
target = Target(place.name, env=self.env)
897900
RemotePlace(target, name=place.name)

0 commit comments

Comments
 (0)