summaryrefslogtreecommitdiff
path: root/cmd2.py
diff options
context:
space:
mode:
authorJared Crapo <jared@kotfu.net>2017-12-11 19:15:15 -0700
committerJared Crapo <jared@kotfu.net>2017-12-11 19:15:15 -0700
commit67e669e3345fb637e4f4779691a7a8ec4b1763f6 (patch)
tree7632e68cc845e1089111e9f10b105bce8c6d5a46 /cmd2.py
parent4f57dc14a7ffc2cbd741622da7d05d42ba7f7789 (diff)
parent63b0c6b3a92cab837a71bbad78e777c522823c93 (diff)
downloadcmd2-git-67e669e3345fb637e4f4779691a7a8ec4b1763f6.tar.gz
Merge branch 'master' of https://github.com/python-cmd2/cmd2 into argparse
Diffstat (limited to 'cmd2.py')
-rwxr-xr-xcmd2.py19
1 files changed, 15 insertions, 4 deletions
diff --git a/cmd2.py b/cmd2.py
index 64388de9..9b0bc66a 100755
--- a/cmd2.py
+++ b/cmd2.py
@@ -46,6 +46,13 @@ from optparse import make_option
import pyparsing
import pyperclip
+# Newer versions of pyperclip are released as a single file, but older versions had a more complicated structure
+try:
+ from pyperclip.exceptions import PyperclipException
+except ImportError:
+ # noinspection PyUnresolvedReferences
+ from pyperclip import PyperclipException
+
# On some systems, pyperclip will import gtk for its clipboard functionality.
# The following code is a workaround for gtk interfering with printing from a background
# thread while the CLI thread is blocking in raw_input() in Python 2 on Linux.
@@ -98,7 +105,7 @@ if six.PY3:
else:
BROKEN_PIPE_ERROR = IOError
-__version__ = '0.7.8a'
+__version__ = '0.7.9a'
# Pyparsing enablePackrat() can greatly speed up parsing, but problems have been seen in Python 3 in the past
pyparsing.ParserElement.enablePackrat()
@@ -339,13 +346,17 @@ def options(option_list, arg_desc="arg"):
# Can we access the clipboard? Should always be true on Windows and Mac, but only sometimes on Linux
# noinspection PyUnresolvedReferences
try:
- if sys.platform.startswith('linux'):
+ # Get the version of the pyperclip module as a float
+ pyperclip_ver = float('.'.join(pyperclip.__version__.split('.')[:2]))
+
+ # The extraneous output bug in pyperclip on Linux using xclip was fixed in more recent versions of pyperclip
+ if sys.platform.startswith('linux') and pyperclip_ver < 1.6:
# Avoid extraneous output to stderr from xclip when clipboard is empty at cost of overwriting clipboard contents
pyperclip.copy('')
else:
# Try getting the contents of the clipboard
_ = pyperclip.paste()
-except pyperclip.exceptions.PyperclipException:
+except PyperclipException:
can_clip = False
else:
can_clip = True
@@ -597,7 +608,7 @@ class Cmd(cmd.Cmd):
Also handles BrokenPipeError exceptions for when a commands's output has been piped to another process and
that process terminates before the cmd2 command is finished executing.
- :param msg: str - message to print to current stdout - anyting convertible to a str with '{}'.format() is OK
+ :param msg: str - message to print to current stdout - anything convertible to a str with '{}'.format() is OK
:param end: str - string appended after the end of the message if not already present, default a newline
"""
if msg is not None and msg != '':