From 188b533c8c625860239a31e6f27130d70820deb1 Mon Sep 17 00:00:00 2001 From: Gunther Cox Date: Sat, 20 Feb 2016 09:07:21 -0500 Subject: [PATCH 1/5] Added testing for python 3 to travis builds. --- .travis.yml | 6 ++++-- setup.py | 9 ++------- zorg_network_camera/__init__.py | 2 +- 3 files changed, 7 insertions(+), 10 deletions(-) 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/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/zorg_network_camera/__init__.py b/zorg_network_camera/__init__.py index 0052d1c..a4a35c5 100644 --- a/zorg_network_camera/__init__.py +++ b/zorg_network_camera/__init__.py @@ -4,5 +4,5 @@ from .ocr import OCR -__version__ = '0.0.2' +__version__ = '0.0.3' From a539259421aa1656fb04f1942b1e6cd8f5ffb7d1 Mon Sep 17 00:00:00 2001 From: Gunther Cox Date: Sat, 20 Feb 2016 09:25:17 -0500 Subject: [PATCH 2/5] Added python 2 & 3 compatabile urllib import. --- zorg_network_camera/adaptor.py | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/zorg_network_camera/adaptor.py b/zorg_network_camera/adaptor.py index 42a41df..b7bd7dd 100644 --- a/zorg_network_camera/adaptor.py +++ b/zorg_network_camera/adaptor.py @@ -1,7 +1,13 @@ from zorg.adaptor import Adaptor -import urllib2, urlparse +import urlparse import os +# Check urllib for Python 2 or 3 compatability +try: + from urllib import request as urllib_request +except ImportError: + import urllib2 as urllib_request + class Camera(Adaptor): @@ -26,7 +32,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 +46,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 +64,3 @@ def has_changed(self): # Return True if the image has been modified # or if the image has no last-modified header return True - From e286b532d25c9a199684c96d1dc9efefbe2ab303 Mon Sep 17 00:00:00 2001 From: Gunther Cox Date: Sat, 20 Feb 2016 09:25:35 -0500 Subject: [PATCH 3/5] pep8 fixes. --- examples/camera.py | 2 +- examples/ocr_camera.py | 2 +- tests/smoke_tests/test_commands.py | 1 - tests/test_drivers.py | 5 +++-- zorg_network_camera/__init__.py | 1 - zorg_network_camera/light_sensor.py | 1 - zorg_network_camera/ocr.py | 3 +-- 7 files changed, 6 insertions(+), 9 deletions(-) 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/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 a4a35c5..6f14227 100644 --- a/zorg_network_camera/__init__.py +++ b/zorg_network_camera/__init__.py @@ -5,4 +5,3 @@ __version__ = '0.0.3' - 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 - From 732315ebfa95ac309ec48d69f7b18a29c62705c1 Mon Sep 17 00:00:00 2001 From: Gunther Cox Date: Sat, 20 Feb 2016 09:44:51 -0500 Subject: [PATCH 4/5] Added urlparse to python 2 and 3 import check. --- zorg_network_camera/adaptor.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/zorg_network_camera/adaptor.py b/zorg_network_camera/adaptor.py index b7bd7dd..31a9e4e 100644 --- a/zorg_network_camera/adaptor.py +++ b/zorg_network_camera/adaptor.py @@ -1,11 +1,12 @@ from zorg.adaptor import Adaptor -import 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 @@ -23,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 From 4a20bdeaa801bb7e726d80b95cf7ab8718d6ebc5 Mon Sep 17 00:00:00 2001 From: Gunther Cox Date: Sat, 20 Feb 2016 09:52:53 -0500 Subject: [PATCH 5/5] Updated readme. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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.