-
Notifications
You must be signed in to change notification settings - Fork 0
/
Docker.py
95 lines (73 loc) · 2.97 KB
/
Docker.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
import subprocess, os
import docker
from PySide6 import QtCore
from PySide6.QtWidgets import (
QVBoxLayout,
QLabel,
QWidget,
QGridLayout,
QPushButton
)
from setup_logger import logging
class Docker:
def __init__(self):
super().__init__()
def start_ros(self):
logging.info("Starting ROS (maybe)...")
print("Starting ROS (maybe)...")
def getADEVersion(self) -> str:
path = '/usr/local/bin/ade'
if os.path.isfile(path):
ade_version = subprocess.run([path, '--version'], stdout=subprocess.PIPE).stdout.decode("utf-8")
else:
return "ADE not found"
logging.info("ADE version: {version}".format(version=ade_version))
return ade_version
class DockerTab(QWidget):
def __init__(self, parent: QWidget):
super().__init__(parent)
self.client = docker.DockerClient(base_url='unix://var/run/docker.sock')
app = self.parent().app
self.disp_width = app.primaryScreen().size().width()
self.disp_height = app.primaryScreen().size().height()
btn_size = self.disp_width/5
Gridlayout = QGridLayout()
button_start_ros = QPushButton("Start ROS")
button_start_ros.clicked.connect(Docker.start_ros)
button_start_ros.setFixedSize(btn_size, btn_size)
layout = QVBoxLayout()
layout.setAlignment(QtCore.Qt.AlignCenter)
ade_version = QLabel("ADE Version: {version}".format(version=Docker.getADEVersion(self)))
ade_version.setAlignment(QtCore.Qt.AlignCenter)
version = QLabel("Docker Version: {version}".format(version=self.getDockerVersion()))
version.setAlignment(QtCore.Qt.AlignCenter)
layout.addWidget(ade_version)
layout.addWidget(version)
layout.addWidget(self.getDockerImages())
Gridlayout.addWidget(button_start_ros, 0, 0)
Gridlayout.addLayout(layout, 0, 1)
self.setLayout(Gridlayout)
def getDockerImages(self):
widget = QWidget()
layout = QGridLayout()
list = self.client.images.list()
label = QLabel("Index")
label.setAlignment(QtCore.Qt.AlignRight)
layout.addWidget(label, 0, 0)
label = QLabel("Image Tag")
label.setAlignment(QtCore.Qt.AlignLeft)
layout.addWidget(label, 0, 1)
for index, image in enumerate(list):
if(len(image.tags)) > 0:
label = QLabel("{image}".format(image=image.tags[0]))
label.setAlignment(QtCore.Qt.AlignLeft)
indexLabel = QLabel(str(index))
indexLabel.setAlignment(QtCore.Qt.AlignRight)
layout.addWidget(indexLabel, index+1, 0)
layout.addWidget(label, index+1, 1)
widget.setLayout(layout)
return widget
def getDockerVersion(self):
version = self.client.version()['Components'][0]['Version']
logging.info("Docker Server version: {version}".format(version=version))
return version