Added multistep pattern matching
This commit is contained in:
parent
6789843eeb
commit
bf053eda24
@ -116,12 +116,20 @@ class SearchPassService(dbus.service.Object):
|
||||
[self.password_executable, "list"], universal_newlines=True
|
||||
).split("\n")[:-1]
|
||||
|
||||
results = [
|
||||
e[0]
|
||||
for e in process.extract(
|
||||
name, password_list, limit=5, scorer=fuzz.partial_ratio
|
||||
)
|
||||
]
|
||||
results = list(filter(lambda p: p.startswith(name), password_list))[:5]
|
||||
|
||||
remaining = 5 - len(results)
|
||||
|
||||
if remaining > 0:
|
||||
fuzzy_results = [
|
||||
e[0]
|
||||
for e in process.extract(
|
||||
name, password_list, limit=remaining, scorer=fuzz.token_sort_ratio
|
||||
)
|
||||
]
|
||||
|
||||
results.extend(fuzzy_results)
|
||||
|
||||
if field is not None:
|
||||
results = [f":{field} {r}" for r in results]
|
||||
return results
|
||||
@ -149,12 +157,29 @@ class SearchPassService(dbus.service.Object):
|
||||
path = path_join(dir_path, filename)[:-4]
|
||||
password_list.append(path)
|
||||
|
||||
results = [
|
||||
e[0]
|
||||
for e in process.extract(
|
||||
name, password_list, limit=5, scorer=fuzz.partial_ratio
|
||||
)
|
||||
]
|
||||
results = list(filter(lambda p: p.startswith(name), password_list))[:5]
|
||||
|
||||
remaining = 5 - len(results)
|
||||
|
||||
if remaining > 0:
|
||||
containing_results = list(filter(lambda p: name in p, password_list))[
|
||||
:remaining
|
||||
]
|
||||
|
||||
results.extend(containing_results)
|
||||
|
||||
remaining = 5 - len(results)
|
||||
|
||||
if remaining > 0:
|
||||
fuzzy_results = [
|
||||
e[0]
|
||||
for e in process.extract(
|
||||
name, password_list, limit=remaining, scorer=fuzz.token_sort_ratio
|
||||
)
|
||||
]
|
||||
|
||||
results.extend(fuzzy_results)
|
||||
|
||||
if field == "otp":
|
||||
results = [f"otp {r}" for r in results]
|
||||
elif field is not None:
|
||||
@ -169,7 +194,9 @@ class SearchPassService(dbus.service.Object):
|
||||
if match:
|
||||
value = match.group("value")
|
||||
else:
|
||||
raise RuntimeError(f"The field {field} was not found in the password entry.")
|
||||
raise RuntimeError(
|
||||
f"The field {field} was not found in the password entry."
|
||||
)
|
||||
else:
|
||||
value = output.split("\n", 1)[0]
|
||||
return value
|
||||
@ -188,7 +215,9 @@ class SearchPassService(dbus.service.Object):
|
||||
|
||||
def send_password_to_native_clipboard(self, base_args, name, field=None):
|
||||
if self.password_mode == "bw":
|
||||
output = subprocess.check_output(base_args + [name], universal_newlines=True)
|
||||
output = subprocess.check_output(
|
||||
base_args + [name], universal_newlines=True
|
||||
)
|
||||
value = self.get_value_from_output(output, field)
|
||||
p1 = subprocess.run(self.clipboard_executable, input=value, text=True)
|
||||
if p1.returncode:
|
||||
|
Loading…
x
Reference in New Issue
Block a user