[PATCH evemu 14/19] py: Cleanup imports, make attr usage more obvious
Daniel Martin
consume.noise at gmail.com
Mon Jan 6 09:38:14 PST 2014
Remove unused imports and sort the remaining ones. Additionally, replace
nearly all "from ... import ..." with simple imports, making it more
obvious where attributes came from, i.e.:
find_library() vs. ctypes.util.find_library() or
exception.ExecutionError() vs. evemu.exception.ExecutionError().
Signed-off-by: Daniel Martin <consume.noise at gmail.com>
---
python/evemu/__init__.py | 7 +++----
python/evemu/base.py | 18 +++++++++---------
python/evemu/testing/result.py | 7 +++++--
python/evemu/testing/runner.py | 10 +++++-----
python/evemu/testing/testcase.py | 32 +++++++++++++++-----------------
python/evemu/tests/test_base.py | 14 +++++++-------
python/evemu/tests/test_device.py | 11 +++++------
src/convert-old-dumps-to-1.1.py | 13 +++++++------
src/make-event-names.py | 2 +-
9 files changed, 57 insertions(+), 57 deletions(-)
diff --git a/python/evemu/__init__.py b/python/evemu/__init__.py
index 72d3841..f07a8ca 100644
--- a/python/evemu/__init__.py
+++ b/python/evemu/__init__.py
@@ -17,16 +17,15 @@ raw events.
# You should have received a copy of the GNU Lesser General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
-from ctypes.util import find_library
-
import ctypes
-import evemu.base
-import evemu.const
import glob
import os
import re
import stat
+import evemu.base
+import evemu.const
+
__all__ = ["Device"]
diff --git a/python/evemu/base.py b/python/evemu/base.py
index 66ea36a..713aec1 100644
--- a/python/evemu/base.py
+++ b/python/evemu/base.py
@@ -1,9 +1,9 @@
import ctypes
-from ctypes.util import find_library
+import ctypes.util
import os
-from evemu import const
-from evemu import exception
+import evemu.const
+import evemu.exception
class EvEmuBase(object):
@@ -11,29 +11,29 @@ class EvEmuBase(object):
A base wrapper class for the evemu functions, accessed via ctypes.
"""
def __init__(self):
- self._lib = ctypes.CDLL(const.LIB, use_errno=True)
- self._libc = ctypes.CDLL(find_library("c"), use_errno=True)
+ self._lib = ctypes.CDLL(evemu.const.LIB, use_errno=True)
+ self._libc = ctypes.CDLL(ctypes.util.find_library("c"), use_errno=True)
def _call0(self, api_call, *parameters):
result = api_call(*parameters)
if result == 0 and self.get_c_errno() != 0:
- raise exception.ExecutionError("%s: %s" % (
+ raise evemu.exception.ExecutionError("%s: %s" % (
api_call.__name__, self.get_c_error()))
return result
def _call(self, api_call, *parameters):
result = api_call(*parameters)
if result < 0 and self.get_c_errno() != 0:
- raise exception.ExecutionError("%s: %s" % (
+ raise evemu.exception.ExecutionError("%s: %s" % (
api_call.__name__, self.get_c_error()))
return result
def _callstr(self, api_call, *parameters):
result = api_call(*parameters)
if result == None and self.get_c_errno() != 0:
- raise exception.ExecutionError("%s: %s" % (
+ raise evemu.exception.ExecutionError("%s: %s" % (
api_call.__name__, self.get_c_error()))
- return result.decode(const.ENCODING)
+ return result.decode(evemu.const.ENCODING)
def get_c_errno(self):
return ctypes.get_errno()
diff --git a/python/evemu/testing/result.py b/python/evemu/testing/result.py
index d824b36..37ad2e8 100644
--- a/python/evemu/testing/result.py
+++ b/python/evemu/testing/result.py
@@ -1,4 +1,8 @@
import unittest
+
+import evemu.tests
+
+
try:
# Python 2.7
from unittest import TextTestResult
@@ -8,8 +12,7 @@ except ImportError:
def get_test_directory():
- from evemu import tests
- return tests.__path__[0]
+ return evemu.tests.__path__[0]
def get_test_module():
diff --git a/python/evemu/testing/runner.py b/python/evemu/testing/runner.py
index 324c0fd..cdd4879 100644
--- a/python/evemu/testing/runner.py
+++ b/python/evemu/testing/runner.py
@@ -1,12 +1,12 @@
import os
import unittest
-from evemu.testing import result
+import evemu.testing.result
+import evemu.tests
def get_test_directory():
- from evemu import tests
- return tests.__path__[0]
+ return evemu.tests.__path__[0]
class CustomTestRunner(unittest.TextTestRunner):
@@ -14,7 +14,7 @@ class CustomTestRunner(unittest.TextTestRunner):
This is only needed for Python 2.6 and lower.
"""
def _makeResult(self):
- return result.CustomTestResult(
+ return evemu.testing.result.CustomTestResult(
self.stream, self.descriptions, self.verbosity)
@@ -46,7 +46,7 @@ def get_runner():
try:
# Python 2.7
runner = unittest.TextTestRunner(
- verbosity=2, resultclass=result.CustomTestResult)
+ verbosity=2, resultclass=evemu.testing.result.CustomTestResult)
except TypeError:
# Python 2.4, 2.5, 2.6
runner = CustomTestRunner(verbosity=2)
diff --git a/python/evemu/testing/testcase.py b/python/evemu/testing/testcase.py
index 2603581..173bf0c 100644
--- a/python/evemu/testing/testcase.py
+++ b/python/evemu/testing/testcase.py
@@ -1,10 +1,8 @@
-from ctypes.util import find_library
import os
import unittest
-from evemu import const
-from evemu import exception
-
+import evemu.const
+import evemu.exception
def get_top_directory():
import evemu
@@ -18,7 +16,7 @@ def skip(message):
def _skip(message):
def decorator(test_item):
def skip_wrapper(*args, **kwds):
- raise exception.SkipTest(message)
+ raise evemu.exception.SkipTest(message)
return skip_wrapper
return decorator
return _skip(message)
@@ -63,52 +61,52 @@ class BaseTestCase(unittest.TestCase):
_expected_abs_ntrig_dell_xt2 = {
# A: 00 0 9600 75 0 0
- const.absolute_axes["ABS_X"]:
+ evemu.const.absolute_axes["ABS_X"]:
{"min": 0, "max": 9600, "fuzz": 75, "flat": 0, "res": 0},
# A: 01 0 7200 78 0 0
- const.absolute_axes["ABS_Y"]:
+ evemu.const.absolute_axes["ABS_Y"]:
{"min": 0, "max": 7200, "fuzz": 78, "flat": 0, "res": 0},
# A: 30 0 9600 200 0 0
- const.absolute_axes["ABS_MT_TOUCH_MAJOR"]:
+ evemu.const.absolute_axes["ABS_MT_TOUCH_MAJOR"]:
{"min": 0, "max": 9600, "fuzz": 200, "flat": 0, "res": 0},
# A: 31 0 7200 150 0 0
- const.absolute_axes["ABS_MT_TOUCH_MINOR"]:
+ evemu.const.absolute_axes["ABS_MT_TOUCH_MINOR"]:
{"min": 0, "max": 7200, "fuzz": 150, "flat": 0, "res": 0},
# A: 34 0 1 0 0 0
- const.absolute_axes["ABS_MT_ORIENTATION"]:
+ evemu.const.absolute_axes["ABS_MT_ORIENTATION"]:
{"min": 0, "max": 1, "fuzz": 0, "flat": 0, "res": 0},
# A: 35 0 9600 75 0 0
- const.absolute_axes["ABS_MT_POSITION_X"]:
+ evemu.const.absolute_axes["ABS_MT_POSITION_X"]:
{"min": 0, "max": 9600, "fuzz": 75, "flat": 0, "res": 0},
# A: 36 0 7200 78 0 0
- const.absolute_axes["ABS_MT_POSITION_Y"]:
+ evemu.const.absolute_axes["ABS_MT_POSITION_Y"]:
{"min": 0, "max": 7200, "fuzz": 78, "flat": 0, "res": 0}
}
_expected_key_ntrig_dell_xt2 = {
- const.buttons["BTN_TOUCH"]: True
+ evemu.const.buttons["BTN_TOUCH"]: True
}
def get_expected_abs(self, sub_key):
expected_items = self._expected_abs_ntrig_dell_xt2.items()
- expected = dict.fromkeys(const.absolute_axes.values(), 0)
+ expected = dict.fromkeys(evemu.const.absolute_axes.values(), 0)
expected.update((k, v[sub_key]) for (k, v) in expected_items)
return expected
def get_expected_ev_abs(self):
expected_keys = self._expected_abs_ntrig_dell_xt2.keys()
- expected = dict.fromkeys(const.absolute_axes.values(), False)
+ expected = dict.fromkeys(evemu.const.absolute_axes.values(), False)
expected.update((k, True) for k in expected_keys)
return expected
def get_expected_ev_key(self):
expected_keys = self._expected_key_ntrig_dell_xt2.keys()
- expected = dict.fromkeys(const.buttons.values(), False)
+ expected = dict.fromkeys(evemu.const.buttons.values(), False)
expected.update((k, True) for k in expected_keys)
return expected
def get_expected_prop(self):
# no props for N-Trig-MultiTouch-Virtual-Device
- return dict.fromkeys(const.absolute_axes.values(), False)
+ return dict.fromkeys(evemu.const.absolute_axes.values(), False)
diff --git a/python/evemu/tests/test_base.py b/python/evemu/tests/test_base.py
index 01dd965..60a05f9 100644
--- a/python/evemu/tests/test_base.py
+++ b/python/evemu/tests/test_base.py
@@ -1,22 +1,22 @@
import unittest
-from evemu import const
-from evemu.base import EvEmuBase
-from evemu.testing import testcase
+import evemu.base
+import evemu.const
+import evemu.testing.testcase
-class EvEmuBaseTestCase(testcase.BaseTestCase):
+class EvEmuBaseTestCase(evemu.testing.testcase.BaseTestCase):
def test_so_library_found(self):
- wrapper = EvEmuBase()
+ wrapper = evemu.base.EvEmuBase()
# Make sure that the library loads
self.assertNotEqual(
wrapper._lib._name.find("libevemu"), -1)
def test_c_symbols_found(self):
# Make sure that the expected functions are present
- wrapper = EvEmuBase()
- for function_name in const.API:
+ wrapper = evemu.base.EvEmuBase()
+ for function_name in evemu.const.API:
function = getattr(wrapper._lib, function_name)
self.assertTrue(function is not None)
diff --git a/python/evemu/tests/test_device.py b/python/evemu/tests/test_device.py
index ee6cd6e..4510ce7 100644
--- a/python/evemu/tests/test_device.py
+++ b/python/evemu/tests/test_device.py
@@ -1,13 +1,12 @@
-
-from evemu.testing import testcase
from multiprocessing import Process, Queue, Event
-import evemu
-import os
import re
import tempfile
import unittest
+import evemu
+import evemu.testing.testcase
+
def record(recording_started, device_node, q):
"""
@@ -40,7 +39,7 @@ def extract_events(data):
"""
return [line for line in data if line.startswith("E:")]
-class DeviceActionTestCase(testcase.BaseTestCase):
+class DeviceActionTestCase(evemu.testing.testcase.BaseTestCase):
"""
Verifies the high-level Device functions (create, describe, play, record).
"""
@@ -127,7 +126,7 @@ class DeviceActionTestCase(testcase.BaseTestCase):
self.assertEquals(lhs.group(1), rhs.group(1))
-class DevicePropertiesTestCase(testcase.BaseTestCase):
+class DevicePropertiesTestCase(evemu.testing.testcase.BaseTestCase):
"""
Verifies the workings of the various device property accessors.
"""
diff --git a/src/convert-old-dumps-to-1.1.py b/src/convert-old-dumps-to-1.1.py
index a224a97..d3cc420 100755
--- a/src/convert-old-dumps-to-1.1.py
+++ b/src/convert-old-dumps-to-1.1.py
@@ -9,11 +9,12 @@
# Make sure the print statement is disabled and the function is used.
from __future__ import print_function
-import re
import os
+import re
import sys
+
import evemu
-from event_names import *
+import event_names
def convert_events(lines):
event_re = re.compile(r"E: (\d+\.\d*) ([a-fA-f0-9]+) ([a-fA-f0-9]+) (-?\d*)\n")
@@ -27,13 +28,13 @@ def convert_events(lines):
value = int(value, 0)
print("E: %s %04x %04x %04d\t" % (t, type, code, value))
desc = ""
- if type == ev_map["EV_SYN"]:
+ if type == event_names.ev_map["EV_SYN"]:
if code == syn_map["SYN_MT_REPORT"]:
- print("# ++++++++++++ %s (%d) ++++++++++" % (event_get_code_name(type, code), value))
+ print("# ++++++++++++ %s (%d) ++++++++++" % (event_names.event_get_code_name(type, code), value))
else:
- print("# ------------ %s (%d) ----------" % (event_get_code_name(type, code), value))
+ print("# ------------ %s (%d) ----------" % (event_names.event_get_code_name(type, code), value))
else:
- print("# %s / %-20s %d" % ( event_get_type_name(type), event_get_code_name(type, code), value))
+ print("# %s / %-20s %d" % (event_names.event_get_type_name(type), event_get_code_name(type, code), value))
else:
print(line)
diff --git a/src/make-event-names.py b/src/make-event-names.py
index 296ae0e..bc77f2c 100755
--- a/src/make-event-names.py
+++ b/src/make-event-names.py
@@ -7,9 +7,9 @@
# Make sure the print statement is disabled and the function is used.
from __future__ import print_function
+import argparse
import re
import sys
-import argparse
SOURCE_FILE = "/usr/include/linux/input.h"
--
1.8.5.2
More information about the Input-tools
mailing list