filecat plugin: a simple plugin to read file contents
This commit is contained in:
parent
151c94c5f3
commit
5e6519a51e
1 changed files with 28 additions and 0 deletions
28
plugins/filecat.py
Normal file
28
plugins/filecat.py
Normal file
|
@ -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)
|
Loading…
Reference in a new issue