From 27891e36f6c3e3b33204c5bdc22bd4d7e40c36ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=98=B3=E5=85=89=E5=B0=91=E5=B9=B4?= <849317537@qq.com> Date: Mon, 12 Aug 2024 03:40:14 +0000 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D--log=E5=AF=BC=E8=87=B4?= =?UTF-8?q?=E7=BD=91=E7=BB=9C=E8=AE=BE=E5=A4=87=E8=A2=AB=E5=88=A0=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main.rs | 7 ++++--- test.env | 6 ++++++ test/test.py | 17 +++++++++++------ 3 files changed, 21 insertions(+), 9 deletions(-) create mode 100644 test.env diff --git a/src/main.rs b/src/main.rs index dc86dc1..2eabf7c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,3 +1,4 @@ +use std::os::unix::fs::OpenOptionsExt; use std::{io, fs, fmt, os, path, process, time}; use fmt::Display; use os::fd::{AsFd, AsRawFd}; @@ -498,7 +499,8 @@ impl Display for ContainerInfo { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { let volume: String = self.volume.chars().take(20).collect(); let env: String = self.env.chars().take(20).collect(); - write!(f, "\x1b[4m{:<10} {:<8} {:<10} {:<20} {:<20} {:<20} {:<10}\x1b[24m", self.id, self.pid, self.image, self.run, volume, env, &self.status) + let run: String = self.run.chars().take(20).collect(); + write!(f, "\x1b[4m{:<10} {:<8} {:<10} {:<20} {:<20} {:<20} {:<10}\x1b[24m", self.id, self.pid, self.image, run, volume, env, &self.status) } } @@ -572,7 +574,6 @@ fn stop_container(containers_id: &str, is_remove: bool) -> Result<()> { for container_info in get_all_container_info()?{ stop_container(container_info.id.as_str(), is_remove)? } - // return Ok(()) } for container_id in containers_id.split(" ") { @@ -671,10 +672,10 @@ fn main() -> Result<()>{ Ok(_) => { if container_info.wait { println!("🟢 容器 {} 运行完毕", container_info.id); + remove_network(&container_info.id); } else { println!("🟢 主进程退出"); } - remove_network(&container_info.id); } Err(e) => { // clone 之后的错误 这里已经无法捕获了 diff --git a/test.env b/test.env new file mode 100644 index 0000000..2f3f8dd --- /dev/null +++ b/test.env @@ -0,0 +1,6 @@ +SHLVL=1 +PS1=(python_env) \u\h:\W\$ +PATH=/python_env/bin:/sbin:/usr/sbin:/bin:/usr/bin +VIRTUAL_ENV_PROMPT=(python_env) +VIRTUAL_ENV=/python_env +PWD=/ diff --git a/test/test.py b/test/test.py index 310ac0f..117fb71 100644 --- a/test/test.py +++ b/test/test.py @@ -4,11 +4,16 @@ import time while True: - now = datetime.now().strftime("%Y-%m-%d %H:%M:%S") - request = urllib.request.Request("http://www.baidu.com") - with urllib.request.urlopen(request) as response: - data = response.read() - content = data.decode("utf-8") - print(f"{now} {len(content)}") time.sleep(1) + now = datetime.now().strftime("%Y-%m-%d %H:%M:%S") + print(now) + # try: + # request = urllib.request.Request("http://www.baidu.com") + # with urllib.request.urlopen(request) as response: + # data = response.read() + # content = data.decode("utf-8") + # print(f"{len(content)}") + # except Exception as e: + # print(e) +