Skip to content

Commit

Permalink
Fix PEP8
Browse files Browse the repository at this point in the history
  • Loading branch information
bkbilly committed Aug 15, 2024
1 parent b9e4edc commit 9c7f4e9
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 15 deletions.
21 changes: 6 additions & 15 deletions lnxlink/modules/docker.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ def __init__(self, lnxlink):
self._requirements()
try:
# client = docker.from_env()
self.client = self.docker.DockerClient(base_url='unix://run/docker.sock')
self.client = self.docker.DockerClient(base_url="unix://run/docker.sock")
except Exception as err:
raise SystemError("Docker instance not found")
raise SystemError(f"Docker instance not found: {err}") from err
self.containers = self._get_containers()

def _requirements(self):
Expand All @@ -33,7 +33,7 @@ def exposed_controls(self):
"value_template": f"{{{{ value_json.get('{container}', {{}}).get('running') }}}}",
"attributes_template": f"{{{{ value_json.get('{container}', {{}}) | tojson }}}}",
}
discovery_info[f"Docker Prune"] = {
discovery_info["Docker Prune"] = {
"type": "button",
"icon": "mdi:docker",
}
Expand All @@ -48,24 +48,16 @@ def get_info(self):
return self.containers

def _get_containers(self):
include = (
self.lnxlink.config["settings"]
.get("docker", {})
.get("include", [])
)
exclude = (
self.lnxlink.config["settings"]
.get("docker", {})
.get("exclude", [])
)
include = self.lnxlink.config["settings"].get("docker", {}).get("include", [])
exclude = self.lnxlink.config["settings"].get("docker", {}).get("exclude", [])
containers = {}
for container in self.client.containers.list(all=True):
if len(include) > 0 and container.name not in include:
continue
if container.name in exclude:
continue
ports = set()
for virtual, host in container.ports.items():
for _, host in container.ports.items():
if host is not None:
for host_info in host:
ports.add(host_info["HostPort"])
Expand Down Expand Up @@ -100,4 +92,3 @@ def start_control(self, topic, data):
self.client.images.prune()
self.client.networks.prune()
self.client.volumes.prune()

1 change: 1 addition & 0 deletions requirements_all.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ dbus-idle>=2024.7.1
dbus-mediaplayer>=2024.8.0
dbus-networkdevices>=2024.0.7
dbus-notification>=2024.7.2
docker>=7.0.0
ewmh>=0.1.6
mss>=7.0.1
numpy==1.26.4
Expand Down

0 comments on commit 9c7f4e9

Please sign in to comment.