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
|
[self.password_executable, "list"], universal_newlines=True
|
||||||
).split("\n")[:-1]
|
).split("\n")[:-1]
|
||||||
|
|
||||||
results = [
|
results = list(filter(lambda p: p.startswith(name), password_list))[:5]
|
||||||
e[0]
|
|
||||||
for e in process.extract(
|
remaining = 5 - len(results)
|
||||||
name, password_list, limit=5, scorer=fuzz.partial_ratio
|
|
||||||
)
|
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:
|
if field is not None:
|
||||||
results = [f":{field} {r}" for r in results]
|
results = [f":{field} {r}" for r in results]
|
||||||
return results
|
return results
|
||||||
@ -149,12 +157,29 @@ class SearchPassService(dbus.service.Object):
|
|||||||
path = path_join(dir_path, filename)[:-4]
|
path = path_join(dir_path, filename)[:-4]
|
||||||
password_list.append(path)
|
password_list.append(path)
|
||||||
|
|
||||||
results = [
|
results = list(filter(lambda p: p.startswith(name), password_list))[:5]
|
||||||
e[0]
|
|
||||||
for e in process.extract(
|
remaining = 5 - len(results)
|
||||||
name, password_list, limit=5, scorer=fuzz.partial_ratio
|
|
||||||
)
|
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":
|
if field == "otp":
|
||||||
results = [f"otp {r}" for r in results]
|
results = [f"otp {r}" for r in results]
|
||||||
elif field is not None:
|
elif field is not None:
|
||||||
@ -169,7 +194,9 @@ class SearchPassService(dbus.service.Object):
|
|||||||
if match:
|
if match:
|
||||||
value = match.group("value")
|
value = match.group("value")
|
||||||
else:
|
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:
|
else:
|
||||||
value = output.split("\n", 1)[0]
|
value = output.split("\n", 1)[0]
|
||||||
return value
|
return value
|
||||||
@ -188,7 +215,9 @@ class SearchPassService(dbus.service.Object):
|
|||||||
|
|
||||||
def send_password_to_native_clipboard(self, base_args, name, field=None):
|
def send_password_to_native_clipboard(self, base_args, name, field=None):
|
||||||
if self.password_mode == "bw":
|
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)
|
value = self.get_value_from_output(output, field)
|
||||||
p1 = subprocess.run(self.clipboard_executable, input=value, text=True)
|
p1 = subprocess.run(self.clipboard_executable, input=value, text=True)
|
||||||
if p1.returncode:
|
if p1.returncode:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user