From de1d06e33c7247ba9159d11e5d51fb72201622e5 Mon Sep 17 00:00:00 2001 From: John Helmert Date: Thu, 6 Jun 2019 19:31:42 -0500 Subject: [PATCH 1/4] Replace deprecated ConfigParser method ConfigParser.readfp() -> ConfigParser.read_file() --- rtv/config.py | 2 +- rtv/theme.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/rtv/config.py b/rtv/config.py index daef147..fb2def4 100644 --- a/rtv/config.py +++ b/rtv/config.py @@ -250,7 +250,7 @@ class Config(object): config = configparser.ConfigParser() if os.path.exists(filename): with codecs.open(filename, encoding='utf-8') as fp: - config.readfp(fp) + config.read_file(fp) return cls._parse_rtv_file(config) diff --git a/rtv/theme.py b/rtv/theme.py index 2f8329b..f3f7633 100644 --- a/rtv/theme.py +++ b/rtv/theme.py @@ -399,7 +399,7 @@ class Theme(object): config = configparser.ConfigParser() config.optionxform = six.text_type # Preserve case with codecs.open(filename, encoding='utf-8') as fp: - config.readfp(fp) + config.read_file(fp) except configparser.ParsingError as e: raise ConfigError(e.message) From e545c7052c7d7f4f0ed654e6279f43a247f32a54 Mon Sep 17 00:00:00 2001 From: John Helmert Date: Fri, 7 Jun 2019 11:39:09 -0500 Subject: [PATCH 2/4] Fix Github issue #695 Caused by Page.move_to_bottom() setting self.nav.page_index to -1, only possible when there are no comments on a submission, but which also caused a crash when rendering. --- rtv/page.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/rtv/page.py b/rtv/page.py index bf21377..f9ab5bd 100644 --- a/rtv/page.py +++ b/rtv/page.py @@ -236,6 +236,12 @@ class Page(object): """ Move the cursor to the last item on the page. """ + + # If the page is empty, don't try to go to the bottom, rtv will + # crash when rendering + if self.content.range[1] < 0: + return + self.nav.page_index = self.content.range[1] self.nav.cursor_index = 0 self.nav.inverted = True From 7423a43e5094f027a1fb0504743ce08ad4063935 Mon Sep 17 00:00:00 2001 From: John Helmert Date: Sat, 8 Jun 2019 15:18:15 -0500 Subject: [PATCH 3/4] Make the clipboard command user-configurable Add config item clipboard_cmd, with a default of 'pbcopy w' on Darwin and 'xclip' on everything else. This will allow the user to use any command for the clipboard, including 'wl-copy' for Wayland (addressing issue #693 on Github). With his change, significant simplifications could be made to clipboard.py - the copy_*() functions have been removed and combined into copy(). With this simplification, the old OSX test is obsolete, and new OSX tests are needed (need a way to simulate sys.platform). --- rtv/clipboard.py | 44 +++++++++-------------------------------- rtv/page.py | 2 +- rtv/templates/rtv.cfg | 6 ++++++ tests/test_clipboard.py | 19 ++++++------------ 4 files changed, 22 insertions(+), 49 deletions(-) diff --git a/rtv/clipboard.py b/rtv/clipboard.py index 4194b4c..a1e581a 100644 --- a/rtv/clipboard.py +++ b/rtv/clipboard.py @@ -4,48 +4,22 @@ from __future__ import unicode_literals import sys import subprocess -from .exceptions import ProgramError - - def _subprocess_copy(text, args_list): p = subprocess.Popen(args_list, stdin=subprocess.PIPE, close_fds=True) p.communicate(input=text.encode('utf-8')) -def copy(text): +def copy(text, cmd): """ Copy text to OS clipboard. """ - if sys.platform == 'darwin': - copy_osx(text) - else: - # For Linux, BSD, cygwin, etc. - copy_linux(text) + # If no command is specified (i.e. the config option is empty) try + # to find a reasonable default based on the operating system + if cmd is None: + if sys.platform == 'darwin': + cmd = 'pbcopy w' + else: # For Linux, BSD, cygwin, etc. + cmd = 'xclip' - -def copy_osx(text): - _subprocess_copy(text, ['pbcopy', 'w']) - - -def copy_linux(text): - - def get_command_name(): - # Checks for the installation of xsel or xclip - for cmd in ['xsel', 'xclip']: - cmd_exists = subprocess.call( - ['which', cmd], - stdout=subprocess.PIPE, stderr=subprocess.PIPE) == 0 - if cmd_exists: - return cmd - return None - - cmd_args = { - 'xsel': ['xsel', '-b', '-i'], - 'xclip': ['xclip', '-selection', 'c']} - cmd_name = get_command_name() - - if cmd_name is None: - raise ProgramError("External copy application not found") - - _subprocess_copy(text, cmd_args.get(cmd_name)) + _subprocess_copy(text, cmd.split()) diff --git a/rtv/page.py b/rtv/page.py index f9ab5bd..cfe4b28 100644 --- a/rtv/page.py +++ b/rtv/page.py @@ -542,7 +542,7 @@ class Page(object): return try: - clipboard_copy(url) + clipboard_copy(url, self.config['clipboard_cmd']) except (ProgramError, OSError) as e: _logger.exception(e) self.term.show_notification( diff --git a/rtv/templates/rtv.cfg b/rtv/templates/rtv.cfg index 3cca8a2..7b41489 100644 --- a/rtv/templates/rtv.cfg +++ b/rtv/templates/rtv.cfg @@ -16,6 +16,12 @@ ascii = False ; Turn on monochrome mode to disable color. monochrome = False +; Data being copied is piped into this command +;clipboard_cmd = xclip +;clipboard_cmd = xsel -b -i +;clipboard_cmd = wl-copy +;clipboard_cmd = pbcopy w + ; Flash when an invalid action is executed. flash = True diff --git a/tests/test_clipboard.py b/tests/test_clipboard.py index ed84eef..7dc77df 100644 --- a/tests/test_clipboard.py +++ b/tests/test_clipboard.py @@ -3,7 +3,7 @@ from __future__ import unicode_literals import pytest -from rtv.clipboard import copy_linux, copy_osx +from rtv.clipboard import copy from rtv.exceptions import ProgramError @@ -23,20 +23,13 @@ def test_copy(): p.communicate = mock.Mock() Popen.return_value = p - # If the `which` command can't find a program to use - call.return_value = 1 # Returns an error code - with pytest.raises(ProgramError): - copy_linux('test') - call.return_value = 0 - copy_linux('test') + copy('test', 'xsel -b -i') assert Popen.call_args[0][0] == ['xsel', '-b', '-i'] p.communicate.assert_called_with(input='test'.encode('utf-8')) - copy_linux('test ❤') + + copy('test ❤', 'xclip') + assert Popen.call_args[0][0] == ['xclip'] p.communicate.assert_called_with(input='test ❤'.encode('utf-8')) - copy_osx('test') - assert Popen.call_args[0][0] == ['pbcopy', 'w'] - p.communicate.assert_called_with(input='test'.encode('utf-8')) - copy_osx('test ❤') - p.communicate.assert_called_with(input='test ❤'.encode('utf-8')) + # Need OSX tests, can't simulate sys.platform From 1c0afc8a559abb0bb03a864b422d86c9e4447215 Mon Sep 17 00:00:00 2001 From: John Helmert Date: Sun, 9 Jun 2019 11:05:37 -0500 Subject: [PATCH 4/4] More adjustments for new maintainership --- CONTRIBUTING.rst | 2 +- rtv.1 | 5 +++-- rtv/__main__.py | 2 +- rtv/docs.py | 4 ++-- rtv/templates/index.html | 2 +- rtv/templates/mailcap | 2 +- rtv/templates/rtv.cfg | 2 +- scripts/rtv.1.template | 3 ++- setup.py | 6 +++--- tests/test_terminal.py | 4 ++-- 10 files changed, 17 insertions(+), 15 deletions(-) diff --git a/CONTRIBUTING.rst b/CONTRIBUTING.rst index 7e06784..217555a 100644 --- a/CONTRIBUTING.rst +++ b/CONTRIBUTING.rst @@ -5,7 +5,7 @@ Contributor Guidelines Before you start ================ -- Post an issue on the `tracker `_ describing the bug or feature you would like to add +- Post an issue on the `tracker `_ describing the bug or feature you would like to add - If an issue already exists, leave a comment to let others know that you intend to work on it Considerations diff --git a/rtv.1 b/rtv.1 index 7b100f1..7f94db4 100644 --- a/rtv.1 +++ b/rtv.1 @@ -1,4 +1,4 @@ -.TH "RTV" "1" "June 03, 2019" "Version 1.27.0" "Usage and Commands" +.TH "RTV" "1" "June 08, 2019" "Version 1.27.0" "Usage and Commands" .SH NAME RTV - Reddit Terminal Viewer .SH SYNOPSIS @@ -113,7 +113,8 @@ program to be installed. Web browser to use when opening links. Will fallback to \fI$BROWSER\fR. .SH AUTHOR Michael Lazar (2017). +John Helmert (2019). .SH BUGS -Report bugs to \fIhttps://github.com/michael-lazar/rtv/issues\fR +Report bugs to \fIhttps://gitlab.com/ajak/rtv/issues\fR .SH LICENSE The MIT License (MIT) diff --git a/rtv/__main__.py b/rtv/__main__.py index 2992d8f..a0b050a 100755 --- a/rtv/__main__.py +++ b/rtv/__main__.py @@ -264,7 +264,7 @@ def main(): debug_text, traceback.format_exc(), 'rtv has crashed. Please report this traceback at:', - 'https://github.com/michael-lazar/rtv/issues\n']) + 'https://gitlab.com/ajak/rtv/issues\n']) sys.stderr.write(exit_message) return 1 # General error exception code except KeyboardInterrupt: diff --git a/rtv/docs.py b/rtv/docs.py index b935f15..bdbc51b 100644 --- a/rtv/docs.py +++ b/rtv/docs.py @@ -2,7 +2,7 @@ from __future__ import unicode_literals AGENT = """\ -desktop:https://github.com/michael-lazar/rtv:{version}\ +desktop:https://github.com/ajak/rtv:{version}\ (by /u/civilization_phaze_3)\ """ @@ -26,7 +26,7 @@ HELP = """\ ==================================== Reddit Terminal Viewer -https://github.com/michael-lazar/rtv +https://github.com/ajak/rtv ==================================== [Basic Commands] diff --git a/rtv/templates/index.html b/rtv/templates/index.html index 20a0987..4a3e26a 100644 --- a/rtv/templates/index.html +++ b/rtv/templates/index.html @@ -26,6 +26,6 @@ ${message} - + diff --git a/rtv/templates/mailcap b/rtv/templates/mailcap index 9c6a9d5..61e8c1d 100644 --- a/rtv/templates/mailcap +++ b/rtv/templates/mailcap @@ -1,5 +1,5 @@ # Example mailcap file for Reddit Terminal Viewer -# https://github.com/michael-lazar/rtv/ +# https://gitlab.com/ajak/rtv/ # # Copy the contents of this file to {HOME}/.mailcap, or point to it using $MAILCAPS # Then launch RTV using the --enable-media flag. All shell commands defined in diff --git a/rtv/templates/rtv.cfg b/rtv/templates/rtv.cfg index 7b41489..7663164 100644 --- a/rtv/templates/rtv.cfg +++ b/rtv/templates/rtv.cfg @@ -1,5 +1,5 @@ ; Reddit Terminal Viewer Configuration File -; https://github.com/michael-lazar/rtv +; https://gitlab.com/ajak/rtv ; ; This file should be placed in $XDG_CONFIG/rtv/rtv.cfg ; If $XDG_CONFIG is not set, use ~/.config/rtv/rtv.cfg diff --git a/scripts/rtv.1.template b/scripts/rtv.1.template index c743d9b..9c36dc6 100644 --- a/scripts/rtv.1.template +++ b/scripts/rtv.1.template @@ -41,7 +41,8 @@ program to be installed. Web browser to use when opening links. Will fallback to \fI$BROWSER\fR. .SH AUTHOR Michael Lazar (2017). +John Helmert (2019). .SH BUGS -Report bugs to \fIhttps://github.com/michael-lazar/rtv/issues\fR +Report bugs to \fIhttps://gitlab.com/ajak/rtv/issues\fR .SH LICENSE {license} diff --git a/setup.py b/setup.py index c2beb54..5171bc5 100644 --- a/setup.py +++ b/setup.py @@ -49,9 +49,9 @@ setuptools.setup( description='A simple terminal viewer for Reddit (Reddit Terminal Viewer)', long_description=long_description(), long_description_content_type='text/markdown', - url='https://github.com/michael-lazar/rtv', - author='Michael Lazar', - author_email='lazar.michael22@gmail.com', + url='https://gitlab.com/ajak/rtv', + author='John Helmert III', + author_email='jchelmertt3@gmail.com', license='MIT', keywords='reddit terminal praw curses', packages=[ diff --git a/tests/test_terminal.py b/tests/test_terminal.py index dbea2ca..d3dda17 100644 --- a/tests/test_terminal.py +++ b/tests/test_terminal.py @@ -738,7 +738,7 @@ def test_terminal_get_link_page_text(terminal): {'href': 'https://www.reddit.com', 'text': 'Reddit Homepage'}, {'href': 'https://www.duckduckgo.com', 'text': 'Search Engine'}, { - 'href': 'https://github.com/michael-lazar/rtv', + 'href': 'https://gitlab.com/ajak/rtv', 'text': 'This project\'s homepage' } ] @@ -747,7 +747,7 @@ def test_terminal_get_link_page_text(terminal): assert text == dedent("""\ [0] [Reddit Homepage](https://www.reddit.com) [1] [Search Engine](https://www.duckduckgo.com) - [2] [This project's home…](https://github.com/michael-lazar/rtv) + [2] [This project's home…](https://gitlab.com/ajak/rtv) """)