Finally fix and finish docker_info()
This commit is contained in:
parent
49f1ca76d2
commit
4adebb0adc
1 changed files with 17 additions and 22 deletions
|
@ -11,36 +11,31 @@ def docker_info():
|
||||||
raw_info = getoutput('docker ps')
|
raw_info = getoutput('docker ps')
|
||||||
# Header: "CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES" (with way more spaces)
|
# Header: "CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES" (with way more spaces)
|
||||||
header = raw_info[:raw_info.find('\n')+1]
|
header = raw_info[:raw_info.find('\n')+1]
|
||||||
header_temp = header
|
header_indices = {'CONTAINER ID': header.find('CONTAINER ID'), 'IMAGE': header.find('IMAGE'), 'COMMAND': header.find('COMMAND'), \
|
||||||
header_indices = {}
|
'CREATED': header.find('CREATED'), \
|
||||||
while ' ' in header_temp: # Split header
|
'STATUS': header.find('STATUS'), 'PORTS': header.find('PORTS'), 'NAMES': header.find('NAMES')}
|
||||||
temp = header_temp[header_temp.rfind(' ')+2:].strip()
|
|
||||||
header_indices[temp] = header.find(temp)
|
|
||||||
header_temp = header_temp[:header_temp.rfind(' ')].strip()
|
|
||||||
header_indices[header[:header.find(' ')]] = 0
|
|
||||||
|
|
||||||
raw_info = raw_info[raw_info.find('\n')+1:] # Remove header (example above)
|
# Remove header (example above)
|
||||||
|
raw_info = raw_info[raw_info.find('\n')+1:]
|
||||||
info = {}
|
info = {}
|
||||||
|
|
||||||
# Find container names
|
# Find container names
|
||||||
containers = []
|
containers = []
|
||||||
for line in raw_info:
|
for line in raw_info.split('\n'):
|
||||||
containers.append(line.strip()[line.strip().rfind(' ')+1:])
|
containers.append(line.strip()[line.strip().rfind(' ')+1:])
|
||||||
|
|
||||||
# Fill in info
|
# Fill in info
|
||||||
for i in range(len(containers)):
|
for i in range(len(containers)):
|
||||||
info[containers[i]] = {}
|
info[containers[i]] = {}
|
||||||
for column in header_indices:
|
header_indices_keys = list(header_indices)
|
||||||
end_i = header_indices[column] + len(column)
|
for j in range(len(header_indices_keys)): # TODO: Fix
|
||||||
info[containers[i]][column] = raw_info[i][header_indices[column]:end_i]
|
start_i = header_indices[header_indices_keys[j]]
|
||||||
|
if j+1 != len(header_indices):
|
||||||
debug = True
|
end_i = header_indices[header_indices_keys[j+1]]
|
||||||
if debug:
|
else:
|
||||||
print('Raw info:\n', raw_info, '\n')
|
end_i = len(header)
|
||||||
print('Header:\n', header, '\n')
|
info[containers[i]][header_indices[header_indices_keys[j]]] = \
|
||||||
print('Header indices:\n', header_indices, '\n')
|
raw_info.split('\n')[i][start_i:end_i].strip()
|
||||||
print('Containers:\n', containers, '\n')
|
|
||||||
print('Info:\n', info, '\n')
|
|
||||||
|
|
||||||
return info
|
return info
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue