Python3 uses subprocess to execute shell commands and export docker images

 subprocess.run(cmd, stdout=subprocess.PIPE, encoding="utf8", shell=True, check=True).stdout

Document: https://www.runoob.com/w3cnote/python3-subprocess.html

from u_工具 import *
import subprocess
import platform

def is_linux_system():
    return 'linux' in platform.system().lower()

def is_windows_system():
    return 'windows' in platform.system().lower()


def shell(cmd, stdout=subprocess.PIPE, encoding="utf8", shell=True, check=True, **kwargs):
    return subprocess.run(cmd, stdout=stdout, encoding=encoding, shell=shell, check=check, **kwargs)\
                    .stdout


lines_str = shell("docker images | grep goharbor")
lines = stream(lines_str.split('\n')).filter(lambda i: i).collect()

for line in lines:
    name = line.split()[0]
    version = line.split()[1]
    print(f'''{name}:{version}''')
    # shell(f'''docker save {name}:{version} -o /a_soft/harbor/image/{name.split("/")[1]}:{version}.image''')

- u_tool: https://github.com/hl-mio/u_util/tree/main/python3

 

Guess you like

Origin blog.csdn.net/u013595395/article/details/114752900