Browse Source

filecat plugin: a simple plugin to read file contents

master
Von Random 3 weeks ago
parent
commit
5e6519a51e
1 changed files with 28 additions and 0 deletions
  1. 28
    0
      plugins/filecat.py

+ 28
- 0
plugins/filecat.py View File

@@ -0,0 +1,28 @@
1
+import plugins
2
+
3
+
4
+FILECAT_DEFAULTS = {
5
+    'filename': '/etc/hostname', 'title': 'CAT',
6
+    'freq': 60, 'nofile': 'unavailable'
7
+}
8
+
9
+
10
+class PluginThread(plugins.PluginThreadCommon):
11
+    def __init__(self, config):
12
+        super(PluginThread, self).__init__(config, FILECAT_DEFAULTS)
13
+        self.hide = False
14
+        self.format_status(self.conf['title'], False)
15
+
16
+    def format_status(self, contents, urgent):
17
+        self.status['urgent'] = urgent
18
+        self.status['full_text'] = self.conf['title'] + ': ' + contents
19
+
20
+    def main(self):
21
+        try:
22
+            with open(self.conf['filename'], 'r') as datafile:
23
+                contents = datafile.read().strip()
24
+            urgent = False
25
+        except FileNotFoundError:
26
+            contents = self.conf['nofile']
27
+            urgent = True
28
+        self.format_status(contents, urgent)

Loading…
Cancel
Save