summaryrefslogtreecommitdiff
path: root/plugins
diff options
context:
space:
mode:
authorFlorent Le Coz <louiz@louiz.org>2011-09-23 17:43:01 +0200
committerFlorent Le Coz <louiz@louiz.org>2011-09-23 17:43:01 +0200
commite3b933445fe4b18af6ec462fc40da5f482e447a0 (patch)
tree7f5c4060cd913d53000e22f269efce603e323cdc /plugins
parentf34d3172a11190ebfd8030deb5771a55fdb57476 (diff)
downloadpoezio-e3b933445fe4b18af6ec462fc40da5f482e447a0.tar.gz
poezio-e3b933445fe4b18af6ec462fc40da5f482e447a0.tar.bz2
poezio-e3b933445fe4b18af6ec462fc40da5f482e447a0.tar.xz
poezio-e3b933445fe4b18af6ec462fc40da5f482e447a0.zip
[teisenbe] first attempt at a plugin system.
Diffstat (limited to 'plugins')
-rw-r--r--plugins/screen_detach.py45
-rw-r--r--plugins/test.py12
2 files changed, 57 insertions, 0 deletions
diff --git a/plugins/screen_detach.py b/plugins/screen_detach.py
new file mode 100644
index 00000000..6ebc77f2
--- /dev/null
+++ b/plugins/screen_detach.py
@@ -0,0 +1,45 @@
+import os
+import stat
+import pyinotify
+
+SCREEN_DIR = '/var/run/screen/S-%s' % (os.getlogin(),)
+
+class Plugin(BasePlugin):
+ def init(self):
+ self.timed_event = None
+ sock_path = None
+ self.thread = None
+ for f in os.listdir(SCREEN_DIR):
+ path = os.path.join(SCREEN_DIR, f)
+ if screen_attached(path):
+ sock_path = path
+ self.attached = True
+ break
+
+ # Only actually do something if we found an attached screen (assuming only one)
+ if sock_path:
+ wm = pyinotify.WatchManager()
+ wm.add_watch(sock_path, pyinotify.EventsCodes.ALL_FLAGS['IN_ATTRIB'])
+ self.thread = pyinotify.ThreadedNotifier(wm, default_proc_fun=HandleScreen(plugin=self))
+ self.thread.start()
+
+ def cleanup(self):
+ if self.thread:
+ self.thread.stop()
+
+ def update_screen_state(self, socket):
+ attached = screen_attached(socket)
+ if attached != self.attached:
+ self.attached = attached
+ status = 'available' if self.attached else 'away'
+ self.core.command_status(status)
+
+def screen_attached(socket):
+ return (os.stat(socket).st_mode & stat.S_IXUSR) != 0
+
+class HandleScreen(pyinotify.ProcessEvent):
+ def my_init(self, **kwargs):
+ self.plugin = kwargs['plugin']
+
+ def process_IN_ATTRIB(self, event):
+ self.plugin.update_screen_state(event.path)
diff --git a/plugins/test.py b/plugins/test.py
new file mode 100644
index 00000000..fc7aedc6
--- /dev/null
+++ b/plugins/test.py
@@ -0,0 +1,12 @@
+class Plugin(BasePlugin):
+ def init(self):
+ self.core.information("Plugin loaded")
+
+ def cleanup(self):
+ self.core.information("Plugin unloaded")
+
+ def on_message(self, message):
+ self.core.information("Test plugin received message: {}".format(message))
+
+ def command_plugintest(self, args):
+ self.core.information("Command! With args {}".format(args))