summaryrefslogtreecommitdiff
path: root/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'plugins')
-rw-r--r--plugins/day_change.py4
-rw-r--r--plugins/gpg/__init__.py2
-rw-r--r--plugins/iq_show.py4
-rw-r--r--plugins/link.py39
-rw-r--r--plugins/pipe_cmd.py41
-rw-r--r--plugins/replace.py2
-rw-r--r--plugins/uptime.py4
7 files changed, 60 insertions, 36 deletions
diff --git a/plugins/day_change.py b/plugins/day_change.py
index cedb4b35..6e0c3e1f 100644
--- a/plugins/day_change.py
+++ b/plugins/day_change.py
@@ -27,9 +27,7 @@ class Plugin(BasePlugin):
msg = _("Day changed to %s") % (datetime.date.today().isoformat())
for tab in self.core.tabs:
- if (isinstance(tab, tabs.MucTab) or
- isinstance(tab, tabs.PrivateTab) or
- isinstance(tab, tabs.ConversationTab)):
+ if isinstance(tab, tabs.ChatTab):
tab.add_message(msg)
self.core.refresh_window()
diff --git a/plugins/gpg/__init__.py b/plugins/gpg/__init__.py
index 67720a5e..bc8a96c1 100644
--- a/plugins/gpg/__init__.py
+++ b/plugins/gpg/__init__.py
@@ -106,7 +106,7 @@ to upload you public key on a public server.
"""
from gpg import gnupg
-from sleekxmpp.xmlstream.stanzabase import JID
+from slixmpp.xmlstream.stanzabase import JID
from xml.etree import cElementTree as ET
import xml.sax.saxutils
diff --git a/plugins/iq_show.py b/plugins/iq_show.py
index 8f82ca72..387878f4 100644
--- a/plugins/iq_show.py
+++ b/plugins/iq_show.py
@@ -3,8 +3,8 @@ Show the exchanged IQs (useful for debugging).
"""
from plugin import BasePlugin
-from sleekxmpp.xmlstream.matcher import StanzaPath
-from sleekxmpp.xmlstream.handler import Callback
+from slixmpp.xmlstream.matcher import StanzaPath
+from slixmpp.xmlstream.handler import Callback
class Plugin(BasePlugin):
def init(self):
diff --git a/plugins/link.py b/plugins/link.py
index b2c4470d..d39d01b9 100644
--- a/plugins/link.py
+++ b/plugins/link.py
@@ -43,11 +43,14 @@ Usage
.. glossary::
/link
- **Usage:** ``/link [range]``
+ **Usage:** ``/link [range] [command]``
- This plugin adds a :term:`/link` command that will open the links in ``firefox``. If
- you want to use another browser, you can use the :term:`/set` command to change the
- :term:`browser` option.
+ This plugin adds a :term:`/link` command that will open the links in
+ ``firefox``. If you want to use another browser, or any other
+ command, you can use the :term:`/set` command to change the
+ :term:`browser` option. You can also specify the command to execute
+ directly in the arguments. For example `/link "mpv %s"` will open
+ the first link found using mpv, instead of the configured browser.
:term:`/link` without argument will open the last link found
@@ -94,8 +97,10 @@ class Plugin(BasePlugin):
def init(self):
for _class in (tabs.MucTab, tabs.PrivateTab, tabs.ConversationTab):
self.api.add_tab_command(_class, 'link', self.command_link,
- usage='[num]',
- help='Opens the last link from the conversation into a browser.\nIf [num] is given, then it will open the num-th link displayed.',
+ usage='[num] [command]',
+ help='Opens the last link from the conversation into a browser.\n\
+ If [num] is given, then it will\open the num-th link displayed. \
+ Use a [command] argument to override the configured browser value.',
short='Open links into a browser')
def find_link(self, nb):
@@ -114,7 +119,13 @@ class Plugin(BasePlugin):
def command_link(self, args):
args = common.shell_split(args)
- if len(args) == 1:
+ start = 1
+ end = 1
+ # With two arguments, the first is the range, the second is the command
+ # With only one argument, it is a range if it starts with a number
+ # or :, otherwise it is a command
+ if len(args) == 2 or\
+ len(args) == 1 and (args[0][0].isnumeric() or args[0][0] == ":"):
if args[0].find(':') == -1:
try:
start = int(args[0])
@@ -130,15 +141,19 @@ class Plugin(BasePlugin):
end = int(end)
except ValueError:
return self.api.information('Invalid range: %s' % (args[0]), 'Error')
- else:
- start = 1
- end = 1
+ command = None
+ if len(args) == 2:
+ command = args[1]
+ if len(args) == 1 and (not args[0][0].isnumeric() and args[0][0] != ":"):
+ command = args[0]
for nb in range(start, end+1):
link = self.find_link(nb)
if not link:
return self.api.information('No URL found.', 'Warning')
default = app_mapping.get(platform.system(), 'firefox')
- self.core.exec_command([self.config.get('browser', default), link])
-
+ if command is None:
+ self.core.exec_command([self.config.get('browser', default), link])
+ else:
+ self.core.exec_command([command, link])
def cleanup(self):
del self.config
diff --git a/plugins/pipe_cmd.py b/plugins/pipe_cmd.py
index f554a71d..762501ae 100644
--- a/plugins/pipe_cmd.py
+++ b/plugins/pipe_cmd.py
@@ -6,10 +6,10 @@ This plugins allows commands to be sent to poezio via a named pipe.
from plugin import BasePlugin
-import threading
import os
import stat
import logging
+import asyncio
log = logging.getLogger(__name__)
@@ -25,19 +25,30 @@ class Plugin(BasePlugin):
os.mkfifo(self.pipename)
if not stat.S_ISFIFO(os.stat(self.pipename).st_mode):
- log.error("File %s is not a fifo file" % self.pipename)
- raise TypeError
-
- thread = threading.Thread(target=self.main_loop)
- thread.setDaemon(True)
- thread.start()
-
- def main_loop(self):
- while not self.stop:
- fd = open(self.pipename, 'r')
- line = fd.read().strip()
- self.api.run_command(line)
- fd.close()
+ raise TypeError("File %s is not a fifo file" % self.pipename)
+
+ self.fd = os.open(self.pipename, os.O_RDONLY|os.O_NONBLOCK)
+
+ self.data = b""
+ asyncio.get_event_loop().add_reader(self.fd, self.read_from_fifo)
+
+ def read_from_fifo(self):
+ data = os.read(self.fd, 512)
+ if not data:
+ # EOF, close the fifo. And reopen it
+ asyncio.get_event_loop().remove_reader(self.fd)
+ os.close(self.fd)
+ self.fd = os.open(self.pipename, os.O_RDONLY|os.O_NONBLOCK)
+ asyncio.get_event_loop().add_reader(self.fd, self.read_from_fifo)
+ self.data = b''
+ else:
+ self.data += data
+ l = self.data.split(b'\n', 1)
+ if len(l) == 2:
+ line, self.data = l
+ log.debug("run: %s" % (line.decode().strip()))
+ self.api.run_command(line.decode().strip())
def cleanup(self):
- self.stop = True
+ asyncio.get_event_loop().remove_reader(self.fd)
+ os.close(self.fd)
diff --git a/plugins/replace.py b/plugins/replace.py
index c9143ef8..21f2c9af 100644
--- a/plugins/replace.py
+++ b/plugins/replace.py
@@ -58,7 +58,7 @@ import tabs
import datetime
import random
import re
-from sleekxmpp.xmlstream.stanzabase import JID
+from slixmpp.xmlstream.stanzabase import JID
class Plugin(BasePlugin):
def init(self):
diff --git a/plugins/uptime.py b/plugins/uptime.py
index 2b171703..dbeb6a63 100644
--- a/plugins/uptime.py
+++ b/plugins/uptime.py
@@ -13,7 +13,7 @@ Command
"""
from plugin import BasePlugin
from common import parse_secs_to_str, safeJID
-from sleekxmpp.xmlstream import ET
+from slixmpp.xmlstream import ET
class Plugin(BasePlugin):
def init(self):
@@ -33,4 +33,4 @@ class Plugin(BasePlugin):
return
iq = self.core.xmpp.makeIqGet(ito=jid.server)
iq.append(ET.Element('{jabber:iq:last}query'))
- iq.send(block=False, callback=callback)
+ iq.send(callback=callback)