Merge pull request #7 from shtrom/fuzzywuzzy

Use fuzzy wuzzy to generate matches
This commit is contained in:
jle64 2018-12-04 15:40:40 +01:00 committed by GitHub
commit efe14098b3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 15 deletions

View File

@ -25,7 +25,7 @@
# Copyright (C) 2012 Red Hat, Inc. # Copyright (C) 2012 Red Hat, Inc.
# Author: Luke Macken <lmacken@redhat.com> # Author: Luke Macken <lmacken@redhat.com>
import difflib from fuzzywuzzy import process, fuzz
from os import getenv from os import getenv
from os import walk from os import walk
from os.path import expanduser from os.path import expanduser
@ -83,9 +83,8 @@ class SearchPassService(dbus.service.Object):
pass pass
def get_result_set(self, terms): def get_result_set(self, terms):
name = ' '.join(terms) name = ''.join(terms)
matcher = difflib.SequenceMatcher(b=name, autojunk=False) password_list = []
matches = {}
for root, dirs, files in walk(self.password_store): for root, dirs, files in walk(self.password_store):
dir_path = root[len(self.password_store) + 1:] dir_path = root[len(self.password_store) + 1:]
@ -97,18 +96,12 @@ class SearchPassService(dbus.service.Object):
if filename[-4:] != '.gpg': if filename[-4:] != '.gpg':
continue continue
path = path_join(dir_path, filename)[:-4] path = path_join(dir_path, filename)[:-4]
for part in path.split('/'): password_list.append(path)
# smartcase: be case insensitive unless uppercase
# characters are used in the search
if name.islower():
part = part.lower()
matcher.set_seq1(part)
score = matcher.ratio()
if score >= 0.5 and \
(path not in matches or score > matches[path]):
matches[path] = score
return sorted(matches, key=matches.__getitem__, reverse=True) return [entry[0] for entry in process.extract(name,
password_list,
scorer=fuzz.partial_ratio,
limit=5)]
def send_password_to_gpaste(self, name): def send_password_to_gpaste(self, name):
pass_cmd = subprocess.run( pass_cmd = subprocess.run(

View File

@ -6,6 +6,9 @@ DATADIR=${DATADIR:-/usr/share}
LIBDIR=${LIBDIR:-/usr/lib} LIBDIR=${LIBDIR:-/usr/lib}
LIBEXECDIR=${LIBEXECDIR:-/usr/lib/} LIBEXECDIR=${LIBEXECDIR:-/usr/lib/}
SYSCONFDIR=${SYSCONFDIR:-/etc} SYSCONFDIR=${SYSCONFDIR:-/etc}
PIPARGS=${PIPARGS:-} # use --user for local install
pip install ${PIPARGS} fuzzywuzzy
install -Dm 0755 gnome-pass-search-provider.py "${LIBEXECDIR}"/gnome-pass-search-provider/gnome-pass-search-provider.py install -Dm 0755 gnome-pass-search-provider.py "${LIBEXECDIR}"/gnome-pass-search-provider/gnome-pass-search-provider.py