From b4dcdbc905d9b65c7212d82f70ab78e5954fa5dc Mon Sep 17 00:00:00 2001 From: --global <--global> Date: Thu, 15 Dec 2022 09:25:06 -0600 Subject: [PATCH] Fix some stuff --- basic_management.py | 9 +++------ docker_parser.py | 6 +++--- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/basic_management.py b/basic_management.py index efcf6d6..298ea49 100644 --- a/basic_management.py +++ b/basic_management.py @@ -1,9 +1,6 @@ from subprocess import getoutput +import docker_parser +import pprint # Goals: Loop: Select container (or exit), then menu to do stuff to container (start, stop, rm, list info, go back to main menu) - - -if '\n' not in getoutput('docker ps'): - print('No containers running') - exit() -ps() +pprint.pprint(docker_parser.DockerParser.ps()) diff --git a/docker_parser.py b/docker_parser.py index 9eebc1b..469b06c 100644 --- a/docker_parser.py +++ b/docker_parser.py @@ -5,7 +5,7 @@ class NoContainersError(Exception): pass class DockerParser: - def ps(raw_info='docker ps'): + def ps(raw_info=getoutput('docker ps')): """ Gets info about all running Docker containers from docker ps :return: Nested dict of containers info @@ -38,7 +38,7 @@ class DockerParser: end_i = header_indices[header_indices_keys[j+1]] else: end_i = len(header) - info[containers[i]][header_indices[header_indices_keys[j]]] = \ + info[containers[i]][header_indices_keys[j]] = \ raw_info.split('\n')[i][start_i:end_i].strip() return info @@ -50,7 +50,7 @@ class DockerParser: """ if '\n' not in raw_info: raise(NoContainersError('A Docker container is required to run this program. Please create a docker container and try again.')) - raw_info = getoutput('docker ps') + raw_info = getoutput('docker container list') # Header: "CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES" (with way more spaces) header = raw_info[:raw_info.find('\n')+1] header_temp = header