Source: debtags
Severity: normal
Version: 1.10.2
User: ubuntu-de...@lists.ubuntu.com
Usertags: origin-ubuntu quantal ubuntu-patch

Please add python3 support to debtagshw.

Regards,

Dmitrijs.

>From 40b9ac13ad9fa91d9783663b4a6bb7acb44dd58c Mon Sep 17 00:00:00 2001
From: Dmitrijs Ledkovs <dmitrijs.ledk...@canonical.com>
Date: Thu, 30 Aug 2012 23:48:40 +0100
Subject: [PATCH] * Add python3-debtagshw * Add DEP8 tests for
 python*-debtagshw

---
 debian/control                   |   18 +++++++++++++++--
 debian/python-debtagshw.install  |    2 +-
 debian/python3-debtagshw.install |    1 +
 debian/rules                     |    7 ++++++-
 debian/tests/control             |    7 +++++++
 debian/tests/python-debtagshw    |    7 +++++++
 debian/tests/python3-debtagshw   |    7 +++++++
 debtagshw/debtagshw.py           |    6 ++++--
 debtagshw/detectors.py           |   25 +++++++++++++-----------
 debtagshw/opengl.py              |   40 ++++++++++++++++++++++----------------
 test/test_hw.py                  |   18 ++++++++++-------
 11 files changed, 97 insertions(+), 41 deletions(-)
 create mode 100644 debian/python3-debtagshw.install
 create mode 100644 debian/tests/control
 create mode 100644 debian/tests/python-debtagshw
 create mode 100644 debian/tests/python3-debtagshw

diff --git a/debian/control b/debian/control
index b5f89cf..f213eac 100644
--- a/debian/control
+++ b/debian/control
@@ -8,9 +8,12 @@ Build-Depends:
   libwibble-dev (>= 0.1.15), libwibble-dev (<< 0.2),
   libtagcoll2-dev (>= 2.0.4), libtagcoll2-dev (<<2.1),
   libept-dev (>= 1.0), libept-dev (<< 2),
-  zlib1g-dev, python, python-docutils, help2man, 
-  python-setuptools
+  zlib1g-dev, python-all, python3-all, python-docutils, help2man,
+  python-setuptools, python3-setuptools
 Standards-Version: 3.9.2.0
+X-Python-Version: >= 2.6
+X-Python3-Version: >= 3.2
+XS-Testsuite: autopkgtest
 Vcs-Git: git://git.debian.org/debtags/debtags.git
 Vcs-Browser: http://git.debian.org/?p=debtags/debtags.git;a=summary
 Homepage: http://wiki.debian.org/Debtags
@@ -41,3 +44,14 @@ Description: Match debtags hardware:: tags against the actual hardware
  debtagshw provides a python library to match a given hardware:: debtag
  against the current system in order to verify that the system supports
  the hardware.
+
+Package: python3-debtagshw
+Section: python
+Architecture: all
+Depends: ${python3:Depends}, ${misc:Depends}
+Recommends: gir1.2-gudev-1.0, laptop-detect, sane-utils, python-cups
+Description: Match debtags hardware:: tags against the actual hardware (Python 3)
+ debtagshw provides a python library to match a given hardware:: debtag
+ against the current system in order to verify that the system supports
+ the hardware.
+ This package is for Python 3.
diff --git a/debian/python-debtagshw.install b/debian/python-debtagshw.install
index 2453ce7..4c0c522 100644
--- a/debian/python-debtagshw.install
+++ b/debian/python-debtagshw.install
@@ -1 +1 @@
-usr/lib/python*/
+usr/lib/python2*/
diff --git a/debian/python3-debtagshw.install b/debian/python3-debtagshw.install
new file mode 100644
index 0000000..eae3930
--- /dev/null
+++ b/debian/python3-debtagshw.install
@@ -0,0 +1 @@
+usr/lib/python3/
diff --git a/debian/rules b/debian/rules
index 9b10aaf..b79fa40 100755
--- a/debian/rules
+++ b/debian/rules
@@ -1,7 +1,10 @@
 #!/usr/bin/make -f
 
+PYTHON3:=$(shell py3versions -r)
+py3sdo=set -e; $(foreach py, $(PYTHON3), $(py) $(1);)
+
 %:
-	dh $@ --with=python2,autoreconf
+	dh $@ --with=python2,python3,autoreconf
 
 override_dh_auto_clean:
 	dh_auto_clean --buildsystem=autoconf
@@ -14,10 +17,12 @@ override_dh_auto_configure:
 override_dh_auto_build:
 	dh_auto_build --buildsystem=autoconf
 	dh_auto_build --buildsystem=python_distutils
+	$(call py3sdo, setup.py build)
 
 override_dh_auto_install:
 	dh_auto_install --buildsystem=autoconf
 	dh_auto_install --buildsystem=python_distutils
+	$(call py3sdo, setup.py install --root=$(CURDIR)/debian/tmp --install-layout=deb)
 
 override_dh_fixperms:
 	dh_fixperms
diff --git a/debian/tests/control b/debian/tests/control
new file mode 100644
index 0000000..0825008
--- /dev/null
+++ b/debian/tests/control
@@ -0,0 +1,7 @@
+Tests: python-debtagshw
+Features: no-build-needed
+Depends: python-debtagshw, python-nose
+
+Tests: python3-debtagshw
+Features: no-build-needed
+Depends: python3-debtagshw, python3-nose
diff --git a/debian/tests/python-debtagshw b/debian/tests/python-debtagshw
new file mode 100644
index 0000000..2a30a73
--- /dev/null
+++ b/debian/tests/python-debtagshw
@@ -0,0 +1,7 @@
+#!/bin/sh
+set -e -u
+cp -r tests "$ADTTMP/"
+cd "$ADTTMP"
+pyversions -i \
+| tr ' ' '\n' \
+| xargs -I {}  {} -m unittest discover -v 2>&1
diff --git a/debian/tests/python3-debtagshw b/debian/tests/python3-debtagshw
new file mode 100644
index 0000000..80afade
--- /dev/null
+++ b/debian/tests/python3-debtagshw
@@ -0,0 +1,7 @@
+#!/bin/sh
+set -e -u
+cp -r tests "$ADTTMP/"
+cd "$ADTTMP"
+py3versions -i \
+| tr ' ' '\n' \
+| xargs -I {}  {} -m unittest discover -v 2>&1
diff --git a/debtagshw/debtagshw.py b/debtagshw/debtagshw.py
index 137f411..9a78d89 100644
--- a/debtagshw/debtagshw.py
+++ b/debtagshw/debtagshw.py
@@ -19,13 +19,15 @@
 # along with this program; if not, write to the Free Software
 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
+from __future__ import absolute_import
+
 import logging
 LOG=logging.getLogger(__name__)
 
 # get the detectors lib
-import detectors
+from . import detectors
 
-from enums import HardwareSupported
+from .enums import HardwareSupported
 
 class DebtagsAvailableHW(object):
     """ Match the currents system hardware to debtags """
diff --git a/debtagshw/detectors.py b/debtagshw/detectors.py
index df6e483..c06d480 100644
--- a/debtagshw/detectors.py
+++ b/debtagshw/detectors.py
@@ -19,6 +19,8 @@
 # along with this program; if not, write to the Free Software
 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
+from __future__ import absolute_import
+
 import logging
 import os
 import subprocess
@@ -31,8 +33,8 @@ try:
 except ImportError:
     HAVE_GUDEV = False
 
-from enums import HardwareSupported
-import opengl
+from .enums import HardwareSupported
+from . import opengl
 
 class Detector(object):
     """ Base detector class """
@@ -110,8 +112,8 @@ class DetectorUdev(Detector):
     }
 
     # all tags this class knows about
-    SUPPORTED_TAGS = DEBTAG_TO_UDEV_PROPERTY.keys() + \
-                      DEBTAG_TO_ID_TYPE.keys()
+    SUPPORTED_TAGS = list(DEBTAG_TO_UDEV_PROPERTY.keys()) + \
+                      list(DEBTAG_TO_ID_TYPE.keys())
 
     def __init__(self):
         if HAVE_GUDEV:
@@ -145,7 +147,7 @@ class DetectorUdev(Detector):
                     return HardwareSupported.YES
         # if we know about the tag and did not find it, return NO
         # (LP: #1020057)
-        if tag in self.SUPPORTED_TAGS: 
+        if tag in self.SUPPORTED_TAGS:
             return HardwareSupported.NO
         # otherwise its UNKNOWN
         return HardwareSupported.UNKNOWN
@@ -156,7 +158,7 @@ class DetectorUdev(Detector):
 
 class DetectorCmdline(Detector):
     """ detect hardware using cmdline helpers """
-    
+
     LAPTOP_DETECT = "/usr/sbin/laptop-detect"
     SCANIMAGE = ["scanimage", "-L"]
 
@@ -189,7 +191,8 @@ class DetectorCmdline(Detector):
         # Note: you can use multiprocessing.Pool.map to run all checks in
         # parallel
         try:
-            output = subprocess.check_output(self.SCANIMAGE)
+            output = subprocess.check_output(self.SCANIMAGE,
+                                             universal_newlines=True)
             if output.startswith("device"):
                 return HardwareSupported.YES
             else:
@@ -200,7 +203,7 @@ class DetectorCmdline(Detector):
 
 class DetectorCtypes(Detector):
     """ detect hardware using ctypes c calls """
-    
+
     def __init__(self):
         self.TAG_TO_FUNC = {
             'hardware::video:opengl' : self._is_supported,
@@ -218,9 +221,9 @@ class DetectorCtypes(Detector):
             elif res is False:
                 return HardwareSupported.NO
         return HardwareSupported.UNKNOWN
-    
+
     def get_supported_tags(self):
-        return self.TAG_TO_FUNC.keys()
+        return list(self.TAG_TO_FUNC.keys())
 
 
 class DetectorPython(Detector):
@@ -247,7 +250,7 @@ def get_detectors():
     """ hepler that returns a list of all lowlevel detector classes """
     # introspect the detectors modules to load all availalbe detectors
     detectors = []
-    for name, klass in globals().iteritems():
+    for name, klass in globals().items():
         if name.startswith("Detector"):
             detectors.append(klass())
     return detectors
diff --git a/debtagshw/opengl.py b/debtagshw/opengl.py
index a0e33e1..d1233b4 100644
--- a/debtagshw/opengl.py
+++ b/debtagshw/opengl.py
@@ -19,9 +19,12 @@
 # along with this program; if not, write to the Free Software
 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
+from __future__ import print_function
+
 import logging
 import multiprocessing
 import os
+import sys
 
 LOG=logging.getLogger(__name__)
 
@@ -56,7 +59,7 @@ class OpenGL(object):
     GLX_VERSION=2
     GLX_EXTENSIONS=3
 
-    # for the visinfo 
+    # for the visinfo
     GLX_RGBA = 4
     GLX_RED_SIZE = 8
     GLX_GREEN_SIZE = 9
@@ -122,7 +125,7 @@ class OpenGL(object):
             visinfo = glx.glXChooseVisual(display, 0, attribDouble)
         if not visinfo:
             raise OpenGLError("Can not get visinfo")
-        # create context etc 
+        # create context etc
         context = glx.glXCreateContext (display, visinfo, None, self.direct)
         if not context:
             raise OpenGLError("Can not create glx context")
@@ -130,15 +133,19 @@ class OpenGL(object):
         glx.glXMakeCurrent(display, root, context)
         # and get the actual useful gl data
         glx.glGetString.restype = c_char_p
-        vendor = glx.glGetString(self.GL_VENDOR)
-        renderer = glx.glGetString(self.GL_RENDERER)
-        version = glx.glGetString(self.GL_VERSION)
-        extensions = glx.glGetString(self.GL_EXTENSIONS)
-        LOG.info("gl vendor: %s" % vendor)
-        LOG.info("gl renderer: %s" % renderer)
-        LOG.info("gl version: %s" % version)
-        LOG.debug("gl extenstions: %s" % extensions)
-        return vendor, renderer, version
+
+        opengl_tuple = []
+        for gl_item in ["vendor", "renderer", "version", "extensions"]:
+            gl_hex = getattr(self, "GL_%s" % gl_item.upper())
+            gl_string = glx.glGetString(gl_hex)
+            if sys.version > '3':
+                gl_string = gl_string.decode()
+            if gl_item == "extensions":
+                LOG.debug("gl %s: %s" % (gl_item, gl_string))
+            else:
+                LOG.info("gl %s: %s" % (gl_item, gl_string))
+            opengl_tuple.append(gl_string)
+        return opengl_tuple[:3]
 
     def opengl_driver(self):
         vendor, renderer, version = self._get_opengl_vendor_renderer_version_tuple()
@@ -171,7 +178,7 @@ class OpenGL(object):
 
 
 # private helpers
-   
+
 def _apply_in_multiprocessing_pool(func):
     """ private helper to run the given func in a multiprocessing env
         to protect against segfaults in the ctypes code """
@@ -231,13 +238,12 @@ def get_version():
         return _apply_in_multiprocessing_pool(_do_get_version)
     except OSError:
         return None
-    
+
 if __name__ == "__main__":
     logging.basicConfig(level=logging.INFO)
     supported = run_check()
     driver = get_driver()
     version = get_version()
-    print "opengl_supported: ", supported
-    print "opengl_driver: ", driver
-    print "opengl_version: ", version
-
+    print("opengl_supported: ", supported)
+    print("opengl_driver: ", driver)
+    print("opengl_version: ", version)
diff --git a/test/test_hw.py b/test/test_hw.py
index 2a670e4..2929db8 100644
--- a/test/test_hw.py
+++ b/test/test_hw.py
@@ -21,6 +21,8 @@
 # along with this program; if not, write to the Free Software
 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
+from __future__ import absolute_import
+
 import logging
 import unittest
 import tempfile
@@ -29,7 +31,6 @@ from mock import Mock, patch
 
 
 import sys
-sys.path.insert(0, "../")
 
 from debtagshw.detectors import (
     Detector,
@@ -61,7 +62,7 @@ class TestDebtagsHW(unittest.TestCase):
         # this may fail on a buildd with no keyboard
         hw = DebtagsAvailableHW()
         self.assertTrue(hw._check_hw_debtag("hardware::input:keyboard"))
-    
+
     def test_laptop_detect(self):
         d = DetectorCmdline()
         d.LAPTOP_DETECT = "/bin/true"
@@ -73,7 +74,10 @@ class TestDebtagsHW(unittest.TestCase):
 
     def test_scanner(self):
         f = tempfile.NamedTemporaryFile()
-        f.write("device 'uri' is a foo bar bar")
+        test_bytes = "device 'uri' is a foo bar bar"
+        if sys.version > '3':
+            test_bytes = test_bytes.encode()
+        f.write(test_bytes)
         f.flush()
         d = DetectorCmdline()
         d.SCANIMAGE = ["cat", f.name]
@@ -112,7 +116,7 @@ class TestPublicAPI(unittest.TestCase):
             'hardware::gps' : HardwareSupported.NO,
             'hardware::xxx' : HardwareSupported.UNKNOWN,
             })
-        
+
     def test_generate_tag_expressions(self):
         res = {}
         # test
@@ -126,7 +130,7 @@ class TestCasePrinter(unittest.TestCase):
 
     def _make_cups_mock(self):
         import cups
-        cups_mock = Mock()        
+        cups_mock = Mock()
         cups_connection_mock = Mock(cups.Connection)
         cups_mock.Connection.return_value = cups_connection_mock
         return cups_mock, cups_connection_mock
@@ -138,7 +142,7 @@ class TestCasePrinter(unittest.TestCase):
             cups_connection_mock.getPrinters.return_value = {}
             self.assertEqual(hw._check_hw_debtag("hardware::printer"),
                              HardwareSupported.NO)
-            cups_connection_mock.getPrinters.return_value = { 
+            cups_connection_mock.getPrinters.return_value = {
                 'deskjet' : { 'print-info' : "some info",
                             },
                 }
@@ -184,7 +188,7 @@ class TestCaseOpenGL(unittest.TestCase):
                 if driver != "unknown":
                     opengl_version = detector.opengl_version()
                     self.assertNotEqual(opengl_version, "unknown")
-                    
+
 
 if __name__ == "__main__":
     logging.basicConfig(level=logging.INFO)
-- 
1.7.10.4

Reply via email to