Skip to content

Commit

Permalink
Added Python 3 support to archelonc
Browse files Browse the repository at this point in the history
  • Loading branch information
carsongee committed Aug 22, 2015
1 parent 5ab98c6 commit 02e81f8
Show file tree
Hide file tree
Showing 13 changed files with 33 additions and 34 deletions.
1 change: 1 addition & 0 deletions archelonc/archelonc/__init__.py
Expand Up @@ -2,5 +2,6 @@
"""
Client for Web enabled shell history
"""
from __future__ import unicode_literals

VERSION = '0.5.0'
8 changes: 4 additions & 4 deletions archelonc/archelonc/command.py
Expand Up @@ -2,7 +2,7 @@
"""
Command line entry points for the archelon client.
"""
from __future__ import print_function
from __future__ import print_function, absolute_import, unicode_literals
from difflib import Differ
import os
import shutil
Expand Down Expand Up @@ -70,14 +70,14 @@ def update():
commands[diff[2:-1]] = None

# Warn if we are doing a large upload
num_commands = len(commands.keys())
num_commands = len(list(commands.keys()))
if num_commands > LARGE_UPDATE_COUNT:
print('Beginning upload of {} history items. '
'This may take a while...'.format(num_commands))

try:
success = True
commands = [x for x in commands.keys() if x]
commands = [x for x in list(commands.keys()) if x]
# To ease testing, sort commands
commands.sort()
if len(commands) > 0:
Expand Down Expand Up @@ -119,7 +119,7 @@ def import_history():
continue
commands[command] = None
try:
success, response = web_history.bulk_add(commands.keys())
success, response = web_history.bulk_add(list(commands.keys()))
except ArcheloncConnectionException as ex:
print(ex)
sys.exit(4)
Expand Down
8 changes: 4 additions & 4 deletions archelonc/archelonc/data.py
Expand Up @@ -2,12 +2,13 @@
"""
Data modeling for command history to be modular
"""
from __future__ import print_function
from __future__ import print_function, absolute_import, unicode_literals
from abc import ABCMeta, abstractmethod
from collections import OrderedDict
import os

import requests
import six


class ArcheloncException(Exception):
Expand All @@ -25,12 +26,11 @@ class ArcheloncAPIException(ArcheloncException):
pass


class HistoryBase(object):
class HistoryBase(six.with_metaclass(ABCMeta, object)):
"""
Base class of what all backend command history
searches should use.
"""
__metaclass__ = ABCMeta

@abstractmethod
def search_forward(self, term, page=0):
Expand Down Expand Up @@ -67,7 +67,7 @@ def __init__(self):
with open(os.path.expanduser('~/.bash_history')) as history_file:
for line in history_file:
history_dict[line.strip()] = None
self.data = history_dict.keys()
self.data = list(history_dict.keys())

def search_forward(self, term, page=0):
"""
Expand Down
4 changes: 2 additions & 2 deletions archelonc/archelonc/search.py
Expand Up @@ -2,7 +2,7 @@
"""
npyscreen based application for searching shell history
"""
from __future__ import print_function
from __future__ import print_function, absolute_import, unicode_literals
import curses
import os
import sys
Expand Down Expand Up @@ -93,7 +93,7 @@ def search(self, page=0):
return self.parent.parentApp.data.search_reverse(
self.value, page
)
except ArcheloncException, ex:
except ArcheloncException as ex:
print(ex)
sys.exit(1)

Expand Down
6 changes: 3 additions & 3 deletions archelonc/archelonc/tests/test_command.py
Expand Up @@ -2,11 +2,11 @@
Verify the various archelnc commands.
"""
from __future__ import absolute_import, print_function, unicode_literals
from cStringIO import StringIO
import filecmp
import os
from tempfile import NamedTemporaryFile as TempFile

from six.moves import cStringIO # pylint: disable=import-error
import mock

from archelonc.command import (
Expand Down Expand Up @@ -167,7 +167,7 @@ def test_update_not_success(self, mock_web_setup):
@mock.patch('archelonc.command.HISTORY_FILE', TEST_ARCHELON_HISTORY)
@mock.patch('archelonc.command.LARGE_UPDATE_COUNT', 1)
@mock.patch('archelonc.command._get_web_setup')
@mock.patch('sys.stdout', new_callable=StringIO)
@mock.patch('sys.stdout', new_callable=cStringIO)
def test_update_large_indicator(self, mock_stdout, mock_web_setup):
"""
Verify output when there are greater than 50 commands
Expand Down Expand Up @@ -239,7 +239,7 @@ def test_import_errors(self, mock_web_setup):
self.assertEqual(exception_context.exception.code, 6)

@mock.patch('archelonc.command._get_web_setup')
@mock.patch('sys.stdout', new_callable=StringIO)
@mock.patch('sys.stdout', new_callable=cStringIO)
def test_export_success_stdout(self, mock_stdout, mock_web_setup):
"""
Validate that we can export all commands successfully.
Expand Down
1 change: 1 addition & 0 deletions archelonc/archelonc/tests/test_data.py
Expand Up @@ -7,6 +7,7 @@
import unittest

import mock
from six.moves import range # pylint: disable=redefined-builtin,import-error

from archelonc.data import (
LocalHistory,
Expand Down
3 changes: 2 additions & 1 deletion archelonc/archelonc/tests/test_search.py
Expand Up @@ -8,6 +8,7 @@
import unittest

import mock
from six.moves import range # pylint: disable=redefined-builtin,import-error

from archelonc.search import (
Search, SearchForm, SearchBox, CommandBox, SearchResults, SearchResult
Expand Down Expand Up @@ -52,7 +53,7 @@ def test_update(self):
mock_parent.reset_mock()
mock_parent.parentApp.page = 41
mock_parent.results_list.cursor_line = 2
mock_parent.search_box.search.return_value = range(2)
mock_parent.search_box.search.return_value = list(range(2))
with mock.patch('npyscreen.Textfield.update') as mock_update:
search_result.update()
self.assertTrue(mock_update.called_once)
Expand Down
6 changes: 5 additions & 1 deletion archelonc/setup.py
Expand Up @@ -2,7 +2,7 @@
"""
Package installer for archelon client
"""

from __future__ import absolute_import
from setuptools import setup, find_packages


Expand All @@ -28,10 +28,14 @@
('License :: OSI Approved :: '
'GNU Affero General Public License v3'),
'Operating System :: POSIX :: Linux',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3.3',
'Programming Language :: Python :: 3.4',
],
install_requires=[
'npyscreen',
'requests>=2.4.2',
'six',
],
scripts=['scripts/archelon'],
entry_points={'console_scripts': [
Expand Down
9 changes: 2 additions & 7 deletions archelonc/test_requirements.txt
Expand Up @@ -3,13 +3,6 @@
pytest
pytest-pep8
pytest-pylint

# Thanks to @bdero for this:
# logilab-common is only necessary because pylint's dependency chain will
# result in the latest logilab-common being fetched, but astroid
# (another pylint dependency) depends on logilab-common<=0.63.0
logilab-common==0.63.0

pytest-cov
pytest-capturelog
pytest-watch
Expand All @@ -20,3 +13,5 @@ contextlib2
diff-cover
coveralls
tox>=2.0.0,<3.0.0
# https://bitbucket.org/hpk42/execnet/issues/46/running-pytest-pep8-raises-valueerror
execnet==1.3.0
7 changes: 3 additions & 4 deletions archelonc/tox.ini
@@ -1,15 +1,14 @@
[tox]
envlist = py27-archelonc
envlist = py{27,33,34}-archelonc
skip_missing_interpreters = True
skipsdist = True

[testenv]
basepython =
py27: python2.7
# py33: python3.3
# py34: python3.4
py33: python3.3
py34: python3.4
passenv = *
# whitelist_externals = cp
deps =
-e{toxinidir}
-r{toxinidir}/test_requirements.txt
Expand Down
3 changes: 3 additions & 0 deletions archelond/setup.py
Expand Up @@ -28,6 +28,9 @@
('License :: OSI Approved :: '
'GNU Affero General Public License v3'),
'Operating System :: POSIX :: Linux',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3.3',
'Programming Language :: Python :: 3.4',
],
install_requires=[
'flask',
Expand Down
9 changes: 2 additions & 7 deletions archelond/test_requirements.txt
Expand Up @@ -3,17 +3,12 @@
pytest
pytest-pep8
pytest-pylint

# Thanks to @bdero for this:
# logilab-common is only necessary because pylint's dependency chain will
# result in the latest logilab-common being fetched, but astroid
# (another pylint dependency) depends on logilab-common<=0.63.0
logilab-common==0.63.0

pytest-cov
pytest-capturelog
pytest-watch
mock
diff-cover
coveralls
tox>=2.0.0,<3.0.0
# https://bitbucket.org/hpk42/execnet/issues/46/running-pytest-pep8-raises-valueerror
execnet==1.3.0
2 changes: 1 addition & 1 deletion tox.ini
@@ -1,5 +1,5 @@
[tox]
envlist = py{27,33,34}-archelond, py27-archelonc, docs, coverage
envlist = py{27,33,34}-archelond, py{27,33,34}-archelonc, docs, coverage
skip_missing_interpreters = True
skipsdist = True

Expand Down

0 comments on commit 02e81f8

Please sign in to comment.