From 96ae824ecd6fc9eb31087f6cdcabb025cb3f84e8 Mon Sep 17 00:00:00 2001 From: Yinan Qin <39023210+elysia-best@users.noreply.github.com> Date: Thu, 12 Sep 2024 16:23:26 +0800 Subject: [PATCH] fix: Change from f-string to format() (#81) Fix: https://fishros.org.cn/forum/topic/3008/%E4%B8%80%E9%94%AE%E5%AE%89%E8%A3%85%E5%B4%A9%E6%BA%83 --- tools/tool_config_docker_proxy.py | 14 +++++++------- tools/tool_config_system_source.py | 2 +- tools/tool_install_backup_system.py | 4 ++-- tools/tool_install_ros_with_docker.py | 2 +- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/tools/tool_config_docker_proxy.py b/tools/tool_config_docker_proxy.py index 496b1b5..e619516 100644 --- a/tools/tool_config_docker_proxy.py +++ b/tools/tool_config_docker_proxy.py @@ -24,12 +24,12 @@ def config_docker_proxy(self): if not url: url = '127.0.0.1' port = input('请输入代理所在端口:') - proxy_config_vpn = f"""[Service] -Environment="HTTP_PROXY=http://{url}:{port}/" -Environment="HTTPS_PROXY=http://{url}:{port}/" -Environment="NO_PROXY=localhost,127.0.0.1,{url},.example.com""" + proxy_config_vpn = """[Service] +Environment="HTTP_PROXY=http://{}:{}/" +Environment="HTTPS_PROXY=http://{}:{}/" +Environment="NO_PROXY=localhost,127.0.0.1,{},.example.com""".format(url, port, url, port, url) FileUtils.new('/etc/systemd/system/docker.service.d/','proxy.conf',proxy_config_vpn) - PrintUtils.print_info(f"在{'/etc/systemd/system/docker.service.d'}/{'proxy.conf'}写入了{proxy_config_vpn},接下来为你重启Docker!") + PrintUtils.print_info("在{}/{}写入了{},接下来为你重启Docker!".format('/etc/systemd/system/docker.service.d', 'proxy.conf', proxy_config_vpn)) CmdTask("sudo systemctl daemon-reload").run() CmdTask("sudo systemctl restart docker").run() elif code==2: @@ -39,9 +39,9 @@ def config_docker_proxy(self): code,result = ChooseTask(dic, "请选择代理加速网址").run() url = dic[code] print(url) - proxy_config_vpn = f'{{"registry-mirrors": ["{url}"]}}' + proxy_config_vpn = '{{"registry-mirrors": ["{}"]}}'.format(url) FileUtils.new('/etc/docker/','daemon.json',proxy_config_vpn) - PrintUtils.print_info(f"在{'/etc/docker/'}/{'daemon.json'}写入了{proxy_config_vpn},接下来为你重启Docker!") + PrintUtils.print_info("在{}/{}写入了{},接下来为你重启Docker!".format('/etc/docker/', 'daemon.json', proxy_config_vpn)) CmdTask("sudo systemctl daemon-reload").run() CmdTask("sudo systemctl restart docker").run() elif code==3: diff --git a/tools/tool_config_system_source.py b/tools/tool_config_system_source.py index 4ed22d3..df5ae4d 100644 --- a/tools/tool_config_system_source.py +++ b/tools/tool_config_system_source.py @@ -147,7 +147,7 @@ def get_source_by_system(self,system,codename,arch,failed_sources=[]): PrintUtils.print_warn('接下来为您排除已经失败的源') for source in fast_source: if source in failed_sources: - PrintUtils.print_info(f'{source} 已经测试失败,跳过!') + PrintUtils.print_info('{} 已经测试失败,跳过!'.format(source)) else: return source,template else: diff --git a/tools/tool_install_backup_system.py b/tools/tool_install_backup_system.py index 81227f7..dc2610f 100644 --- a/tools/tool_install_backup_system.py +++ b/tools/tool_install_backup_system.py @@ -19,9 +19,9 @@ def install_nodejs(self): disk_origin = '/dev/sda' save_disk = input('请输入你要存放的文件磁盘(如:/dev/sdb2):') file_name = input('请输入文件名guidebot_240802:') - CmdTask(f"mkdir -p /tmp/save_disk && mount {save_disk} /tmp/save_disk").run() + CmdTask("mkdir -p /tmp/save_disk && mount {} /tmp/save_disk".format(save_disk)).run() PrintUtils.print_info("查看进度: watch -n 1 pkill -USR1 -x dd") - command = f'cd /tmp/save_disk && dd if={disk_origin} | gzip > {file_name}.gz' + command = 'cd /tmp/save_disk && dd if={} | gzip > {}.gz'.format(disk_origin, file_name) CmdTask(command).run() else: diff --git a/tools/tool_install_ros_with_docker.py b/tools/tool_install_ros_with_docker.py index 31b74e8..b9bf0a9 100644 --- a/tools/tool_install_ros_with_docker.py +++ b/tools/tool_install_ros_with_docker.py @@ -84,7 +84,7 @@ def get_vesion_list(): """获取可安装的ROS版本列表""" names = [] for version in RosVersions.ros_version: - names.append(f'{version.name} ({version.version})') + names.append('{} ({})'.format(version.name, version.version)) return names