[PATCH v2 evemu 11/13] python: use the evemu_read_event wrapper to convert recordings
Peter Hutterer
peter.hutterer at who-t.net
Sun Aug 3 21:38:11 PDT 2014
Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
---
Changes to v1:
- drop the regex matching, leave that up to the library
- event printing is still left here, it's in the next patch (and you'll see why :)
python/evemu/__init__.py | 13 +++++++++++++
src/convert-old-dumps-to-1.1.py | 27 ++-------------------------
2 files changed, 15 insertions(+), 25 deletions(-)
diff --git a/python/evemu/__init__.py b/python/evemu/__init__.py
index ea0901d..a35f1fa 100644
--- a/python/evemu/__init__.py
+++ b/python/evemu/__init__.py
@@ -40,6 +40,19 @@ class InputEvent(object):
self.code = code
self.value = value
+ def __str__(self):
+ type, code, value = self.type, self.code, self.value
+
+ s = "E: %d.%d %04x %04x %04d\t" % (self.sec, self.usec, type, code, value)
+ if type == event_names.ev_map["EV_SYN"]:
+ if code == event_names.syn_map["SYN_MT_REPORT"]:
+ s += "# ++++++++++++ %s (%d) ++++++++++" % (event_names.event_get_code_name(type, code), value)
+ else:
+ s += "# ------------ %s (%d) ----------" % (event_names.event_get_code_name(type, code), value)
+ else:
+ s += "# %s / %-20s %d" % (event_names.event_get_type_name(type), event_names.event_get_code_name(type, code), value)
+ return s
+
class Device(object):
"""
Encapsulates a raw kernel input event device, either an existing one as
diff --git a/src/convert-old-dumps-to-1.1.py b/src/convert-old-dumps-to-1.1.py
index 4caf4df..01362fb 100755
--- a/src/convert-old-dumps-to-1.1.py
+++ b/src/convert-old-dumps-to-1.1.py
@@ -17,40 +17,17 @@ import sys
import evemu
import evemu.event_names
-def convert_events(lines):
- event_re = re.compile(r"E: (\d+\.\d*) ([a-fA-f0-9]+) ([a-fA-f0-9]+) (-?\d*)\n")
-
- for line in lines:
- m = event_re.match(line)
- if m:
- t, type, code, value = m.groups()
- type = int(type, 16)
- code = int(code, 16)
- value = int(value, 0)
- print("E: %s %04x %04x %04d\t" % (t, type, code, value))
- desc = ""
- if type == event_names.ev_map["EV_SYN"]:
- if code == syn_map["SYN_MT_REPORT"]:
- print("# ++++++++++++ %s (%d) ++++++++++" % (event_names.event_get_code_name(type, code), value))
- else:
- print("# ------------ %s (%d) ----------" % (event_names.event_get_code_name(type, code), value))
- else:
- print("# %s / %-20s %d" % (event_names.event_get_type_name(type), event_names.event_get_code_name(type, code), value))
- else:
- print(line)
-
def usage(args):
print("%s mydev.desc [mydev.events]" % os.path.basename(args[0]))
return 1
-
if __name__ == "__main__":
if len(sys.argv) < 2:
exit(usage(sys.argv))
file_desc = sys.argv[1]
d = evemu.Device(file_desc, create=False)
d.describe(sys.stdout)
- d = None
if len(sys.argv) > 2:
with open(sys.argv[2]) as f:
- convert_events(f.readlines())
+ for e in d.events(f):
+ print(e)
--
1.9.3
More information about the Input-tools
mailing list