summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVon Random <von@vdrandom.org>2019-05-24 12:14:08 +0300
committerVon Random <von@vdrandom.org>2019-05-24 12:14:08 +0300
commit5e6519a51ed58a75f50a547a98cc08ed886d1fda (patch)
tree7ebd8d0df1e9f39919326465c18f53485595348d
parent151c94c5f3d0a786ce1058481f1c4c5c908bc305 (diff)
filecat plugin: a simple plugin to read file contents
-rw-r--r--plugins/filecat.py28
1 files changed, 28 insertions, 0 deletions
diff --git a/plugins/filecat.py b/plugins/filecat.py
new file mode 100644
index 0000000..9eae04d
--- /dev/null
+++ b/plugins/filecat.py
@@ -0,0 +1,28 @@
+import plugins
+
+
+FILECAT_DEFAULTS = {
+ 'filename': '/etc/hostname', 'title': 'CAT',
+ 'freq': 60, 'nofile': 'unavailable'
+}
+
+
+class PluginThread(plugins.PluginThreadCommon):
+ def __init__(self, config):
+ super(PluginThread, self).__init__(config, FILECAT_DEFAULTS)
+ self.hide = False
+ self.format_status(self.conf['title'], False)
+
+ def format_status(self, contents, urgent):
+ self.status['urgent'] = urgent
+ self.status['full_text'] = self.conf['title'] + ': ' + contents
+
+ def main(self):
+ try:
+ with open(self.conf['filename'], 'r') as datafile:
+ contents = datafile.read().strip()
+ urgent = False
+ except FileNotFoundError:
+ contents = self.conf['nofile']
+ urgent = True
+ self.format_status(contents, urgent)