diff --git a/.travis.yml b/.travis.yml index 7f703dd..79baccf 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,8 +4,10 @@ sudo: false language: python python: - - "2.7" - - "pypy" + - '2.7' + - '3.4' + - '3.5' + - 'pypy' addons: apt: diff --git a/README.md b/README.md index 00c1652..d4d556b 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ [![PYPI](https://img.shields.io/pypi/v/zorg-network-camera.svg)](https://pypi.python.org/pypi/zorg-network-camera/) [![Build Status](https://travis-ci.org/zorg/zorg-network-camera.svg?branch=0.0.1)](https://travis-ci.org/zorg/zorg-network-camera) -[![Coverage Status](https://coveralls.io/repos/zorg/zorg-network-camera/badge.svg?branch=master&service=github)](https://coveralls.io/github/zorg/zorg-network-camera?branch=master) +[![Coverage Status](https://coveralls.io/repos/github/zorg/zorg-network-camera/badge.svg?branch=master)](https://coveralls.io/github/zorg/zorg-network-camera?branch=master) This module contains device adaptors and drivers that make it possible to connect network cameras to your robot. diff --git a/examples/camera.py b/examples/camera.py index 7b4ae14..4217d72 100644 --- a/examples/camera.py +++ b/examples/camera.py @@ -11,6 +11,7 @@ /api/robots/CameraBot/devices/camera_one/commands/get_url ''' + def work(my): while True: print(my.camera_one.get_url()) @@ -42,4 +43,3 @@ def work(my): robot.start() api.start() - diff --git a/examples/ocr_camera.py b/examples/ocr_camera.py index 810905f..b5db02c 100644 --- a/examples/ocr_camera.py +++ b/examples/ocr_camera.py @@ -10,6 +10,7 @@ /api/robots/CameraBot/devices/camera_one/commands/get_url ''' + def work(my): while True: print(my.ocr.read()) @@ -36,4 +37,3 @@ def work(my): robot.start() api.start() - diff --git a/setup.py b/setup.py index cf2959a..a9d130c 100644 --- a/setup.py +++ b/setup.py @@ -1,10 +1,7 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -try: - from setuptools import setup, find_packages -except ImportError: - from distutils.core import setup, find_packages +from setuptools import setup, find_packages try: from pypandoc import convert @@ -22,13 +19,12 @@ name="zorg-network-camera", version=version_string, url="https://github.com/zorg/zorg-network-camera", - description="Python framework for robotics and physical computing.", + description="A module which includes various network camera utilities.", long_description=readme("README.md"), author="Zorg Group", author_email="gunthercx@gmail.com", packages=find_packages(), package_dir={"zorg_network_camera": "zorg_network_camera"}, - include_package_data=True, install_requires=requirements, license="MIT", zip_safe=True, @@ -42,7 +38,6 @@ "Environment :: Web Environment", "Operating System :: OS Independent", "Programming Language :: Python", - "Programming Language :: Python :: 2", "Programming Language :: Python :: 2.7", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.3", diff --git a/tests/smoke_tests/test_commands.py b/tests/smoke_tests/test_commands.py index 2d44e3c..0b441b5 100644 --- a/tests/smoke_tests/test_commands.py +++ b/tests/smoke_tests/test_commands.py @@ -48,4 +48,3 @@ def test_command_method_exists(self): for command in sensor.commands: self.assertIn(command, dir(sensor)) - diff --git a/tests/test_drivers.py b/tests/test_drivers.py index ef6b92e..2134f29 100644 --- a/tests/test_drivers.py +++ b/tests/test_drivers.py @@ -94,8 +94,9 @@ def test_valid_text(self): Test that a string containing words returns true. """ # Mock the read method to return a non-word string. - self.ocr.read = MagicMock(return_value="Scientific American volume 307") + self.ocr.read = MagicMock( + return_value="Scientific American volume 307" + ) text_detected = self.ocr.text_visible() self.assertTrue(text_detected) - diff --git a/zorg_network_camera/__init__.py b/zorg_network_camera/__init__.py index 0052d1c..6f14227 100644 --- a/zorg_network_camera/__init__.py +++ b/zorg_network_camera/__init__.py @@ -4,5 +4,4 @@ from .ocr import OCR -__version__ = '0.0.2' - +__version__ = '0.0.3' diff --git a/zorg_network_camera/adaptor.py b/zorg_network_camera/adaptor.py index 42a41df..31a9e4e 100644 --- a/zorg_network_camera/adaptor.py +++ b/zorg_network_camera/adaptor.py @@ -1,7 +1,14 @@ from zorg.adaptor import Adaptor -import urllib2, urlparse import os +# Check urllib for Python 2 or 3 compatability +try: + from urllib.parse import urlsplit + from urllib import request as urllib_request +except ImportError: + from urlparse import urlsplit + import urllib2 as urllib_request + class Camera(Adaptor): @@ -17,7 +24,7 @@ def download_image(self): Download the image and return the local path to the image file. """ - split = urlparse.urlsplit(self.url) + split = urlsplit(self.url) filename = split.path.split("/")[-1] # Ensure the directory to store the image cache exists @@ -26,7 +33,7 @@ def download_image(self): filepath = os.path.join(self.cache_directory, filename) - data = urllib2.urlopen(self.url) + data = urllib_request.urlopen(self.url) with open(filepath, "wb") as image: image.write(data.read()) @@ -40,10 +47,10 @@ def has_changed(self): quicker that downloading and processing the whole file. """ - request = urllib2.Request(self.url) - request.get_method = lambda : 'HEAD' + request = urllib_request.Request(self.url) + request.get_method = lambda: 'HEAD' - response = urllib2.urlopen(request) + response = urllib_request.urlopen(request) information = response.info() if 'Last-Modified' in information: @@ -58,4 +65,3 @@ def has_changed(self): # Return True if the image has been modified # or if the image has no last-modified header return True - diff --git a/zorg_network_camera/light_sensor.py b/zorg_network_camera/light_sensor.py index da173f2..7043763 100644 --- a/zorg_network_camera/light_sensor.py +++ b/zorg_network_camera/light_sensor.py @@ -33,4 +33,3 @@ def get_brightness(self): self.image_brightness = statistics.mean[0] return self.image_brightness - diff --git a/zorg_network_camera/ocr.py b/zorg_network_camera/ocr.py index d3a2ac4..b038573 100644 --- a/zorg_network_camera/ocr.py +++ b/zorg_network_camera/ocr.py @@ -45,7 +45,7 @@ def text_visible(self): for word in words: # If the word is a numeric value - if word.lstrip('-').replace('.','',1).isdigit(): + if word.lstrip('-').replace('.', '', 1).isdigit(): return True # If the word contains only letters with a length from 2 to 20 @@ -53,4 +53,3 @@ def text_visible(self): return True return False -