Skip to content

Instantly share code, notes, and snippets.

@vwbusguy
Created February 11, 2020 01:01
Show Gist options
  • Save vwbusguy/34622a340362b0ee9cabdce00ddd75bd to your computer and use it in GitHub Desktop.
Save vwbusguy/34622a340362b0ee9cabdce00ddd75bd to your computer and use it in GitHub Desktop.
Gnome notification for running podman containers
#!env/bin/python
import gi, subprocess, sys
gi.require_version('Notify', '0.7')
from gi.repository import Notify
containers = []
keys=['created','name','image']
pman_out = subprocess.run(["podman","ps","--format",'{{.Created}}|{{.Names}}|{{.Image}}'],capture_output=True)
if pman_out.returncode == 0:
if not pman_out.stdout:
print("No containers are currently running.")
sys.exit(0)
containers_inp = pman_out.stdout.decode("utf-8")
containers_lines = containers_inp.split("\n")
for line in containers_lines:
if line:
container = dict(zip(keys,line.split('|')))
containers.append(container)
else:
sys.exit(str(pman_out.stderr.decode("utf-8")))
message = str()
for container in containers:
message = message + "{name} ({image})\n - Running since {created}\n".format(**container)
Notify.init("Containers")
Notify.Notification.new("Containers are running",message,'dialog-information').show()
Notify.uninit()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment