From b03a5881825ddf3f9f5831342a9bf61ed3a4970e Mon Sep 17 00:00:00 2001 From: Von Random Date: Mon, 28 Oct 2019 11:57:51 +0300 Subject: plugins: allow disabling of title field; pacman: rename to cmd; cmd: use first line of output as value, not line count --- plugins/__init__.py | 2 +- plugins/cmd.py | 23 +++++++++++++++++++++++ plugins/pacman.py | 29 ----------------------------- 3 files changed, 24 insertions(+), 30 deletions(-) create mode 100644 plugins/cmd.py delete mode 100644 plugins/pacman.py diff --git a/plugins/__init__.py b/plugins/__init__.py index 016b462..262d144 100644 --- a/plugins/__init__.py +++ b/plugins/__init__.py @@ -18,7 +18,7 @@ class PluginThreadCommon: self.thread.daemon = True def format_status(self, status, urgent=False): - if 'title' in self.conf: + if 'title' in self.conf and self.conf['title']: full_text = '{}: {}'.format(self.conf['title'], status) else: full_text = status diff --git a/plugins/cmd.py b/plugins/cmd.py new file mode 100644 index 0000000..839dffe --- /dev/null +++ b/plugins/cmd.py @@ -0,0 +1,23 @@ +import plugins +import subprocess + + +PACMAN_DEFAULTS = { + 'cmd': ('/usr/bin/echo', 'I am cmd'), + 'title': 'CMD', 'freq': 15 +} + + +class PluginThread(plugins.PluginThreadCommon): + def __init__(self, config): + super(PluginThread, self).__init__(config, PACMAN_DEFAULTS) + + def main(self): + pacman_qu = subprocess.Popen( + self.conf['cmd'], stdout=subprocess.PIPE, + stderr=subprocess.DEVNULL, stdin=subprocess.DEVNULL, + encoding='UTF-8' + ) + out = pacman_qu.communicate()[0].strip().splitlines()[0] + + self.format_status(out) diff --git a/plugins/pacman.py b/plugins/pacman.py deleted file mode 100644 index 2b4551f..0000000 --- a/plugins/pacman.py +++ /dev/null @@ -1,29 +0,0 @@ -import plugins -import subprocess - - -PACMAN_DEFAULTS = { - 'cmd': ('/usr/bin/pacman', '-Qu'), - 'title': 'UPD', 'freq': 15, 'problem': 10 -} - - -class PluginThread(plugins.PluginThreadCommon): - def __init__(self, config): - super(PluginThread, self).__init__(config, PACMAN_DEFAULTS) - - def main(self): - pacman_qu = subprocess.Popen( - self.conf['cmd'], stdout=subprocess.PIPE, - stderr=subprocess.DEVNULL, stdin=subprocess.DEVNULL, - encoding='UTF-8' - ) - out = pacman_qu.communicate()[0].strip().splitlines() - packages = len([pkg for pkg in out if not '[ignored]' in pkg]) - if packages: - self.hide = False - else: - self.hide = True - - urgent = packages >= self.conf['problem'] - self.format_status(packages, urgent) -- cgit v1.2.3