INNER CODE UNIT · Python

_is_remote_file_exists

codematrixer/hmdriver2 · hmdriver2/_client.py:213

    def _is_remote_file_exists(self, file_path: str) -> bool:
        """Check if a file exists on the device."""
        command = f"[ -f {file_path} ] && echo 'exists' || echo 'not exists'"
        result = self.hdc.shell(command).output.strip()
        return "exists" in result

    def _setup_device_agent(self, local_path: str, remote_path: str):
        """Ensure the remote agent file is correctly set up."""
        if self._is_remote_file_exists(remote_path):
            local_md5 = self._get_local_md5sum(local_path)
            remote_md5 = self._get_remote_md5sum(remote_path)
            if local_md5 == remote_md5:
                logger.debug("Remote agent file is up-to-date")
                self.hdc.shell(f"chmod +x {remote_path}")
                return
            self.hdc.shell(f"rm {remote_path}")

        self.hdc.send_file(local_path, remote_path)

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…