# 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]classIslink:""" A class to encapsulate the functionality of checking if a path refers to a symbolic link using SFTP islink in Unix-like operating systems. Attributes: path: The remote path to check (can be PurePath, str, or bytes). **Examples:** .. code:: python yield Islink(path="/path/to/symlink") Usage: This class is designed to be used in a generator-based workflow where commands are yielded for execution. The boolean result for each host will be returned in the operation result. Notes: The operation will execute on all hosts in the current execution context. The path must be a valid remote path accessible via SFTP. """def__init__(self,path=None):self.path=pathdef__repr__(self):returnf"Islink(path={self.path!r})"@staticmethodasyncdef_islink_callback(host_info,global_info,command,cp,caller):"""Static callback method for checking if a path is a symbolic link"""asyncwithasyncssh.connect(**host_info)asconn:asyncwithconn.start_sftp_client()assftp:# Check if the path refers to a symbolic linkifcaller.path:is_link=awaitsftp.islink(caller.path)returnis_linkelse:raiseValueError("Path must be provided for islink operation")defexecute(self):r=yieldCommand(f"{self}",local=True,callback=self._islink_callback,caller=self)r.executed=Truer.changed=Falsereturnr