Merge pull request #302 from jlopezzarza/master

[modules/docker] Add basic docker list module
This commit is contained in:
tobi-wan-kenobi 2018-10-18 19:25:09 +02:00 committed by GitHub
commit f7d80d8f27
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
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') * dbus (for the module 'spotify')
* i3ipc (for the module 'title') * i3ipc (for the module 'title')
* pacman-contrib (for module 'arch-update') * pacman-contrib (for module 'arch-update')
* docker (for the module 'docker_ps')
# Required commandline utilities # 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": { "redshift": {
"day": { "prefix": "day" }, "night": { "prefix": "night" }, "transition": { "prefix": "trans" } "day": { "prefix": "day" }, "night": { "prefix": "night" }, "transition": { "prefix": "trans" }
}, },
"docker_ps": {
"prefix": "containers"
},
"sensors": { "sensors": {
"prefix": "sensors" "prefix": "sensors"
}, },

View file

@ -91,13 +91,20 @@
"estimate": { "prefix": "" } "estimate": { "prefix": "" }
}, },
"caffeine": { "caffeine": {
"activated": {"prefix": " " }, "deactivated": { "prefix": " " } "activated": {"prefix": " " },
"deactivated": { "prefix": " " }
}, },
"xrandr": { "xrandr": {
"on": { "prefix": " "}, "off": { "prefix": " " } "on": { "prefix": " "},
"off": { "prefix": " " }
}, },
"redshift": { "redshift": {
"day": { "prefix": "" }, "night": { "prefix": "" }, "transition": { "prefix": "" } "day": { "prefix": "" },
"night": { "prefix": "" },
"transition": { "prefix": "" }
},
"docker_ps": {
"prefix": ""
}, },
"sensors": { "sensors": {
"prefix": "" "prefix": ""
@ -143,6 +150,8 @@
"prefix": "  " "prefix": "  "
}, },
"progress": { "progress": {
"copying": { "prefix": "" } "copying": {
"prefix": ""
}
} }
} }