summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYilin Yang <kerker@google.com>2020-09-22 16:11:47 +0800
committerCommit Bot <commit-bot@chromium.org>2020-09-25 09:48:19 +0000
commit9e5e0e5dba9ed3b641f3595526b2d1488b00a4b6 (patch)
treee4af0105842577cdb5aef221b7635cbb14bfa4f6
parent4747bf170d58917025889fedc93e5a0ac7db7fb1 (diff)
downloadchrome-ec-9e5e0e5dba9ed3b641f3595526b2d1488b00a4b6.tar.gz
util: Migrate inject-keys.py to python2/3 compatible
BUG=chromium:1031705 BRANCH=master TEST=`test-inject-keys.sh` pass with python2, python3 shebang Signed-off-by: kerker <kerker@chromium.org> Change-Id: I61e7fe8525f8b836dae5eedd74f090899ac019e3 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2422111 Reviewed-by: Yu-Ping Wu <yupingso@chromium.org> Reviewed-by: Jack Rosenthal <jrosenth@chromium.org>
-rwxr-xr-xutil/inject-keys.py31
1 files changed, 17 insertions, 14 deletions
diff --git a/util/inject-keys.py b/util/inject-keys.py
index 380fc34729..bd10b693ad 100755
--- a/util/inject-keys.py
+++ b/util/inject-keys.py
@@ -1,10 +1,13 @@
-#!/usr/bin/env python2
+#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Copyright 2016 The Chromium OS Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
+# Note: This is a py2/3 compatible file.
+
+from __future__ import print_function
import string
import subprocess
import sys
@@ -44,7 +47,7 @@ def inject_event(key, press):
if len(key) >= 2 and key[0] != '<':
key = '<' + key + '>'
if key not in KEYMATRIX:
- print "%s: invalid key: %s" % (this_script, key)
+ print("%s: invalid key: %s" % (this_script, key))
sys.exit(1)
(row, col) = KEYMATRIX[key]
subprocess.call(["ectool", "kbpress", str(row), str(col),
@@ -65,35 +68,35 @@ def inject_string(string):
inject_key(UNSHIFT_TABLE[c])
inject_event("<shift_l>", False)
else:
- print "unimplemented character:", c
+ print("unimplemented character:", c)
sys.exit(1)
def usage():
- print "Usage: %s [-s <string>] [-k <key>]" % this_script, \
- "[-p <pressed-key>] [-r <released-key>] ..."
- print "Examples:"
- print "%s -s MyPassw0rd -k enter" % this_script
- print "%s -p ctrl_l -p alt_l -k f3 -r alt_l -r ctrl_l" % this_script
+ print("Usage: %s [-s <string>] [-k <key>]" % this_script,
+ "[-p <pressed-key>] [-r <released-key>] ...")
+ print("Examples:")
+ print("%s -s MyPassw0rd -k enter" % this_script)
+ print("%s -p ctrl_l -p alt_l -k f3 -r alt_l -r ctrl_l" % this_script)
def help():
usage()
- print "Valid keys are:"
+ print("Valid keys are:")
i = 0
for key in KEYMATRIX:
- print "%12s" % key,
+ print("%12s" % key, end='')
i += 1
if i % 4 == 0:
- print
- print
- print "angle brackets may be omitted"
+ print()
+ print()
+ print("angle brackets may be omitted")
def usage_check(asserted_condition, message):
if asserted_condition:
return
- print "%s:" % this_script, message
+ print("%s:" % this_script, message)
usage()
sys.exit(1)