From 13ec32b78f27b6a9358f040df3fdc07c0f9c46c8 Mon Sep 17 00:00:00 2001 From: Alessandro Astone Date: Mar 18 2022 23:02:16 +0000 Subject: Update to v0.6.0 --- diff --git a/python-pyclip.spec b/python-pyclip.spec index 7913112..98d3f6a 100644 --- a/python-pyclip.spec +++ b/python-pyclip.spec @@ -1,8 +1,8 @@ %global pypi_name pyclip Name: python-%{pypi_name} -Version: 0.5.4 -Release: 3%{?dist} +Version: 0.6.0 +Release: 1%{?dist} Summary: Cross-platform Clipboard module for Python with binary support License: ASL 2.0 @@ -10,8 +10,6 @@ URL: https://github.com/spyoungtech/pyclip Source0: %{url}/archive/v%{version}/%{pypi_name}-%{version}.tar.gz BuildArch: noarch -Patch0: support-wl-clipboard.patch - %global _description \ Cross-platform Clipboard module for Python with binary support @@ -44,6 +42,9 @@ BuildRequires: pyproject-rpm-macros %{_bindir}/pyclip %changelog +* Sat Mar 19 2022 Alessandro Astone - 0.6.0-1 +- Update to v0.6.0 + * Tue Mar 08 2022 Alessandro Astone - 0.5.4-2 - Use wl-clipboard diff --git a/support-wl-clipboard.patch b/support-wl-clipboard.patch deleted file mode 100644 index ae2efd2..0000000 --- a/support-wl-clipboard.patch +++ /dev/null @@ -1,177 +0,0 @@ -From 88144a5ed0d5656931d7cd21da61b3f804b6f98c Mon Sep 17 00:00:00 2001 -From: Alessandro Astone -Date: Tue, 8 Mar 2022 23:49:49 +0100 -Subject: [PATCH] Add Linux Wayland support - ---- - docs/README.md | 6 ++- - pyclip/util.py | 4 ++ - pyclip/wayland_clip.py | 113 +++++++++++++++++++++++++++++++++++++++++ - 3 files changed, 121 insertions(+), 2 deletions(-) - create mode 100644 pyclip/wayland_clip.py - -diff --git a/docs/README.md b/docs/README.md -index 4b8e144..0162c48 100644 ---- a/docs/README.md -+++ b/docs/README.md -@@ -63,7 +63,8 @@ This library implements functionality for several platforms and clipboard utilit - - - [x] MacOS - - [x] Windows --- [x] Linux (with `xclip`) -+- [x] Linux on x11 (with `xclip`) -+- [x] Linux on wayland (with `wl-clipboard`) - - If there is a platform or utility not currently listed, please request it by creating an issue. - -@@ -84,7 +85,8 @@ data being lost on copy/paste. This backend may be removed in a future release. - - ### Linux - --Linux requires `xclip` to work (which means you must also use X). Install with your package manager, e.g. `sudo apt install xclip` -+Linux on X11 requires `xclip` to work. Install with your package manager, e.g. `sudo apt install xclip` -+Linux on Wayland requires `wl-clipboard` to work. Install with your package manager, e.g. `sudo apt install wl-clipboard` - - # Acknowledgements - -diff --git a/pyclip/util.py b/pyclip/util.py -index 721a59d..734b6fe 100644 ---- a/pyclip/util.py -+++ b/pyclip/util.py -@@ -12,6 +12,7 @@ - # See the License for the specific language governing permissions and - # limitations under the License. - import sys -+import os - from .base import ClipboardSetupException, ClipboardBase - - -@@ -25,6 +26,9 @@ def detect_clipboard() -> ClipboardBase: - elif sys.platform == 'win32': - from .win_clip import WindowsClipboard - return WindowsClipboard() -+ elif sys.platform == 'linux' and os.environ.get("WAYLAND_DISPLAY"): -+ from .wayland_clip import WaylandClipboard -+ return WaylandClipboard() - elif sys.platform == 'linux': - from .xclip_clip import XclipClipboard - return XclipClipboard() -diff --git a/pyclip/wayland_clip.py b/pyclip/wayland_clip.py -new file mode 100644 -index 0000000..6c0ecef ---- /dev/null -+++ b/pyclip/wayland_clip.py -@@ -0,0 +1,113 @@ -+# Copyright 2021 Spencer Phillip Young -+# Copyright 2022 Alessandro Astone -+# -+# Licensed under the Apache License, Version 2.0 (the "License"); -+# you may not use this file except in compliance with the License. -+# You may obtain a copy of the License at -+# -+# http://www.apache.org/licenses/LICENSE-2.0 -+# -+# Unless required by applicable law or agreed to in writing, software -+# distributed under the License is distributed on an "AS IS" BASIS, -+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -+# See the License for the specific language governing permissions and -+# limitations under the License. -+""" -+Provides the clipboard functionality for Linux via ``wl-copy``/``wl-paste`` -+""" -+import warnings -+ -+from .base import ClipboardBase, ClipboardSetupException, ClipboardException -+from typing import Union -+import shutil -+import subprocess -+ -+ -+class WaylandClipboard(ClipboardBase): -+ def __init__(self): -+ self.wl_copy = shutil.which('wl-copy') -+ self.wl_paste = shutil.which('wl-paste') -+ if not self.wl_copy or not self.wl_paste: -+ raise ClipboardSetupException( -+ "wl-clipboard must be installed. " "Please install wl-clipboard using your system package manager" -+ ) -+ -+ def copy(self, data: Union[str, bytes], encoding: str = None) -> None: -+ """ -+ Copy data into the clipboard -+ -+ :param data: the data to be copied to the clipboard. Can be str or bytes. -+ :param encoding: same meaning as in ``subprocess.Popen``. -+ :return: None -+ """ -+ args = [ self.wl_copy ] -+ if isinstance(data, bytes): -+ if encoding is not None: -+ warnings.warn( -+ "encoding specified with a bytes argument. " -+ "Encoding option will be ignored. " -+ "To remove this warning, omit the encoding parameter or specify it as None", -+ stacklevel=2, -+ ) -+ proc = subprocess.Popen( -+ args, -+ stdin=subprocess.PIPE, -+ encoding=encoding, -+ ) -+ elif isinstance(data, str): -+ proc = subprocess.Popen( -+ args, -+ stdin=subprocess.PIPE, -+ text=True, -+ encoding=encoding, -+ ) -+ else: -+ raise TypeError(f"data argument must be of type str or bytes, not {type(data)}") -+ stdout, stderr = proc.communicate(data) -+ if proc.returncode != 0: -+ raise ClipboardException( -+ f"Copy failed. xclip returned code: {proc.returncode!r} " -+ f"Stderr: {stderr!r} " -+ f"Stdout: {stdout!r}" -+ ) -+ -+ def paste(self, encoding: str = None, text: bool = None, errors: str = None): -+ """ -+ Retrieve data from the clipboard -+ -+ :param encoding: same meaning as in ``subprocess.run`` -+ :param text: same meaning as in ``subprocess.run`` -+ :param errors: same meaning as in ``subprocess.run`` -+ :return: the clipboard contents. return type is binary by default. -+ If any of ``encoding``, ``errors``, or ``text`` are specified, the result type is str -+ """ -+ args = [ self.wl_paste ] -+ if encoding or text or errors: -+ completed_proc = subprocess.run( -+ args, -+ stdin=subprocess.PIPE, -+ stdout=subprocess.PIPE, -+ stderr=subprocess.PIPE, -+ text=text, -+ encoding=encoding, -+ ) -+ else: -+ completed_proc = subprocess.run( -+ args, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE -+ ) -+ -+ if completed_proc.returncode != 0: -+ raise ClipboardException( -+ f"Copy failed. xclip returned code: {completed_proc.returncode!r} " -+ f"Stderr: {completed_proc.stderr!r} " -+ f"Stdout: {completed_proc.stdout!r}" -+ ) -+ return completed_proc.stdout -+ -+ def clear(self): -+ """ -+ Clear the clipboard contents -+ -+ :return: -+ """ -+ self.copy('')