Skip to content
Snippets Groups Projects
Verified Commit e9db82ca authored by me5na7qbjqbrp's avatar me5na7qbjqbrp
Browse files

Use crossplatform clipboard

parent 0b050981
No related branches found
No related tags found
No related merge requests found
Pipeline #2903 passed with warnings with stage
in 39 seconds
......@@ -7,6 +7,9 @@ cPasswords is a group password manager develop by the
Client installation
-------------------
Please install ``python3 gettext python3-paramiko python3-pyperclip`` and
``xclip`` (optionnal).
- Add you GPG fingerprint and your SSH key to the cpassword server. For
the CRANS, you can do this on the intranet.
......
......@@ -24,10 +24,11 @@ import gettext
from configparser import ConfigParser
from secrets import token_urlsafe
# Import setuptool and SSH client
# Import setuptool, SSH client and clipboard
from pkg_resources import resource_filename
from paramiko.client import SSHClient
from paramiko.ssh_exception import SSHException
import pyperclip
# Import modules
from .gpg import decrypt, encrypt, receive_keys, list_keys, GPG_TRUSTLEVELS
......@@ -442,26 +443,11 @@ def saveclipboard(restore=False, old_clipboard=None):
"""Enregistre le contenu du presse-papier. Le rétablit si ``restore=True``"""
if restore and old_clipboard is None:
return
act = '-in' if restore else '-out'
proc = subprocess.Popen(['xclip', act, '-selection', 'clipboard'],
stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=sys.stderr)
if not restore:
old_clipboard = proc.stdout.read()
old_clipboard = pyperclip.paste()
else:
input(_("Appuyez sur Entrée pour récupérer le contenu précédent du presse papier."))
proc.stdin.write(old_clipboard)
proc.stdin.close()
proc.stdout.close()
return old_clipboard
def clipboard(texte):
"""Place ``texte`` dans le presse-papier en mémorisant l'ancien contenu."""
old_clipboard = saveclipboard()
proc = subprocess.Popen(['xclip', '-selection', 'clipboard'],
stdin=subprocess.PIPE, stdout=sys.stdout, stderr=sys.stderr)
proc.stdin.write(texte.encode("utf-8"))
proc.stdin.close()
pyperclip.copy(old_clipboard)
return old_clipboard
......@@ -503,7 +489,8 @@ def show_file(options):
if catch_pass is not None:
is_hidden = True
# On met le mdp dans le clipboard en mémorisant son ancien contenu
old_clipboard = clipboard(catch_pass.group(1))
old_clipboard = saveclipboard()
pyperclip.copy(catch_pass.group(1))
# Et donc on override l'affichage
line = "[Le mot de passe a été mis dans le presse papier]"
filtered += line + '\n'
......
......@@ -47,6 +47,7 @@ setup(
include_package_data=True,
install_requires=[
'paramiko>=2.2',
'pyperclip>=1.7.0'
],
entry_points={
"console_scripts": [
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment