Skip to content
This repository has been archived by the owner on Feb 20, 2023. It is now read-only.

Commit

Permalink
Squashed commit of the following:
Browse files Browse the repository at this point in the history
    Updated the supported python versions list.
    Fixed regression in displaying xposts. #173.
    Fixing a few style things.
    Added a more robust test for the tornado handler.
    Trying without pytest-cov
    Updated travis for coverage.
    Remove python 3.2 support because no unicode literals, following what praw supports.
    "Side effect is not iterable."
    Added requirements for travis.
    Renamed travis file correctly.
    Adding test configurations, got tox working.
    Adding vcr cassettes to the repo.
    Renamed requirements files.
    Split up tests and cleaned up test names.
    Tests done, still one failure.
    Treat cassettes as binary to prevent bad merging.
    Fixed a few broken tests.
    Added a timeout to notifications.
    Prepping subreddit page.
    Finished submission page tests.
    Working on submission tests.
    Fixed vcr matching on urls with params, started submission tests.
    Log cleanup.
    Still trying to fix a broken test.
    -Fixed a few pytest bugs and tweaked logging.
    Still working on subscription tests.
    Finished page tests, on to subscription page.
    Finished content tests and starting page tests.
    Added the test refresh-token file to gitignore.
    Moved functional test file out of the repository.
    Continuing work on subreddit content tests.
    Tests now match module names, cassettes are split into individual tests for faster loading.
    Linter fixes.
    Cleanup.
    Added support for nested loaders.
    Added pytest options, starting subreddit content tests.
    Back on track with loader, continuing content tests.
    Finishing submission content tests and discovered snag with loader exception handling.
    VCR up and running, continuing to implement content tests.
    Playing around with vcr.py
    Moved helper functions into terminal and new objects.py
    Fixed a few broken tests.
    Working on navigator tests.
    Reorganizing some things.
    Mocked webbrowser._tryorder for terminal test.
    Completed oauth tests.
    Progress on the oauth tests.
    Working on adding fake tornado request.
    Starting on OAuth tool tests.
    Finished curses helpers tests.
    Still working on curses helpers tests.
    Almost finished with tests on curses helpers.
    Adding tests and working on mocking stdscr.
    Starting to add tests for curses functions.
    Merge branch 'future_work' of https://github.com/michael-lazar/rtv into future_work
    Refactoring controller, still in progress.
    Renamed auth handler.
    Rename CursesHelper to CursesBase.
    Added temporary file with a possible template for func testing.
    Mixup between basename and dirname.
    Merge branch 'future_work' of https://github.com/michael-lazar/rtv into future_work
    py3 compatability for mock.
    Beginning to refactor the curses session.
    Started adding tests, improved unicode handling in the config.
    Cleanup, fixed a few typos.
    Major refactor, almost done!.
    Started a config class.
    Merge branch 'master' into future_work
    The editor now handles unicode characters in all situations.
    Fixed a few typos from previous commits.
    __main__.py formatting.
    Cleaned up history logic and moved to the config file.
  • Loading branch information
michael-lazar committed Dec 3, 2015
1 parent b91bb86 commit a7b789b
Show file tree
Hide file tree
Showing 70 changed files with 42,149 additions and 1,568 deletions.
3 changes: 3 additions & 0 deletions .coveragerc
@@ -0,0 +1,3 @@
[run]
source = rtv
omit = *__main__.py
1 change: 1 addition & 0 deletions .gitattributes
@@ -0,0 +1 @@
tests/cassettes/* binary
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -4,3 +4,4 @@
build
dist
rtv.egg-info
tests/refresh-token
15 changes: 15 additions & 0 deletions .travis.yml
@@ -0,0 +1,15 @@
language: python
python:
- "2.7"
- "3.3"
- "3.4"
- "3.5"
before_install:
- pip install coveralls pytest coverage mock
- pip install git+https://github.com/kevin1024/vcrpy.git
install:
- pip install .
script:
- coverage run -m py.test -v
after_success:
- coveralls
6 changes: 0 additions & 6 deletions requirements.py2.txt

This file was deleted.

5 changes: 0 additions & 5 deletions requirements.py3.txt

This file was deleted.

3 changes: 3 additions & 0 deletions rtv/__init__.py
@@ -1,3 +1,6 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from .__version__ import __version__

__title__ = 'Reddit Terminal Viewer'
Expand Down
100 changes: 54 additions & 46 deletions rtv/__main__.py
@@ -1,22 +1,21 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

import sys
import locale
import logging

import praw
import praw.errors
import tornado
from requests import exceptions

from . import config
from .exceptions import RTVError
from .curses_helpers import curses_session, LoadScreen
from .submission import SubmissionPage
from . import docs
from .config import Config
from .oauth import OAuthHelper
from .terminal import Terminal
from .objects import curses_session
from .subreddit import SubredditPage
from .docs import AGENT
from .oauth import OAuthTool
from .__version__ import __version__

__all__ = []
_logger = logging.getLogger(__name__)

# Pycharm debugging note:
Expand All @@ -35,57 +34,66 @@ def main():
locale.setlocale(locale.LC_ALL, '')

# Set the terminal title
# TODO: Need to clear the title when the program exits
title = 'rtv {0}'.format(__version__)
sys.stdout.write("\x1b]2;{0}\x07".format(title))

# Fill in empty arguments with config file values. Parameters explicitly
# typed on the command line will take priority over config file params.
parser = config.build_parser()
args = parser.parse_args()

local_config = config.load_config()
for key, val in local_config.items():
if getattr(args, key, None) is None:
setattr(args, key, val)

if args.ascii:
config.unicode = False
if not args.persistent:
config.persistent = False
if args.clear_auth:
config.clear_refresh_token()

if args.log:
logging.basicConfig(level=logging.DEBUG, filename=args.log)
sys.stdout.write('\x1b]2;{0}\x07'.format(title))

# Attempt to load from the config file first, and then overwrite with any
# provided command line arguments.
config = Config()
config.from_file()
config.from_args()

# Load the browsing history from previous sessions
config.load_history()

# Load any previously saved auth session token
config.load_refresh_token()
if config['clear_auth']:
config.delete_refresh_token()

if config['log']:
logging.basicConfig(level=logging.DEBUG, filename=config['log'])
else:
# Add an empty handler so the logger doesn't complain
logging.root.addHandler(logging.NullHandler())

# Construct the reddit user agent
user_agent = docs.AGENT.format(version=__version__)

try:
print('Connecting...')
reddit = praw.Reddit(user_agent=AGENT.format(version=__version__))
reddit.config.decode_html_entities = False
with curses_session() as stdscr:
oauth = OAuthTool(reddit, stdscr, LoadScreen(stdscr))
if oauth.refresh_token:
term = Terminal(stdscr, config['ascii'])
with term.loader(catch_exception=False):
reddit = praw.Reddit(
user_agent=user_agent,
decode_html_entities=False,
disable_update_check=True)

# Authorize on launch if the refresh token is present
oauth = OAuthHelper(reddit, term, config)
if config.refresh_token:
oauth.authorize()

if args.link:
page = SubmissionPage(stdscr, reddit, oauth, url=args.link)
page.loop()
subreddit = args.subreddit or 'front'
page = SubredditPage(stdscr, reddit, oauth, subreddit)
with term.loader():
page = SubredditPage(
reddit, term, config, oauth,
name=config['subreddit'], url=config['link'])
if term.loader.exception:
return

page.loop()
except (exceptions.RequestException, praw.errors.PRAWException,
RTVError) as e:
except Exception as e:
_logger.exception(e)
print('{}: {}'.format(type(e).__name__, e))
raise
except KeyboardInterrupt:
pass
finally:
# Try to save the browsing history
config.save_history()
# Ensure sockets are closed to prevent a ResourceWarning
reddit.handler.http.close()
if 'reddit' in locals():
reddit.handler.http.close()
# Explicitly close file descriptors opened by Tornado's IOLoop
tornado.ioloop.IOLoop.current().close(all_fds=True)

sys.exit(main())
sys.exit(main())
3 changes: 3 additions & 0 deletions rtv/__version__.py
@@ -1 +1,4 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

__version__ = '1.6.1'

0 comments on commit a7b789b

Please sign in to comment.