Compare commits
3 Commits
Author | SHA1 | Date | |
---|---|---|---|
72fe6f3007 | |||
6789843eeb | |||
3406972e21 |
@ -40,7 +40,7 @@ dnf install gnome-pass-search-provider
|
|||||||
|
|
||||||
## Manual
|
## Manual
|
||||||
|
|
||||||
Ensure that python>=3.7 as well as the dbus, gobject and thefuzz (formerly fuzzywuzzy, might still be packaged under that name in your distribution) Python modules are installed. They should all be packaged under python-name or python3-name depending on your distribution.
|
Ensure that python>=3.7 as well as the dbus and gobject Python modules are installed. They should all be packaged under python-name or python3-name depending on your distribution.
|
||||||
|
|
||||||
Clone this repository and run the installation script as root:
|
Clone this repository and run the installation script as root:
|
||||||
```
|
```
|
||||||
|
@ -32,12 +32,6 @@ from os.path import join as path_join
|
|||||||
import dbus.service
|
import dbus.service
|
||||||
from dbus.mainloop.glib import DBusGMainLoop
|
from dbus.mainloop.glib import DBusGMainLoop
|
||||||
|
|
||||||
try:
|
|
||||||
from thefuzz import fuzz
|
|
||||||
from thefuzz import process
|
|
||||||
except ModuleNotFoundError:
|
|
||||||
from fuzzywuzzy import fuzz
|
|
||||||
from fuzzywuzzy import process
|
|
||||||
from gi.repository import GLib
|
from gi.repository import GLib
|
||||||
|
|
||||||
# Convenience shorthand for declaring dbus interface methods.
|
# Convenience shorthand for declaring dbus interface methods.
|
||||||
@ -116,12 +110,8 @@ 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 x: x.startswith(name), password_list))[:5]
|
||||||
e[0]
|
|
||||||
for e in process.extract(
|
|
||||||
name, password_list, limit=5, scorer=fuzz.partial_ratio
|
|
||||||
)
|
|
||||||
]
|
|
||||||
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,51 +139,51 @@ 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 x: x.startswith(name), password_list))[:5]
|
||||||
e[0]
|
|
||||||
for e in process.extract(
|
|
||||||
name, password_list, limit=5, scorer=fuzz.partial_ratio
|
|
||||||
)
|
|
||||||
]
|
|
||||||
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:
|
||||||
results = [f":{field} {r}" for r in results]
|
results = [f":{field} {r}" for r in results]
|
||||||
return results
|
return results
|
||||||
|
|
||||||
|
def get_value_from_output(self, output, field=None):
|
||||||
|
if field is not None:
|
||||||
|
match = re.search(
|
||||||
|
rf"^{field}:\s*(?P<value>.+?)$", output, flags=re.I | re.M
|
||||||
|
)
|
||||||
|
if match:
|
||||||
|
value = match.group("value")
|
||||||
|
else:
|
||||||
|
raise RuntimeError(f"The field {field} was not found in the password entry.")
|
||||||
|
else:
|
||||||
|
value = output.split("\n", 1)[0]
|
||||||
|
return value
|
||||||
|
|
||||||
def send_password_to_gpaste(self, base_args, name, field=None):
|
def send_password_to_gpaste(self, base_args, name, field=None):
|
||||||
gpaste = self.session_bus.get_object(
|
gpaste = self.session_bus.get_object(
|
||||||
"org.gnome.GPaste.Daemon", "/org/gnome/GPaste"
|
"org.gnome.GPaste.Daemon", "/org/gnome/GPaste"
|
||||||
)
|
)
|
||||||
|
|
||||||
output = subprocess.check_output(base_args + [name], universal_newlines=True)
|
output = subprocess.check_output(base_args + [name], universal_newlines=True)
|
||||||
if field is not None:
|
value = self.get_value_from_output(output, field)
|
||||||
match = re.search(
|
|
||||||
rf"^{field}:\s*(?P<value>.+?)$", output, flags=re.I | re.M
|
|
||||||
)
|
|
||||||
if match:
|
|
||||||
password = match.group("value")
|
|
||||||
else:
|
|
||||||
raise RuntimeError(f"The field {field} was not found in the pass file.")
|
|
||||||
else:
|
|
||||||
password = output.split("\n", 1)[0]
|
|
||||||
try:
|
try:
|
||||||
gpaste.AddPassword(name, password, dbus_interface="org.gnome.GPaste1")
|
gpaste.AddPassword(name, value, dbus_interface="org.gnome.GPaste1")
|
||||||
except dbus.DBusException:
|
except dbus.DBusException:
|
||||||
gpaste.AddPassword(name, password, dbus_interface="org.gnome.GPaste2")
|
gpaste.AddPassword(name, value, dbus_interface="org.gnome.GPaste2")
|
||||||
|
|
||||||
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 field is not None:
|
|
||||||
raise RuntimeError("This feature requires GPaste.")
|
|
||||||
|
|
||||||
if self.password_mode == "bw":
|
if self.password_mode == "bw":
|
||||||
p1 = subprocess.Popen(base_args + [name], stdout=subprocess.PIPE)
|
output = subprocess.check_output(base_args + [name], universal_newlines=True)
|
||||||
p2 = subprocess.run(self.clipboard_executable, stdin=p1.stdout)
|
value = self.get_value_from_output(output, field)
|
||||||
if p1.returncode or p2.returncode:
|
p1 = subprocess.run(self.clipboard_executable, input=value, text=True)
|
||||||
|
if p1.returncode:
|
||||||
raise RuntimeError(
|
raise RuntimeError(
|
||||||
f"Error while running rbw: got return codes: {p1.returncode} {p2.returncode}."
|
f"Error while running copying to clipboard: got return code: {p1.returncode}."
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
|
if field is not None:
|
||||||
|
raise RuntimeError("This feature requires GPaste.")
|
||||||
result = subprocess.run(base_args + ["-c", name])
|
result = subprocess.run(base_args + ["-c", name])
|
||||||
if result.returncode:
|
if result.returncode:
|
||||||
raise RuntimeError(
|
raise RuntimeError(
|
||||||
|
@ -9,8 +9,6 @@ Requires: gnome-shell
|
|||||||
Requires: pass
|
Requires: pass
|
||||||
Requires: python3-gobject
|
Requires: python3-gobject
|
||||||
Requires: python3-dbus
|
Requires: python3-dbus
|
||||||
Requires: python3-fuzzywuzzy
|
|
||||||
Requires: python3-Levenshtein
|
|
||||||
BuildRoot: %{_tmppath}/%{name}-%{version}-build
|
BuildRoot: %{_tmppath}/%{name}-%{version}-build
|
||||||
|
|
||||||
%global debug_package %{nil}
|
%global debug_package %{nil}
|
||||||
|
Reference in New Issue
Block a user