[modules/docker] Add basic docker list module

This commit is contained in:
Jorge Lopez 2018-10-18 12:14:06 +02:00
parent 4a75d9e143
commit e767f9b393
4 changed files with 86 additions and 36 deletions

View file

@ -170,6 +170,7 @@ Modules and commandline utilities are only required for modules, the core itself
* dbus (for the module 'spotify')
* i3ipc (for the module 'title')
* pacman-contrib (for module 'arch-update')
* docker (for the module 'docker_ps')
# Required commandline utilities

View file

@ -0,0 +1,37 @@
# -*- coding: utf-8 -*-
"""Displays the number of docker containers running
Requires the following python packages:
* docker
"""
try:
import docker
except ImportError:
pass
from requests.exceptions import ConnectionError
import bumblebee.input
import bumblebee.output
import bumblebee.engine
class Module(bumblebee.engine.Module):
def __init__(self, engine, config):
widget = bumblebee.output.Widget(full_text=self.status)
super(Module, self).__init__(engine, config, widget)
self._status = self.status
def update(self, widgets):
self._status = self.status
def status(self, _):
cli = docker.DockerClient(base_url='unix://var/run/docker.sock')
try:
cli.ping()
except ConnectionError:
return "Daemon off"
return "OK - {}".format(len(cli.containers.list(filters={'status': "running"})))

View file

@ -60,6 +60,9 @@
"redshift": {
"day": { "prefix": "day" }, "night": { "prefix": "night" }, "transition": { "prefix": "trans" }
},
"docker_ps": {
"prefix": "containers"
},
"sensors": {
"prefix": "sensors"
},

View file

@ -59,9 +59,9 @@
"muted": { "prefix": "" },
"unmuted": { "prefix": "" }
},
"kernel": {
"prefix": "\uf17c"
},
"kernel": {
"prefix": "\uf17c"
},
"nic": {
"wireless-up": { "prefix": "" },
"wireless-down": { "prefix": "" },
@ -91,22 +91,29 @@
"estimate": { "prefix": "" }
},
"caffeine": {
"activated": {"prefix": " " }, "deactivated": { "prefix": " " }
"activated": {"prefix": " " },
"deactivated": { "prefix": " " }
},
"xrandr": {
"on": { "prefix": " "}, "off": { "prefix": " " }
"on": { "prefix": " "},
"off": { "prefix": " " }
},
"redshift": {
"day": { "prefix": "" }, "night": { "prefix": "" }, "transition": { "prefix": "" }
"day": { "prefix": "" },
"night": { "prefix": "" },
"transition": { "prefix": "" }
},
"sensors": {
"prefix": ""
},
"traffic":{
"rx": { "prefix": "" },
"tx": { "prefix": "" }
},
"mpd": {
"docker_ps": {
"prefix": ""
},
"sensors": {
"prefix": ""
},
"traffic":{
"rx": { "prefix": "" },
"tx": { "prefix": "" }
},
"mpd": {
"playing": { "prefix": "" },
"paused": { "prefix": "" },
"stopped": { "prefix": "" },
@ -123,26 +130,28 @@
"github": {
"prefix": "  "
},
"hipchat": {
"prefix": "  "
},
"spotify": {
"prefix": "  "
},
"publicip": {
"prefix": "  "
},
"weather": {
"clouds": { "prefix": "" },
"rain": { "prefix": "" },
"snow": { "prefix": "" },
"clear": { "prefix": "" },
"thunder": { "prefix": "" }
},
"taskwarrior": {
"prefix": "  "
},
"progress": {
"copying": { "prefix": "" }
}
"hipchat": {
"prefix": "  "
},
"spotify": {
"prefix": "  "
},
"publicip": {
"prefix": "  "
},
"weather": {
"clouds": { "prefix": "" },
"rain": { "prefix": "" },
"snow": { "prefix": "" },
"clear": { "prefix": "" },
"thunder": { "prefix": "" }
},
"taskwarrior": {
"prefix": "  "
},
"progress": {
"copying": {
"prefix": ""
}
}
}