Skip to content

Instantly share code, notes, and snippets.

@hanny24
Created September 9, 2013 18:16
Show Gist options
  • Save hanny24/6499422 to your computer and use it in GitHub Desktop.
Save hanny24/6499422 to your computer and use it in GitHub Desktop.
Quick & dirty recoll support for Kupfer. Just place it to ~/.local/share/kupfer/plugins.
# Heavily based on Locate plugin by Ulrik Sverdrup <[email protected]>
__kupfer_name__ = _("Recoll")
__kupfer_actions__ = (
"Recoll",
)
__description__ = _("Search using Recoll")
__version__ = ""
__author__ = "Honza Strnad <[email protected]>"
import subprocess
from kupfer.objects import Action, Source
from kupfer.objects import TextLeaf
from kupfer import icons, plugin_support
from kupfer.obj.objects import ConstructFileLeaf
class Recoll (Action):
def __init__(self):
Action.__init__(self, _("Recoll"))
def is_factory(self):
return True
def activate(self, leaf):
return RecollQuerySource(leaf.object)
def item_types(self):
yield TextLeaf
def get_description(self):
return _("Search using Recoll")
def get_gicon(self):
return icons.ComposedIcon("recoll", self.get_icon_name())
def get_icon_name(self):
return "edit-find"
class RecollQuerySource (Source):
def __init__(self, query):
Source.__init__(self, name=_('Results for "%s"') % query)
self.query = query
self.max_items = 500
def repr_key(self):
return self.query
def get_items(self):
command = ("recoll -t -q '%s'" % (self.query))
p = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE)
def get_locate_output(proc):
out, ignored_err = proc.communicate()
return (ConstructFileLeaf(f.split("\x09")[1][8:-1]) for f in out.split("\n")[2:-1])
for F in get_locate_output(p):
yield F
def get_gicon(self):
return icons.ComposedIcon("recoll", self.get_icon_name())
def get_icon_name(self):
return "edit-find"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment