From c290e3bae796f8a8145e82f8fb336d2dc59607d8 Mon Sep 17 00:00:00 2001 From: bmintz Date: Sat, 14 Oct 2017 19:18:14 -0500 Subject: [PATCH 01/12] clipboards: add Termux support pretty simple. it's just the same as the other commands future work should probably deduplicate all those `subprocess.Popen`s. --- pyperclip/clipboards.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/pyperclip/clipboards.py b/pyperclip/clipboards.py index 0814eeb..76de3bd 100644 --- a/pyperclip/clipboards.py +++ b/pyperclip/clipboards.py @@ -24,6 +24,26 @@ def paste_osx(): return copy_osx, paste_osx +def init_termux_clipboard(): + """return a copy and paste function for Termux, + a terminal application for Android. + + more information: https://termux.com/""" + + def copy_termux(text): + p = subprocess.Popen('termux-clipboard-set', + stdin=subprocess.PIPE, close_fds=True) + p.communicate(input=text.encode('utf-8')) + + def paste_termux(): + p = subprocess.Popen('termux-clipboard-get', + stdout=subprocess.PIPE, close_fds=True) + stdout, stderr = p.communicate() + return stdout.decode('utf-8') + + return copy_termux, paste_termux + + def init_gtk_clipboard(): import gtk From d18fbdfec11be1484d8e71af06d8d3d32070e4d5 Mon Sep 17 00:00:00 2001 From: bmintz Date: Sat, 14 Oct 2017 19:19:29 -0500 Subject: [PATCH 02/12] __init__.py: add Termux support --- pyperclip/__init__.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/pyperclip/__init__.py b/pyperclip/__init__.py index a3db1b3..482befa 100644 --- a/pyperclip/__init__.py +++ b/pyperclip/__init__.py @@ -17,6 +17,8 @@ On Mac, the module uses pbcopy and pbpaste, which should come with the os. On Linux, install xclip or xsel via package manager. For example, in Debian: sudo apt-get install xclip +On Android, install the Termux app for terminal emulation, which include +a copy and paste command Otherwise on Linux, you will need the gtk or PyQt4 modules installed. @@ -28,7 +30,7 @@ import platform import os import subprocess -from .clipboards import (init_osx_clipboard, +from .clipboards import (init_osx_clipboard, init_termux_clipboard, init_gtk_clipboard, init_qt_clipboard, init_xclip_clipboard, init_xsel_clipboard, init_klipper_clipboard, init_no_clipboard) @@ -79,6 +81,8 @@ def determine_clipboard(): return init_xsel_clipboard() if _executable_exists("klipper") and _executable_exists("qdbus"): return init_klipper_clipboard() + elif _executable_exists("termux-clipboard-get"): + return init_termux_clipboard() return init_no_clipboard() @@ -87,6 +91,7 @@ def set_clipboard(clipboard): global copy, paste clipboard_types = {'osx': init_osx_clipboard, + 'termux': init_termux_clipboard, 'gtk': init_gtk_clipboard, 'qt': init_qt_clipboard, 'xclip': init_xclip_clipboard, From df7226d4a9e82e8c43f8903862dba0bfdb5cfff3 Mon Sep 17 00:00:00 2001 From: bmintz Date: Sat, 14 Oct 2017 19:22:57 -0500 Subject: [PATCH 03/12] tests/test_copy_paste: add Termux tests --- tests/test_copy_paste.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/test_copy_paste.py b/tests/test_copy_paste.py index 741c3e0..de850b9 100644 --- a/tests/test_copy_paste.py +++ b/tests/test_copy_paste.py @@ -9,7 +9,7 @@ sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..')) from pyperclip import _executable_exists, HAS_DISPLAY -from pyperclip.clipboards import (init_osx_clipboard, +from pyperclip.clipboards import (init_osx_clipboard, init_termux_clipboard init_gtk_clipboard, init_qt_clipboard, init_xclip_clipboard, init_xsel_clipboard, init_klipper_clipboard, init_no_clipboard) @@ -72,6 +72,9 @@ class TestWindows(_TestClipboard): if os.name == 'nt' or platform.system() == 'Windows': clipboard = init_windows_clipboard() +class TestTermux(_TestClipboard): + if _executable_exists('termux-clipboard-get'): + clipboard = init_termux_clipboard() class TestOSX(_TestClipboard): if os.name == 'mac' or platform.system() == 'Darwin': From e64dfb8db1843928ccd44b957b02ee670d8802a4 Mon Sep 17 00:00:00 2001 From: bmintz Date: Sat, 14 Oct 2017 19:23:43 -0500 Subject: [PATCH 04/12] bump minor version Termux support is a backwards-compatible new feature --- pyperclip/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyperclip/__init__.py b/pyperclip/__init__.py index 482befa..febf80c 100644 --- a/pyperclip/__init__.py +++ b/pyperclip/__init__.py @@ -25,7 +25,7 @@ gtk and PyQt4 modules are not available for Python 3, and this module does not work with PyGObject yet. """ -__version__ = '1.5.27' +__version__ = '1.6' import platform import os From d083f62c49ebb27f51884be1216c17be3a6a2761 Mon Sep 17 00:00:00 2001 From: bmintz Date: Sat, 14 Oct 2017 19:29:07 -0500 Subject: [PATCH 05/12] pyperclip: fix indentation --- pyperclip/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyperclip/__init__.py b/pyperclip/__init__.py index febf80c..a11725a 100644 --- a/pyperclip/__init__.py +++ b/pyperclip/__init__.py @@ -81,7 +81,7 @@ def determine_clipboard(): return init_xsel_clipboard() if _executable_exists("klipper") and _executable_exists("qdbus"): return init_klipper_clipboard() - elif _executable_exists("termux-clipboard-get"): + elif _executable_exists("termux-clipboard-get"): return init_termux_clipboard() return init_no_clipboard() From a8564f4976adec4d6bde3e22000c9c3d70d889c2 Mon Sep 17 00:00:00 2001 From: bmintz Date: Sat, 14 Oct 2017 19:29:38 -0500 Subject: [PATCH 06/12] bump version due to previous commit --- pyperclip/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyperclip/__init__.py b/pyperclip/__init__.py index a11725a..d47c58a 100644 --- a/pyperclip/__init__.py +++ b/pyperclip/__init__.py @@ -25,7 +25,7 @@ gtk and PyQt4 modules are not available for Python 3, and this module does not work with PyGObject yet. """ -__version__ = '1.6' +__version__ = '1.6.1' import platform import os From 6173815e630d41bbc20962bfcbcde914e2acc01b Mon Sep 17 00:00:00 2001 From: bmintz Date: Sat, 14 Oct 2017 19:31:19 -0500 Subject: [PATCH 07/12] tests: add missing comma --- tests/test_copy_paste.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_copy_paste.py b/tests/test_copy_paste.py index de850b9..c30dc89 100644 --- a/tests/test_copy_paste.py +++ b/tests/test_copy_paste.py @@ -9,7 +9,7 @@ sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..')) from pyperclip import _executable_exists, HAS_DISPLAY -from pyperclip.clipboards import (init_osx_clipboard, init_termux_clipboard +from pyperclip.clipboards import (init_osx_clipboard, init_termux_clipboard, init_gtk_clipboard, init_qt_clipboard, init_xclip_clipboard, init_xsel_clipboard, init_klipper_clipboard, init_no_clipboard) From c7a45686242eb10567a70a43e5817e7018dc538d Mon Sep 17 00:00:00 2001 From: bmintz Date: Sat, 14 Oct 2017 19:39:41 -0500 Subject: [PATCH 08/12] clipboards: remove trailing newline from Termux paste output --- pyperclip/clipboards.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pyperclip/clipboards.py b/pyperclip/clipboards.py index 76de3bd..bd6bf25 100644 --- a/pyperclip/clipboards.py +++ b/pyperclip/clipboards.py @@ -39,7 +39,8 @@ def paste_termux(): p = subprocess.Popen('termux-clipboard-get', stdout=subprocess.PIPE, close_fds=True) stdout, stderr = p.communicate() - return stdout.decode('utf-8') + # get rid of the trailing newline + return stdout.decode('utf-8')[:-1] return copy_termux, paste_termux From d12063ce19aa7636f8137db575f607704df105d8 Mon Sep 17 00:00:00 2001 From: bmintz Date: Sat, 14 Oct 2017 19:55:50 -0500 Subject: [PATCH 09/12] __init__.py: add FIXME comment about Termux i can't currently think of a way to detect that whether the Termux:API plugin is installed --- pyperclip/__init__.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pyperclip/__init__.py b/pyperclip/__init__.py index d47c58a..49746d4 100644 --- a/pyperclip/__init__.py +++ b/pyperclip/__init__.py @@ -82,7 +82,10 @@ def determine_clipboard(): if _executable_exists("klipper") and _executable_exists("qdbus"): return init_klipper_clipboard() elif _executable_exists("termux-clipboard-get"): - return init_termux_clipboard() + # FIXME this command will exist even if the Termux:API plugin is not installed + # if it's not installed, copy and paste will just hang + # we need a reliable way to determine whether the plugin is installed + return init_termux_clipboard() return init_no_clipboard() From ebb313cf8dfc2c6b46c11e713d30557d10de2bb3 Mon Sep 17 00:00:00 2001 From: bmintz Date: Sat, 14 Oct 2017 19:56:36 -0500 Subject: [PATCH 10/12] bump patch version --- pyperclip/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyperclip/__init__.py b/pyperclip/__init__.py index 49746d4..d9c17fb 100644 --- a/pyperclip/__init__.py +++ b/pyperclip/__init__.py @@ -25,7 +25,7 @@ gtk and PyQt4 modules are not available for Python 3, and this module does not work with PyGObject yet. """ -__version__ = '1.6.1' +__version__ = '1.6.2' import platform import os From 17866d50019756b776dca7f3677603759f825c0e Mon Sep 17 00:00:00 2001 From: bmintz Date: Sat, 14 Oct 2017 19:58:54 -0500 Subject: [PATCH 11/12] __init__: document the need for the Termux:API plugin --- pyperclip/__init__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pyperclip/__init__.py b/pyperclip/__init__.py index d9c17fb..a80a2d2 100644 --- a/pyperclip/__init__.py +++ b/pyperclip/__init__.py @@ -17,8 +17,8 @@ On Mac, the module uses pbcopy and pbpaste, which should come with the os. On Linux, install xclip or xsel via package manager. For example, in Debian: sudo apt-get install xclip -On Android, install the Termux app for terminal emulation, which include -a copy and paste command +On Android, install the Termux app for terminal emulation. Then install +the Termux:API plugin, which provide support for the copy and paste commands. Otherwise on Linux, you will need the gtk or PyQt4 modules installed. From ff71096092eb2621beb94a75ed3f32641dede8cc Mon Sep 17 00:00:00 2001 From: bmintz Date: Sat, 14 Oct 2017 19:59:24 -0500 Subject: [PATCH 12/12] bump patch version --- pyperclip/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyperclip/__init__.py b/pyperclip/__init__.py index a80a2d2..8076e66 100644 --- a/pyperclip/__init__.py +++ b/pyperclip/__init__.py @@ -25,7 +25,7 @@ gtk and PyQt4 modules are not available for Python 3, and this module does not work with PyGObject yet. """ -__version__ = '1.6.2' +__version__ = '1.6.3' import platform import os