From: Tzung-Bi Shih <tzungbi@kernel.org>
To: bleung@chromium.org, groeck@chromium.org
Cc: chrome-platform@lists.linux.dev, tzungbi@kernel.org,
guillaume.tucker@collabora.com, denys.f@collabora.com,
ricardo.canuelo@collabora.com
Subject: [PATCH 12/14] treewide: remove "r" in open() if reading mode
Date: Mon, 13 Mar 2023 17:44:29 +0800 [thread overview]
Message-ID: <20230313094431.507952-13-tzungbi@kernel.org> (raw)
In-Reply-To: <20230313094431.507952-1-tzungbi@kernel.org>
open()'s default mode is "r". To simplify, remove them if reading
mode.
Signed-off-by: Tzung-Bi Shih <tzungbi@kernel.org>
---
cros/helpers/kernel.py | 2 +-
cros/helpers/mcu.py | 8 ++++----
cros/helpers/sysfs.py | 4 ++--
cros/tests/cros_ec_accel.py | 2 +-
cros/tests/cros_ec_pwm.py | 6 +++---
cros/tests/cros_ec_rtc.py | 2 +-
setup.py | 2 +-
7 files changed, 13 insertions(+), 13 deletions(-)
diff --git a/cros/helpers/kernel.py b/cros/helpers/kernel.py
index 9e4d769c0531..c319f99a3143 100644
--- a/cros/helpers/kernel.py
+++ b/cros/helpers/kernel.py
@@ -14,7 +14,7 @@ def current_kernel_version():
""" Returns the current kernel version as an integer you can
compare.
"""
- with open("/proc/version", "r") as fh:
+ with open("/proc/version") as fh:
current = fh.read().split()[2].split("-")[0].split(".")
return version_to_int(int(current[0]), int(current[1]), int(current[2]))
diff --git a/cros/helpers/mcu.py b/cros/helpers/mcu.py
index 7d197e600f47..6c12affd4073 100644
--- a/cros/helpers/mcu.py
+++ b/cros/helpers/mcu.py
@@ -116,7 +116,7 @@ def is_feature_supported(feature):
cmd.insize = sizeof(response)
cmd.outsize = 0
- with open("/dev/cros_ec", "r") as fh:
+ with open("/dev/cros_ec") as fh:
fcntl.ioctl(fh, EC_DEV_IOCXCMD, cmd)
memmove(addressof(response), addressof(cmd.data), cmd.insize)
@@ -156,7 +156,7 @@ def mcu_hello(s, name):
cmd.outsize = sizeof(response)
memmove(addressof(cmd.data), addressof(param), cmd.insize)
- with open("/dev/" + name, "r") as fh:
+ with open("/dev/" + name) as fh:
fcntl.ioctl(fh, EC_DEV_IOCXCMD, cmd)
memmove(addressof(response), addressof(cmd.data), cmd.outsize)
@@ -174,7 +174,7 @@ def mcu_get_version(name):
cmd.insize = sizeof(response)
cmd.outsize = 0
- with open("/dev/" + name, "r") as fh:
+ with open("/dev/" + name) as fh:
fcntl.ioctl(fh, EC_DEV_IOCXCMD, cmd)
memmove(addressof(response), addressof(cmd.data), cmd.insize)
@@ -188,7 +188,7 @@ def mcu_reboot(name):
cmd.insize = 0
cmd.outsize = 0
try:
- with open("/dev/" + name, "r") as fh:
+ with open("/dev/" + name) as fh:
fcntl.ioctl(fh, EC_DEV_IOCXCMD, cmd)
except IOError:
pass
diff --git a/cros/helpers/sysfs.py b/cros/helpers/sysfs.py
index 80653fd13431..4d3b6735ef45 100755
--- a/cros/helpers/sysfs.py
+++ b/cros/helpers/sysfs.py
@@ -6,7 +6,7 @@ import os
def read_file(name):
""" Returns the content of the file named 'name'."""
- with open(name, "r") as fh:
+ with open(name) as fh:
contents = fh.read()
return contents
@@ -20,7 +20,7 @@ def sysfs_check_attributes_exists(s, path, name, files, check_devtype):
try:
for devname in os.listdir(path):
if check_devtype:
- with open(path + "/" + devname + "/name", "r") as fh:
+ with open(path + "/" + devname + "/name") as fh:
devtype = fh.read()
if not devtype.startswith(name):
continue
diff --git a/cros/tests/cros_ec_accel.py b/cros/tests/cros_ec_accel.py
index b76d2a6fbb4d..3d6a54acac16 100755
--- a/cros/tests/cros_ec_accel.py
+++ b/cros/tests/cros_ec_accel.py
@@ -57,7 +57,7 @@ class TestCrosECAccel(unittest.TestCase):
try:
for devname in os.listdir("/sys/bus/iio/devices"):
base_path = "/sys/bus/iio/devices/" + devname + "/"
- with open(base_path + "name", "r") as fh:
+ with open(base_path + "name") as fh:
devtype = fh.read()
if devtype.startswith("cros-ec-accel"):
location = read_file(base_path + "location")
diff --git a/cros/tests/cros_ec_pwm.py b/cros/tests/cros_ec_pwm.py
index 7158463b115f..6be5c292ffa2 100644
--- a/cros/tests/cros_ec_pwm.py
+++ b/cros/tests/cros_ec_pwm.py
@@ -14,19 +14,19 @@ class TestCrosECPWM(unittest.TestCase):
"""
if not os.path.exists("/sys/class/backlight/backlight/max_brightness"):
self.skipTest("No backlight pwm found, skipping")
- with open("/sys/kernel/debug/pwm", "r") as fh:
+ with open("/sys/kernel/debug/pwm") as fh:
pwm = fh.read()
for s in pwm.split('\n\n'):
if re.match(r'.*:ec-pwm.*backlight', s, re.DOTALL):
break
else:
self.skipTest("No EC backlight pwm found, skipping")
- with open("/sys/class/backlight/backlight/max_brightness", "r") as fh:
+ with open("/sys/class/backlight/backlight/max_brightness") as fh:
brightness = int(int(fh.read()) / 2)
with open("/sys/class/backlight/backlight/brightness", "w") as fh:
fh.write(str(brightness))
- with open("/sys/kernel/debug/pwm", "r") as fh:
+ with open("/sys/kernel/debug/pwm") as fh:
for line in fh:
if "backlight" in line:
start = line.find("duty") + 6
diff --git a/cros/tests/cros_ec_rtc.py b/cros/tests/cros_ec_rtc.py
index 7afed70f0429..e59fa383659d 100755
--- a/cros/tests/cros_ec_rtc.py
+++ b/cros/tests/cros_ec_rtc.py
@@ -14,7 +14,7 @@ class TestCrosECRTC(unittest.TestCase):
match = 0
try:
for devname in os.listdir("/sys/class/rtc"):
- with open("/sys/class/rtc/" + devname + "/name", "r") as fh:
+ with open("/sys/class/rtc/" + devname + "/name") as fh:
devtype = fh.read()
if devtype.startswith("cros-ec-rtc"):
files = [
diff --git a/setup.py b/setup.py
index 92e4ed794245..958aaa89e143 100644
--- a/setup.py
+++ b/setup.py
@@ -3,7 +3,7 @@
import setuptools
-with open("README.md", "r") as fh:
+with open("README.md") as fh:
long_description = fh.read()
setuptools.setup(
--
2.40.0.rc1.284.g88254d51c5-goog
next prev parent reply other threads:[~2023-03-13 9:44 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-03-13 9:44 [PATCH 00/14] cros-ec-tests: fix some exceptions and clean-ups Tzung-Bi Shih
2023-03-13 9:44 ` [PATCH 01/14] lava_runner: rename to LavaTestResult Tzung-Bi Shih
2023-03-13 9:44 ` [PATCH 02/14] lava_runner: use TextTestRunner Tzung-Bi Shih
2023-03-13 9:44 ` [PATCH 03/14] lava_runner: use TextTestResult Tzung-Bi Shih
2023-03-13 9:44 ` [PATCH 04/14] lava_runner: respect to verbosity flag from unittest framework Tzung-Bi Shih
2023-03-13 9:44 ` [PATCH 05/14] helpers/sysfs: fix NameError Tzung-Bi Shih
2023-03-13 9:44 ` [PATCH 06/14] helpers/mcu: fix ResourceWarning on /dev/cros_ec Tzung-Bi Shih
2023-03-13 9:44 ` [PATCH 07/14] cros_ec_pwm: fix ResourceWarning on /sys/kernel/debug/pwm Tzung-Bi Shih
2023-03-13 9:44 ` [PATCH 08/14] treewide: use context manager on file objects Tzung-Bi Shih
2023-03-13 9:44 ` [PATCH 09/14] cros_ec_pwm: use RE to search EC backlight PWM Tzung-Bi Shih
2023-03-13 9:44 ` [PATCH 10/14] helpers/mcu: fix packet too long error Tzung-Bi Shih
2023-03-13 9:44 ` [PATCH 11/14] helpers/mcu: fix EC_CMD_GET_FEATURES usage Tzung-Bi Shih
2023-03-13 9:44 ` Tzung-Bi Shih [this message]
2023-03-13 9:44 ` [PATCH 13/14] treewide: don't use "+" operator for constructing paths Tzung-Bi Shih
2023-03-13 9:44 ` [PATCH 14/14] treewide: don't use "+" operator for concatenating strings Tzung-Bi Shih
2023-03-13 11:53 ` [PATCH 00/14] cros-ec-tests: fix some exceptions and clean-ups Ricardo Cañuelo
2023-03-14 3:09 ` Tzung-Bi Shih
2023-03-14 6:47 ` Guillaume Charles Tucker
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230313094431.507952-13-tzungbi@kernel.org \
--to=tzungbi@kernel.org \
--cc=bleung@chromium.org \
--cc=chrome-platform@lists.linux.dev \
--cc=denys.f@collabora.com \
--cc=groeck@chromium.org \
--cc=guillaume.tucker@collabora.com \
--cc=ricardo.canuelo@collabora.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox