Browse Source

It works!

master
John ShaggyTwoDope Jenkins 4 years ago
parent
commit
2449eb0599
48 changed files with 282 additions and 108 deletions
  1. BIN
      ffmpeg-full/ffmpeg-full-1:2.6.2-1-x86_64.pkg.tar.xz
  2. BIN
      ffmpeg-full/pkg/ffmpeg-full/.MTREE
  3. 2
    2
      ffmpeg-full/pkg/ffmpeg-full/.PKGINFO
  4. 2
    2
      rtv/PKGBUILD
  5. BIN
      rtv/pkg/rtv/.MTREE
  6. 4
    4
      rtv/pkg/rtv/.PKGINFO
  7. 3
    3
      rtv/pkg/rtv/usr/bin/rtv
  8. 6
    2
      rtv/pkg/rtv/usr/lib/python3.4/site-packages/rtv-1.3-py3.4.egg-info/PKG-INFO
  9. 0
    0
      rtv/pkg/rtv/usr/lib/python3.4/site-packages/rtv-1.3-py3.4.egg-info/SOURCES.txt
  10. 0
    0
      rtv/pkg/rtv/usr/lib/python3.4/site-packages/rtv-1.3-py3.4.egg-info/dependency_links.txt
  11. 0
    0
      rtv/pkg/rtv/usr/lib/python3.4/site-packages/rtv-1.3-py3.4.egg-info/entry_points.txt
  12. 0
    0
      rtv/pkg/rtv/usr/lib/python3.4/site-packages/rtv-1.3-py3.4.egg-info/requires.txt
  13. 0
    0
      rtv/pkg/rtv/usr/lib/python3.4/site-packages/rtv-1.3-py3.4.egg-info/top_level.txt
  14. 3
    2
      rtv/pkg/rtv/usr/lib/python3.4/site-packages/rtv/__main__.py
  15. BIN
      rtv/pkg/rtv/usr/lib/python3.4/site-packages/rtv/__pycache__/__init__.cpython-34.pyc
  16. BIN
      rtv/pkg/rtv/usr/lib/python3.4/site-packages/rtv/__pycache__/__init__.cpython-34.pyo
  17. BIN
      rtv/pkg/rtv/usr/lib/python3.4/site-packages/rtv/__pycache__/__main__.cpython-34.pyc
  18. BIN
      rtv/pkg/rtv/usr/lib/python3.4/site-packages/rtv/__pycache__/__main__.cpython-34.pyo
  19. BIN
      rtv/pkg/rtv/usr/lib/python3.4/site-packages/rtv/__pycache__/__version__.cpython-34.pyc
  20. BIN
      rtv/pkg/rtv/usr/lib/python3.4/site-packages/rtv/__pycache__/__version__.cpython-34.pyo
  21. BIN
      rtv/pkg/rtv/usr/lib/python3.4/site-packages/rtv/__pycache__/config.cpython-34.pyc
  22. BIN
      rtv/pkg/rtv/usr/lib/python3.4/site-packages/rtv/__pycache__/config.cpython-34.pyo
  23. BIN
      rtv/pkg/rtv/usr/lib/python3.4/site-packages/rtv/__pycache__/content.cpython-34.pyc
  24. BIN
      rtv/pkg/rtv/usr/lib/python3.4/site-packages/rtv/__pycache__/content.cpython-34.pyo
  25. BIN
      rtv/pkg/rtv/usr/lib/python3.4/site-packages/rtv/__pycache__/curses_helpers.cpython-34.pyc
  26. BIN
      rtv/pkg/rtv/usr/lib/python3.4/site-packages/rtv/__pycache__/curses_helpers.cpython-34.pyo
  27. BIN
      rtv/pkg/rtv/usr/lib/python3.4/site-packages/rtv/__pycache__/docs.cpython-34.pyc
  28. BIN
      rtv/pkg/rtv/usr/lib/python3.4/site-packages/rtv/__pycache__/docs.cpython-34.pyo
  29. BIN
      rtv/pkg/rtv/usr/lib/python3.4/site-packages/rtv/__pycache__/exceptions.cpython-34.pyc
  30. BIN
      rtv/pkg/rtv/usr/lib/python3.4/site-packages/rtv/__pycache__/exceptions.cpython-34.pyo
  31. BIN
      rtv/pkg/rtv/usr/lib/python3.4/site-packages/rtv/__pycache__/helpers.cpython-34.pyc
  32. BIN
      rtv/pkg/rtv/usr/lib/python3.4/site-packages/rtv/__pycache__/helpers.cpython-34.pyo
  33. BIN
      rtv/pkg/rtv/usr/lib/python3.4/site-packages/rtv/__pycache__/page.cpython-34.pyc
  34. BIN
      rtv/pkg/rtv/usr/lib/python3.4/site-packages/rtv/__pycache__/page.cpython-34.pyo
  35. BIN
      rtv/pkg/rtv/usr/lib/python3.4/site-packages/rtv/__pycache__/submission.cpython-34.pyc
  36. BIN
      rtv/pkg/rtv/usr/lib/python3.4/site-packages/rtv/__pycache__/submission.cpython-34.pyo
  37. BIN
      rtv/pkg/rtv/usr/lib/python3.4/site-packages/rtv/__pycache__/subreddit.cpython-34.pyc
  38. BIN
      rtv/pkg/rtv/usr/lib/python3.4/site-packages/rtv/__pycache__/subreddit.cpython-34.pyo
  39. 1
    1
      rtv/pkg/rtv/usr/lib/python3.4/site-packages/rtv/__version__.py
  40. 22
    11
      rtv/pkg/rtv/usr/lib/python3.4/site-packages/rtv/content.py
  41. 27
    1
      rtv/pkg/rtv/usr/lib/python3.4/site-packages/rtv/curses_helpers.py
  42. 16
    4
      rtv/pkg/rtv/usr/lib/python3.4/site-packages/rtv/docs.py
  43. 143
    39
      rtv/pkg/rtv/usr/lib/python3.4/site-packages/rtv/page.py
  44. 35
    18
      rtv/pkg/rtv/usr/lib/python3.4/site-packages/rtv/submission.py
  45. 18
    19
      rtv/pkg/rtv/usr/lib/python3.4/site-packages/rtv/subreddit.py
  46. BIN
      rtv/rtv-1.3-1-any.pkg.tar.xz
  47. BIN
      rtv/rtv-1.3-1.src.tar.gz
  48. BIN
      rtv/v1.3.tar.gz

BIN
ffmpeg-full/ffmpeg-full-1:2.6.2-1-x86_64.pkg.tar.xz View File


BIN
ffmpeg-full/pkg/ffmpeg-full/.MTREE View File


+ 2
- 2
ffmpeg-full/pkg/ffmpeg-full/.PKGINFO View File

@@ -1,11 +1,11 @@
# Generated by makepkg 4.2.1
# using fakeroot version 1.20.2
# Sun Apr 19 16:34:37 UTC 2015
# Tue Apr 21 10:13:45 UTC 2015
pkgname = ffmpeg-full
pkgver = 1:2.6.2-1
pkgdesc = Complete and free Internet live audio and video broadcasting solution (with all options)
url = http://ffmpeg.org/
builddate = 1429461277
builddate = 1429611225
packager = Unknown Packager
size = 23196672
arch = x86_64

+ 2
- 2
rtv/PKGBUILD View File

@@ -1,7 +1,7 @@
# Maintainer: John Jenkins twodopeshaggy@gmail.com

pkgname=rtv
pkgver=1.2.2
pkgver=1.3
pkgrel=1
pkgdesc="Browse Reddit from your terminal"
arch=('any')
@@ -11,7 +11,7 @@ conflicts=('rtv-git')
makedepends=('git')
depends=('ncurses' 'python' 'python-six' 'python-requests' 'python-praw' 'python-setuptools')
source=(https://github.com/michael-lazar/rtv/archive/v$pkgver.tar.gz)
md5sums=('ae2cea2fdec3657611db625751ae36f1')
md5sums=('1ad33080c055565cbe1540539335d634')

package() {
cd "$srcdir/$pkgname-$pkgver"

BIN
rtv/pkg/rtv/.MTREE View File


+ 4
- 4
rtv/pkg/rtv/.PKGINFO View File

@@ -1,13 +1,13 @@
# Generated by makepkg 4.2.1
# using fakeroot version 1.20.2
# Wed Apr 8 02:49:04 UTC 2015
# Thu Apr 23 03:10:29 UTC 2015
pkgname = rtv
pkgver = 1.2.2-1
pkgver = 1.3-1
pkgdesc = Browse Reddit from your terminal
url = https://github.com/michael-lazar/rtv
builddate = 1428461344
builddate = 1429758629
packager = Unknown Packager
size = 231424
size = 247808
arch = any
license = MIT
conflict = rtv-git

+ 3
- 3
rtv/pkg/rtv/usr/bin/rtv View File

@@ -1,10 +1,10 @@
#!/bin/python
# EASY-INSTALL-ENTRY-SCRIPT: 'rtv==1.2.2','console_scripts','rtv'
__requires__ = 'rtv==1.2.2'
# EASY-INSTALL-ENTRY-SCRIPT: 'rtv==1.3','console_scripts','rtv'
__requires__ = 'rtv==1.3'
import sys
from pkg_resources import load_entry_point

if __name__ == '__main__':
sys.exit(
load_entry_point('rtv==1.2.2', 'console_scripts', 'rtv')()
load_entry_point('rtv==1.3', 'console_scripts', 'rtv')()
)

rtv/pkg/rtv/usr/lib/python3.4/site-packages/rtv-1.2.2-py3.4.egg-info/PKG-INFO → rtv/pkg/rtv/usr/lib/python3.4/site-packages/rtv-1.3-py3.4.egg-info/PKG-INFO View File

@@ -1,6 +1,6 @@
Metadata-Version: 1.1
Name: rtv
Version: 1.2.2
Version: 1.3
Summary: A simple terminal viewer for Reddit (Reddit Terminal Viewer)
Home-page: https://github.com/michael-lazar/rtv
Author: Michael Lazar
@@ -121,6 +121,9 @@ Description:
:``/``: Open a prompt to switch subreddits
:``f``: Open a prompt to search the current subreddit
:``p``: Post a new submission to the current subreddit
:``e``: Edit the selected submission
:``d``: Delete the selected submission
The ``/`` prompt accepts subreddits in the following formats
@@ -139,7 +142,8 @@ Description:
:``◄`` or ``h``: Return to subreddit mode
:``►`` or ``l``: Fold the selected comment, or load additional comments
:``c``: Post a new comment on the selected item
:``e``: Edit the selected comment
:``d``: Delete the selected comment
=========
Changelog

rtv/pkg/rtv/usr/lib/python3.4/site-packages/rtv-1.2.2-py3.4.egg-info/SOURCES.txt → rtv/pkg/rtv/usr/lib/python3.4/site-packages/rtv-1.3-py3.4.egg-info/SOURCES.txt View File


rtv/pkg/rtv/usr/lib/python3.4/site-packages/rtv-1.2.2-py3.4.egg-info/dependency_links.txt → rtv/pkg/rtv/usr/lib/python3.4/site-packages/rtv-1.3-py3.4.egg-info/dependency_links.txt View File


rtv/pkg/rtv/usr/lib/python3.4/site-packages/rtv-1.2.2-py3.4.egg-info/entry_points.txt → rtv/pkg/rtv/usr/lib/python3.4/site-packages/rtv-1.3-py3.4.egg-info/entry_points.txt View File


rtv/pkg/rtv/usr/lib/python3.4/site-packages/rtv-1.2.2-py3.4.egg-info/requires.txt → rtv/pkg/rtv/usr/lib/python3.4/site-packages/rtv-1.3-py3.4.egg-info/requires.txt View File


rtv/pkg/rtv/usr/lib/python3.4/site-packages/rtv-1.2.2-py3.4.egg-info/top_level.txt → rtv/pkg/rtv/usr/lib/python3.4/site-packages/rtv-1.3-py3.4.egg-info/top_level.txt View File


+ 3
- 2
rtv/pkg/rtv/usr/lib/python3.4/site-packages/rtv/__main__.py View File

@@ -19,7 +19,6 @@ from .__version__ import __version__

__all__ = []


def load_config():
"""
Search for a configuration file at the location ~/.rtv and attempt to load
@@ -98,13 +97,15 @@ def main():

config.unicode = args.unicode

# Squelch SSL warnings for Ubuntu
logging.captureWarnings(True)
if args.log:
logging.basicConfig(level=logging.DEBUG, filename=args.log)

try:
print('Connecting...')
reddit = praw.Reddit(user_agent=AGENT)
reddit.config.decode_html_entities = True
reddit.config.decode_html_entities = False
if args.username:
# PRAW will prompt for password if it is None
reddit.login(args.username, args.password)

BIN
rtv/pkg/rtv/usr/lib/python3.4/site-packages/rtv/__pycache__/__init__.cpython-34.pyc View File


BIN
rtv/pkg/rtv/usr/lib/python3.4/site-packages/rtv/__pycache__/__init__.cpython-34.pyo View File


BIN
rtv/pkg/rtv/usr/lib/python3.4/site-packages/rtv/__pycache__/__main__.cpython-34.pyc View File


BIN
rtv/pkg/rtv/usr/lib/python3.4/site-packages/rtv/__pycache__/__main__.cpython-34.pyo View File


BIN
rtv/pkg/rtv/usr/lib/python3.4/site-packages/rtv/__pycache__/__version__.cpython-34.pyc View File


BIN
rtv/pkg/rtv/usr/lib/python3.4/site-packages/rtv/__pycache__/__version__.cpython-34.pyo View File


BIN
rtv/pkg/rtv/usr/lib/python3.4/site-packages/rtv/__pycache__/config.cpython-34.pyc View File


BIN
rtv/pkg/rtv/usr/lib/python3.4/site-packages/rtv/__pycache__/config.cpython-34.pyo View File


BIN
rtv/pkg/rtv/usr/lib/python3.4/site-packages/rtv/__pycache__/content.cpython-34.pyc View File


BIN
rtv/pkg/rtv/usr/lib/python3.4/site-packages/rtv/__pycache__/content.cpython-34.pyo View File


BIN
rtv/pkg/rtv/usr/lib/python3.4/site-packages/rtv/__pycache__/curses_helpers.cpython-34.pyc View File


BIN
rtv/pkg/rtv/usr/lib/python3.4/site-packages/rtv/__pycache__/curses_helpers.cpython-34.pyo View File


BIN
rtv/pkg/rtv/usr/lib/python3.4/site-packages/rtv/__pycache__/docs.cpython-34.pyc View File


BIN
rtv/pkg/rtv/usr/lib/python3.4/site-packages/rtv/__pycache__/docs.cpython-34.pyo View File


BIN
rtv/pkg/rtv/usr/lib/python3.4/site-packages/rtv/__pycache__/exceptions.cpython-34.pyc View File


BIN
rtv/pkg/rtv/usr/lib/python3.4/site-packages/rtv/__pycache__/exceptions.cpython-34.pyo View File


BIN
rtv/pkg/rtv/usr/lib/python3.4/site-packages/rtv/__pycache__/helpers.cpython-34.pyc View File


BIN
rtv/pkg/rtv/usr/lib/python3.4/site-packages/rtv/__pycache__/helpers.cpython-34.pyo View File


BIN
rtv/pkg/rtv/usr/lib/python3.4/site-packages/rtv/__pycache__/page.cpython-34.pyc View File


BIN
rtv/pkg/rtv/usr/lib/python3.4/site-packages/rtv/__pycache__/page.cpython-34.pyo View File


BIN
rtv/pkg/rtv/usr/lib/python3.4/site-packages/rtv/__pycache__/submission.cpython-34.pyc View File


BIN
rtv/pkg/rtv/usr/lib/python3.4/site-packages/rtv/__pycache__/submission.cpython-34.pyo View File


BIN
rtv/pkg/rtv/usr/lib/python3.4/site-packages/rtv/__pycache__/subreddit.cpython-34.pyc View File


BIN
rtv/pkg/rtv/usr/lib/python3.4/site-packages/rtv/__pycache__/subreddit.cpython-34.pyo View File


+ 1
- 1
rtv/pkg/rtv/usr/lib/python3.4/site-packages/rtv/__version__.py View File

@@ -1 +1 @@
__version__ = '1.2.2'
__version__ = '1.3'

+ 22
- 11
rtv/pkg/rtv/usr/lib/python3.4/site-packages/rtv/content.py View File

@@ -1,4 +1,5 @@
import textwrap
import logging

import praw
import requests
@@ -8,6 +9,7 @@ from .helpers import humanize_timestamp, wrap_text, strip_subreddit_url

__all__ = ['SubredditContent', 'SubmissionContent']

_logger = logging.getLogger(__name__)

class BaseContent(object):

@@ -41,14 +43,22 @@ class BaseContent(object):
retval = []
while stack:
item = stack.pop(0)
if isinstance(item, praw.objects.MoreComments) and (
item.count == 0):
continue
nested = getattr(item, 'replies', None)
if nested:
for n in nested:
n.nested_level = item.nested_level + 1
stack[0:0] = nested
if isinstance(item, praw.objects.MoreComments):
if item.count == 0:
# MoreComments item count should never be zero, but if it
# is then discard the MoreComment object. Need to look into
# this further.
continue
else:
if item._replies is None:
# Attach children MoreComment replies to parents
# https://github.com/praw-dev/praw/issues/391
item._replies = [stack.pop(0)]
nested = getattr(item, 'replies', None)
if nested:
for n in nested:
n.nested_level = item.nested_level + 1
stack[0:0] = nested
retval.append(item)
return retval

@@ -109,6 +119,7 @@ class BaseContent(object):
data['url'] = ('selfpost' if is_selfpost(sub.url) else sub.url)
data['likes'] = sub.likes
data['gold'] = sub.gilded > 0
data['nsfw'] = sub.over_18

return data

@@ -119,7 +130,7 @@ class SubmissionContent(BaseContent):
list for repeat access.
"""

def __init__(self, submission, loader, indent_size=2, max_indent_level=4):
def __init__(self, submission, loader, indent_size=2, max_indent_level=8):

self.indent_size = indent_size
self.max_indent_level = max_indent_level
@@ -132,7 +143,7 @@ class SubmissionContent(BaseContent):
self._comment_data = [self.strip_praw_comment(c) for c in comments]

@classmethod
def from_url(cls, reddit, url, loader, indent_size=2, max_indent_level=4):
def from_url(cls, reddit, url, loader, indent_size=2, max_indent_level=8):

try:
with loader():
@@ -209,7 +220,7 @@ class SubmissionContent(BaseContent):

elif data['type'] == 'MoreComments':
with self._loader():
comments = data['object'].comments(update=False)
comments = data['object'].comments(update=True)
comments = self.flatten_comments(comments,
root_level=data['level'])
comment_data = [self.strip_praw_comment(c) for c in comments]

+ 27
- 1
rtv/pkg/rtv/usr/lib/python3.4/site-packages/rtv/curses_helpers.py View File

@@ -10,7 +10,8 @@ from .helpers import strip_textpad
from .exceptions import EscapeInterrupt

__all__ = ['ESCAPE', 'UARROW', 'DARROW', 'BULLET', 'show_notification',
'show_help', 'LoadScreen', 'Color', 'text_input', 'curses_session']
'show_help', 'LoadScreen', 'Color', 'text_input', 'curses_session',
'prompt_input']

ESCAPE = 27

@@ -235,6 +236,31 @@ def text_input(window, allow_resize=True):
return strip_textpad(out)


def prompt_input(window, prompt, hide=False):
"""
Display a prompt where the user can enter text at the bottom of the screen

Set hide to True to make the input text invisible.
"""

attr = curses.A_BOLD | Color.CYAN
n_rows, n_cols = window.getmaxyx()

if hide:
prompt += ' ' * (n_cols - len(prompt) - 1)
window.addstr(n_rows-1, 0, prompt, attr)
out = window.getstr(n_rows-1, 1)
else:
window.addstr(n_rows - 1, 0, prompt, attr)
window.refresh()
subwin = window.derwin(1, n_cols - len(prompt),
n_rows - 1, len(prompt))
subwin.attrset(attr)
out = text_input(subwin)

return out


@contextmanager
def curses_session():
"""

+ 16
- 4
rtv/pkg/rtv/usr/lib/python3.4/site-packages/rtv/docs.py View File

@@ -1,7 +1,7 @@
from .__version__ import __version__

__all__ = ['AGENT', 'SUMMARY', 'AUTH', 'CONTROLS', 'HELP', 'COMMENT_FILE',
'SUBMISSION_FILE']
'SUBMISSION_FILE', 'COMMENT_EDIT_FILE']

AGENT = """\
desktop:https://github.com/michael-lazar/rtv:{} (by /u/civilization_phaze_3)\
@@ -42,11 +42,16 @@ Subreddit Mode
`/` : Open a prompt to switch subreddits
`f` : Open a prompt to search the current subreddit
`p` : Post a new submission to the current subreddit
`e` : Edit the selected submission
`d` : Delete the selected submission

Submission Mode
`LEFT` or `h` : Return to subreddit mode
`RIGHT` or `l` : Fold the selected comment, or load additional comments
`c` : Post a new comment on the selected item
`e` : Edit the selected comment
`d` : Delete the selected comment

"""

COMMENT_FILE = """
@@ -57,12 +62,19 @@ COMMENT_FILE = """
{content}
"""

SUBMISSION_FILE = """
COMMENT_EDIT_FILE = """{content}
# Please enter a comment. Lines starting with '#' will be ignored,
# and an empty message aborts the comment.
#
# Editing your comment
"""

SUBMISSION_FILE = """{content}
# Please enter your submission. Lines starting with '#' will be ignored,
# and an empty field aborts the submission.
#
# The first line will be interpreted as the title
# The following lines will be interpreted as the content
#
# Posting to /r/{name}
"""
# Posting to {name}
"""

+ 143
- 39
rtv/pkg/rtv/usr/lib/python3.4/site-packages/rtv/page.py View File

@@ -1,15 +1,21 @@
import curses
import time
import six
import sys
import logging
from contextlib import contextmanager

import praw.errors
import requests

from .helpers import clean
from .curses_helpers import Color, show_notification, show_help, text_input
from .docs import AGENT
from .helpers import clean, open_editor
from .curses_helpers import (Color, show_notification, show_help, text_input,
prompt_input)
from .docs import COMMENT_EDIT_FILE, SUBMISSION_FILE

__all__ = ['Navigator']
__all__ = ['Navigator', 'BaseController', 'BasePage']

_logger = logging.getLogger(__name__)

class Navigator(object):
"""
@@ -101,6 +107,36 @@ class Navigator(object):
else:
return True

class SafeCaller(object):

def __init__(self, window):
self.window = window
self.catch = True

def __enter__(self):
return self

def __exit__(self, exc_type, e, exc_tb):

if self.catch:
if isinstance(e, praw.errors.APIException):
message = ['Error: {}'.format(e.error_type), e.message]
show_notification(self.window, message)
_logger.exception(e)
return True
elif isinstance(e, praw.errors.ClientException):
message = ['Error: Client Exception', e.message]
show_notification(self.window, message)
_logger.exception(e)
return True
elif isinstance(e, requests.HTTPError):
show_notification(self.window, ['Unexpected Error'])
_logger.exception(e)
return True
elif isinstance(e, requests.ConnectionError):
show_notification(self.window, ['Unexpected Error'])
_logger.exception(e)
return True

class BaseController(object):
"""
@@ -170,6 +206,13 @@ class BasePage(object):
self._content_window = None
self._subwindows = None

def refresh_content(self):
raise NotImplementedError

@staticmethod
def draw_item(window, data, inverted):
raise NotImplementedError

@BaseController.register('q')
def exit(self):
sys.exit()
@@ -188,14 +231,6 @@ class BasePage(object):
self._move_cursor(1)
self.clear_input_queue()

def clear_input_queue(self):
"Clear excessive input caused by the scroll wheel or holding down a key"

self.stdscr.nodelay(1)
while self.stdscr.getch() != -1:
continue
self.stdscr.nodelay(0)

@BaseController.register('a')
def upvote(self):
data = self.content.get(self.nav.absolute_index)
@@ -237,49 +272,122 @@ class BasePage(object):
self.logout()
return

username = self.prompt_input('Enter username:')
password = self.prompt_input('Enter password:', hide=True)
username = prompt_input(self.stdscr, 'Enter username:')
password = prompt_input(self.stdscr, 'Enter password:', hide=True)
if not username or not password:
curses.flash()
return

try:
with self.loader():
with self.loader(message='Logging in'):
self.reddit.login(username, password)
except praw.errors.InvalidUserPass:
show_notification(self.stdscr, ['Invalid user/pass'])
else:
show_notification(self.stdscr, ['Welcome {}'.format(username)])

@BaseController.register('d')
def delete(self):
"""
Delete a submission or comment.
"""

if not self.reddit.is_logged_in():
show_notification(self.stdscr, ['Not logged in'])
return

data = self.content.get(self.nav.absolute_index)
if data.get('author') != self.reddit.user.name:
curses.flash()
return

prompt = 'Are you sure you want to delete this? (y/n):'
char = prompt_input(self.stdscr, prompt)
if char != 'y':
show_notification(self.stdscr, ['Aborted'])
return

with self.safe_call as s:
with self.loader(message='Deleting', delay=0):
data['object'].delete()
time.sleep(2.0)
s.catch = False
self.refresh_content()

@BaseController.register('e')
def edit(self):
"""
Edit a submission or comment.
"""

if not self.reddit.is_logged_in():
show_notification(self.stdscr, ['Not logged in'])
return

data = self.content.get(self.nav.absolute_index)
if data.get('author') != self.reddit.user.name:
curses.flash()
return

if data['type'] == 'Submission':
subreddit = self.reddit.get_subreddit(self.content.name)
content = data['text']
info = SUBMISSION_FILE.format(content=content, name=subreddit)
elif data['type'] == 'Comment':
content = data['body']
info = COMMENT_EDIT_FILE.format(content=content)
else:
curses.flash()
return

curses.endwin()
text = open_editor(info)
curses.doupdate()
if text == content:
show_notification(self.stdscr, ['Aborted'])
return

with self.safe_call as s:
with self.loader(message='Editing', delay=0):
data['object'].edit(text)
time.sleep(2.0)
s.catch = False
self.refresh_content()

def clear_input_queue(self):
"Clear excessive input caused by the scroll wheel or holding down a key"

self.stdscr.nodelay(1)
while self.stdscr.getch() != -1:
continue
self.stdscr.nodelay(0)

def logout(self):
"Prompt to log out of the user's account."

ch = self.prompt_input("Log out? (y/n):")
ch = prompt_input(self.stdscr, "Log out? (y/n):")
if ch == 'y':
self.reddit.clear_authentication()
show_notification(self.stdscr, ['Logged out'])
elif ch != 'n':
curses.flash()

def prompt_input(self, prompt, hide=False):
"Prompt the user for input"

attr = curses.A_BOLD | Color.CYAN
n_rows, n_cols = self.stdscr.getmaxyx()

if hide:
prompt += ' ' * (n_cols - len(prompt) - 1)
self.stdscr.addstr(n_rows-1, 0, prompt, attr)
out = self.stdscr.getstr(n_rows-1, 1)
else:
self.stdscr.addstr(n_rows - 1, 0, prompt, attr)
self.stdscr.refresh()
window = self.stdscr.derwin(1, n_cols - len(prompt),
n_rows - 1, len(prompt))
window.attrset(attr)
out = text_input(window)

return out
@property
def safe_call(self):
"""
Wrap praw calls with extended error handling.
If a PRAW related error occurs inside of this context manager, a
notification will be displayed on the screen instead of the entire
application shutting down. This function will return a callback that
can be used to check the status of the call.

Usage:
#>>> with self.safe_call as s:
#>>> self.reddit.submit(...)
#>>> s.catch = False
#>>> on_success()
"""
return SafeCaller(self.stdscr)

def draw(self):

@@ -296,10 +404,6 @@ class BasePage(object):
self._draw_content()
self._add_cursor()

@staticmethod
def draw_item(window, data, inverted):
raise NotImplementedError

def _draw_header(self):

n_rows, n_cols = self._header_window.getmaxyx()

+ 35
- 18
rtv/pkg/rtv/usr/lib/python3.4/site-packages/rtv/submission.py View File

@@ -89,7 +89,7 @@ class SubmissionPage(BasePage):
"""

if not self.reddit.is_logged_in():
show_notification(self.stdscr, ['Login to post'])
show_notification(self.stdscr, ['Not logged in'])
return

data = self.content.get(self.nav.absolute_index)
@@ -112,26 +112,28 @@ class SubmissionPage(BasePage):
comment_text = open_editor(comment_info)
curses.doupdate()
if not comment_text:
show_notification(self.stdscr, ['Comment canceled'])
show_notification(self.stdscr, ['Aborted'])
return

try:
if data['type'] == 'Submission':
data['object'].add_comment(comment_text)
else:
data['object'].reply(comment_text)
except praw.errors.APIException as e:
message = ['Error: {}'.format(e.error_type), e.message]
show_notification(self.stdscr, message)
_logger.exception(e)
except requests.HTTPError as e:
show_notification(self.stdscr, ['Unexpected Error'])
_logger.exception(e)
else:
with self.loader(delay=0, message='Posting'):
with self.safe_call as s:
with self.loader(message='Posting', delay=0):
if data['type'] == 'Submission':
data['object'].add_comment(comment_text)
else:
data['object'].reply(comment_text)
time.sleep(2.0)
s.catch = False
self.refresh_content()

@SubmissionController.register('d')
def delete_comment(self):
"Delete a comment as long as it is not the current submission"

if self.nav.absolute_index != -1:
self.delete()
else:
curses.flash()

def draw_item(self, win, data, inverted=False):

if data['type'] == 'MoreComments':
@@ -258,11 +260,26 @@ class SubmissionPage(BasePage):
win.addnstr(row, 1, text, n_cols)

row = len(data['split_title']) + len(split_text) + 3
text = clean(u'{score} {comments} '.format(**data))
win.addnstr(row, 1, text, n_cols, curses.A_BOLD)
text = clean(u'{score} '.format(**data))
win.addnstr(row, 1, text, n_cols - 1)

if data['likes'] is None:
text, attr = BULLET, curses.A_BOLD
elif data['likes']:
text, attr = UARROW, curses.A_BOLD | Color.GREEN
else:
text, attr = DARROW, curses.A_BOLD | Color.RED
win.addnstr(text, n_cols - win.getyx()[1], attr)

text = clean(u' {comments} '.format(**data))
win.addnstr(text, n_cols - win.getyx()[1])

if data['gold']:
text, attr = GOLD, (curses.A_BOLD | Color.YELLOW)
win.addnstr(text, n_cols - win.getyx()[1], attr)

if data['nsfw']:
text, attr = 'NSFW', (curses.A_BOLD | Color.RED)
win.addnstr(text, n_cols - win.getyx()[1], attr)

win.border()

+ 18
- 19
rtv/pkg/rtv/usr/lib/python3.4/site-packages/rtv/subreddit.py View File

@@ -12,7 +12,7 @@ from .content import SubredditContent
from .helpers import clean, open_browser, open_editor
from .docs import SUBMISSION_FILE
from .curses_helpers import (BULLET, UARROW, DARROW, GOLD, Color,
LoadScreen, show_notification)
LoadScreen, show_notification, prompt_input)

__all__ = ['opened_links', 'SubredditController', 'SubredditPage']

@@ -67,7 +67,7 @@ class SubredditPage(BasePage):

name = name or self.content.name
prompt = 'Search {}:'.format(name)
query = self.prompt_input(prompt)
query = prompt_input(self.stdscr, prompt)
if query is None:
return

@@ -83,7 +83,7 @@ class SubredditPage(BasePage):
def prompt_subreddit(self):
"Open a prompt to navigate to a different subreddit"
prompt = 'Enter Subreddit: /r/'
name = self.prompt_input(prompt)
name = prompt_input(self.stdscr, prompt)
if name is not None:
self.refresh_content(name=name)

@@ -114,7 +114,7 @@ class SubredditPage(BasePage):
"Post a new submission to the given subreddit"

if not self.reddit.is_logged_in():
show_notification(self.stdscr, ['Login to post'])
show_notification(self.stdscr, ['Not logged in'])
return

# Strips the subreddit to just the name
@@ -126,33 +126,28 @@ class SubredditPage(BasePage):
return

# Open the submission window
submission_info = SUBMISSION_FILE.format(name=sub)
submission_info = SUBMISSION_FILE.format(name=subreddit, content='')
curses.endwin()
submission_text = open_editor(submission_info)
curses.doupdate()

# Validate the submission content
if not submission_text:
show_notification(self.stdscr, ['Post canceled'])
show_notification(self.stdscr, ['Aborted'])
return

if '\n' not in submission_text:
show_notification(self.stdscr, ['No content'])
return

try:
title, content = submission_text.split('\n', 1)
self.reddit.submit(sub, title, text=content)
except praw.errors.APIException as e:
message = ['Error: {}'.format(e.error_type), e.message]
show_notification(self.stdscr, message)
_logger.exception(e)
except requests.HTTPError as e:
show_notification(self.stdscr, ['Unexpected Error'])
_logger.exception(e)
else:
with self.loader(delay=0, message='Posting'):
title, content = submission_text.split('\n', 1)
with self.safe_call as s:
with self.loader(message='Posting', delay=0):
post = self.reddit.submit(sub, title, text=content)
time.sleep(2.0)
# Open the newly created post
s.catch = False
page = SubmissionPage(self.stdscr, self.reddit, submission=post)
page.loop()
self.refresh_content()

@staticmethod
@@ -199,6 +194,10 @@ class SubredditPage(BasePage):
text, attr = GOLD, (curses.A_BOLD | Color.YELLOW)
win.addnstr(text, n_cols - win.getyx()[1], attr)

if data['nsfw']:
text, attr = 'NSFW', (curses.A_BOLD | Color.RED)
win.addnstr(text, n_cols - win.getyx()[1], attr)

row = n_title + offset + 2
if row in valid_rows:
text = clean(u'{author}'.format(**data))

BIN
rtv/rtv-1.3-1-any.pkg.tar.xz View File


BIN
rtv/rtv-1.3-1.src.tar.gz View File


BIN
rtv/v1.3.tar.gz View File


Loading…
Cancel
Save