# Copyright (c) 2025 Kim Jarvis TPF Software Services S.A. kim.jarvis@tpfsystems.com # This software is licensed under the MIT License. See the LICENSE file for details.#importasyncsshfromreemote.commandimportCommand
[docs]classGet_cwd:""" A class to encapsulate the functionality of cwd (get current working directory) in Unix-like operating systems. **Examples:** .. code:: python yield Getcwd() Usage: This class is designed to be used in a generator-based workflow where commands are yielded for execution. The current working directory for each host will be returned in the operation result. Notes: The operation will execute on all hosts in the current execution context. """def__init__(self):passdef__repr__(self):returnf"Getcwd()"@staticmethodasyncdef_getcwd_callback(host_info,global_info,command,cp,caller):"""Static callback method for getting current working directory"""asyncwithasyncssh.connect(**host_info)asconn:asyncwithconn.start_sftp_client()assftp:# Get the current remote working directorycwd=awaitsftp.getcwd()returncwddefexecute(self):r=yieldCommand(f"{self}",local=True,callback=self._getcwd_callback,caller=self)r.executed=Truer.changed=Falsereturnr