diff --git a/tools/scons/SConstruct_tool.py b/tools/scons/SConstruct_tool.py index 07ffecf..7e76003 100644 --- a/tools/scons/SConstruct_tool.py +++ b/tools/scons/SConstruct_tool.py @@ -11,8 +11,7 @@ def append_srcs_dir(directories): import os from collections.abc import Iterable - # 支持的源码文件扩展名 - supported_extensions = ['.c', '.cc', '.cpp', '.S'] # 可根据需要添加其他扩展名 + supported_extensions = ['.c', '.cc', '.cpp', '.S'] # if isinstance(sfile, list): def _find_file(path): directory = str(path) @@ -67,8 +66,3 @@ def compare_and_copy(file1, file2): with open(file1, "rb") as f1, open(file2, "wb") as f2: f2.write(f1.read()) -# # 使用示例 -# file1_path = "path/to/your/first/file" # 第一个文件的路径 -# file2_path = "path/to/your/second/file" # 第二个文件的路径 - -# compare_and_copy(file1_path, file2_path) diff --git a/tools/scons/push.py b/tools/scons/push.py index 8135554..d67833b 100755 --- a/tools/scons/push.py +++ b/tools/scons/push.py @@ -1,43 +1,39 @@ #!/usr/bin/env python3 -import paramiko + import sys import os from pathlib import Path - +import paramiko +from scp import SCPClient +import sys def ssh_push_file(file_group, remote_host, remote_port, username, password): - # 创建SSH客户端实例 - ssh = paramiko.SSHClient() - - # 自动添加不在known_hosts文件的主机名和新的主机密钥 + ssh=paramiko.SSHClient() + ssh.load_system_host_keys() ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) - # 连接到远程服务器 if password != 'None': - ssh.connect(hostname=remote_host, port=remote_port, username=username, password=password, timeout=15) + ssh.connect(hostname=remote_host, port=remote_port, username=username, password=password, timeout=15, compress=True) else: - ssh.connect(hostname=remote_host, port=remote_port, username=username, timeout=15) - - # 使用SSH客户端的open_sftp方法打开SFTP会话 - sftp = ssh.open_sftp() - - # 将本地文件推送到远程服务器 + ssh.connect(hostname=remote_host, port=remote_port, username=username, timeout=15, compress=True) + + scpclient = SCPClient(ssh.get_transport(),socket_timeout=15.0) for local_file, remote_file in file_group: print("push", local_file, remote_file, '...') sys.stdout.flush() - sftp.put(local_file, remote_file) + # sftp.put(local_file, remote_file) + scpclient.put(local_file, remote_file) local_file_stat = os.stat(local_file) - mode = local_file_stat.st_mode - atime = local_file_stat.st_atime - mtime = local_file_stat.st_mtime - sftp.chmod(remote_file, mode) - sftp.utime(remote_file, (atime, mtime)) + # mode = local_file_stat.st_mode + # atime = local_file_stat.st_atime + # mtime = local_file_stat.st_mtime + # sftp.chmod(remote_file, mode) + # sftp.utime(remote_file, (atime, mtime)) sys.stdout.write("\033[A\033[K") print("push", local_file, remote_file, 'success!') sys.stdout.flush() - - # 关闭SFTP会话和SSH客户端 - sftp.close() - ssh.close() + + + if __name__ == '__main__': if len(sys.argv) < 6: