[core] restructure to allow PIP packaging

OK - so I have to admit I *hate* the fact that PIP seems to require a
subdirectory named like the library.

But since the PIP package is something really nifty to have (thanks to
@tony again!!!), I updated the codebase to hopefully conform with what
PIP expects. Testruns so far look promising...
This commit is contained in:
tobi-wan-kenobi 2020-05-09 21:22:00 +02:00
parent 1d25be2059
commit 320827d577
146 changed files with 2509 additions and 2 deletions

View file

@ -0,0 +1,48 @@
# -*- coding: utf-8 -*-
"""Displays the number of docker containers running
Requires the following python packages:
* docker
contributed by `jlopezzarza <https://github.com/jlopezzarza>`_ - many thanks!
"""
import docker
from requests.exceptions import ConnectionError
import core.module
import core.widget
import core.decorators
class Module(core.module.Module):
@core.decorators.every(seconds=5)
def __init__(self, config, theme):
super().__init__(config, theme, core.widget.Widget(self.docker_info))
self.__info = ""
def state(self, widget):
state = []
if self.__info == "OK - 0":
state.append("warning")
elif self.__info in ["n/a", "off"]:
state.append("critical")
return state
def docker_info(self, widget):
try:
cli = docker.DockerClient(base_url="unix://var/run/docker.sock")
cli.ping()
self.__info = "OK - {}".format(
len(cli.containers.list(filters={"status": "running"}))
)
except ConnectionError:
self.__info = "off"
except Exception:
self.__info = "n/a"
return self.__info
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4