Skip to content

Commit

Permalink
Add python 2 backward compatiblity
Browse files Browse the repository at this point in the history
  • Loading branch information
shivammathur committed May 18, 2017
1 parent 821ce08 commit 5a3a3be
Show file tree
Hide file tree
Showing 13 changed files with 64 additions and 23 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,6 @@ target/

# pyenv python configuration file
.python-version

#pycharm
.idea*
8 changes: 6 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
language: python
matrix:
include:
- python: 2.6
env: TOXENV=py26
- python: 2.7
env: TOXENV=py27
- python: 3.3
env: TOXENV=py33
- python: 3.4
Expand All @@ -14,14 +18,14 @@ matrix:
env: TOXENV=py36

# command to install dependencies, e.g. pip install -r requirements.txt --use-mirrors
install:
install:
- pip install -U tox
- pip install tox codecov coveralls
- pip install -r requirements.txt
- pip install pytest-cov

# command to run tests, e.g. python setup.py test
script:
script:
- py.test --cov=ippy tests/
- tox -e ${TOXENV}

Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ Parallel testing of IP addresses and domains in python.
Reads IP addresses and domains from a CSV file and gives two lists of accessible and inaccessible ones.

## About
- Written in Python 3
- Testing of IPs and domains is done in parallel.
- Compatible with both Python 2 and 3.
- Testing of IPs and domains is done in parallel.
- By default there are 4 Workers.
- All Workers work on an input Queue and a output Queue.

Expand Down
4 changes: 2 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ and inaccessible ones.
About
-----

- Written in Python 3
- Compatible with both Python 2 and 3.
- Testing of IPs and domains is done in parallel.
- By default there are 4 Workers.
- All Workers work on an input Queue and a output Queue.
Expand Down Expand Up @@ -75,4 +75,4 @@ then run tox from the project root directory.

::

$ tox
$ tox
8 changes: 7 additions & 1 deletion examples/example1.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
#!/usr/bin/env python3
#!/usr/bin/env python
# -*- coding: utf-8 -*-

from __future__ import print_function
from __future__ import unicode_literals
from __future__ import division
from __future__ import absolute_import
from future.standard_library import install_aliases
from ippy import ippy
import sys

Expand All @@ -14,4 +19,5 @@ def main():
print(output)

if __name__ == "__main__":
install_aliases()
sys.exit(main())
8 changes: 7 additions & 1 deletion examples/example2.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
#!/usr/bin/env python3
#!/usr/bin/env python
# -*- coding: utf-8 -*-

from __future__ import print_function
from __future__ import unicode_literals
from __future__ import division
from __future__ import absolute_import
from future.standard_library import install_aliases
from ippy import ippy
import sys

Expand All @@ -14,4 +19,5 @@ def main():
print(output)

if __name__ == "__main__":
install_aliases()
sys.exit(main())
2 changes: 1 addition & 1 deletion ippy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

__author__ = """Shivam Mathur"""
__email__ = 'shivam_jpr@hotmail.com'
__version__ = '0.2.3'
__version__ = '0.3.0'

from .ippy import Ippy
20 changes: 15 additions & 5 deletions ippy/ippy.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,27 @@
#!/usr/bin/env python3
#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""
Python script to check if IP address and domains are accessible or not.
.. codeauthor:: Shivam Mathur <shivam_jpr@hotmail.com>
"""

from __future__ import print_function
from __future__ import unicode_literals
from __future__ import division
from __future__ import absolute_import
from future.standard_library import install_aliases
from io import StringIO
from json import dumps
from csv import writer
from itertools import zip_longest
from future.moves.itertools import zip_longest

import sys
import os
import platform
import subprocess
import threading
import queue
import pingparsing
import queue


class Ippy(object):
Expand Down Expand Up @@ -185,10 +189,16 @@ def result(self):
result = dumps(result_dict, indent=4)
elif self.output == 'csv':
result = StringIO()
writer(result)
ippy_writer = writer(result)
d = [self._accessible, self._not_accessible]
for x in zip_longest(*d):
ippy_writer.writerow(x)
result = result.getvalue().strip('\r\n')
result = 'Accessible,Not Accessible\n' + result
else:
raise ValueError("Unknown output mode")

return result

if __name__ == "__main__":
install_aliases()
5 changes: 4 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
pingparsing==0.6.0

pingparsing>=0.6.0

future>=0.16.0
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 0.2.3
current_version = 0.3.0
commit = True
tag = True

Expand Down
7 changes: 4 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@

setup(
name='ippy',
version='0.2.3',
version='0.3.0',
description="Parallel testing of IP addresses and domains in python.",
author="Shivam Mathur",
author_email='shivam_jpr@hotmail.com',
url='https://github.com/shivammathur/ippy',
download_url='https://github.com/shivammathur/ippy/archive/0.2.3.tar.gz',
download_url='https://github.com/shivammathur/ippy/archive/0.3.0.tar.gz',
packages=[
'ippy',
],
Expand All @@ -42,7 +42,8 @@
"Intended Audience :: Developers",
"License :: OSI Approved :: MIT License",
"Natural Language :: English",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 2.6",
"Programming Language :: Python :: 2.7",
"Programming Language :: Python :: 3.3",
"Programming Language :: Python :: 3.4",
"Programming Language :: Python :: 3.5",
Expand Down
10 changes: 9 additions & 1 deletion tests/test_ippy.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,20 @@
Tests for `ippy` module.
"""
from __future__ import unicode_literals
from __future__ import print_function
from __future__ import division
from __future__ import absolute_import

import pytest
from future.standard_library import install_aliases
from ippy import ippy
import pytest
import sys
import os
import json
from io import StringIO
from csv import reader
install_aliases()


def test_config():
Expand Down Expand Up @@ -74,12 +80,14 @@ def test_empty_result():
ippt.run()
pytest.raises(ValueError, "ippt.result()")


def test_json_result():
ippt = ippy.Ippy()
ippt.set_config(False, 'json', 10)
result = ippt.result()
assert json.loads(result) is not None


def test_csv_result():
ippt = ippy.Ippy()
ippt.set_config(False, 'csv', 10)
Expand Down
6 changes: 3 additions & 3 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[tox]
envlist = py33, py34, py35, py36
envlist = py26, py27, py33, py34, py35, py36

[testenv]
setenv =
Expand All @@ -9,9 +9,9 @@ deps =
-r{toxinidir}/requirements.txt
codecov>=1.4.0
coveralls
passenv = CI TRAVIS TRAVIS_*
passenv = CI TRAVIS TRAVIS_*
commands =
pip install -U pip
py.test --basetemp={envtmpdir}
codecov -e TOXENV
codecov -e TOXENV
coveralls

0 comments on commit 5a3a3be

Please sign in to comment.