factory: Replace `file()` by `open()` for file opening
Because builtin `file()` is deprecated in python3.
BUG=chromium:999876
TEST=make test
TEST=umpire test
Change-Id: I9a2bb516f0e0fbe897bff9893db3592c4acac83f
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/factory/+/1924209
Commit-Queue: Yilin Yang <kerker@chromium.org>
Tested-by: Yilin Yang <kerker@chromium.org>
Reviewed-by: Yong Hong <yhong@chromium.org>
Auto-Submit: Yilin Yang <kerker@chromium.org>
diff --git a/py/instalog/daemon_utils.py b/py/instalog/daemon_utils.py
index 17e36c4..2224599 100644
--- a/py/instalog/daemon_utils.py
+++ b/py/instalog/daemon_utils.py
@@ -75,9 +75,9 @@
# Redirect standard file descriptors.
sys.stdout.flush()
sys.stderr.flush()
- si = file(self.stdin, 'r')
- so = file(self.stdout, 'a+')
- se = file(self.stderr, 'a+', 0)
+ si = open(self.stdin, 'r')
+ so = open(self.stdout, 'a+')
+ se = open(self.stderr, 'a+', 0)
os.dup2(si.fileno(), sys.stdin.fileno())
os.dup2(so.fileno(), sys.stdout.fileno())
os.dup2(se.fileno(), sys.stderr.fileno())
@@ -93,7 +93,7 @@
def _WritePID(self):
"""Writes the current process's PID to the pidfile."""
pid = str(os.getpid())
- file(self.pidfile, 'w+').write('%s\n' % pid)
+ open(self.pidfile, 'w+').write('%s\n' % pid)
def _RemovePID(self):
"""Unlinks the pidfile."""
diff --git a/py/test/event_log_watcher_unittest.py b/py/test/event_log_watcher_unittest.py
index 6ee0464..346e0e0 100755
--- a/py/test/event_log_watcher_unittest.py
+++ b/py/test/event_log_watcher_unittest.py
@@ -137,7 +137,7 @@
# Manually truncate db file.
with open(self.db, 'w') as f:
- os.ftruncate(file.fileno(f), 10)
+ os.ftruncate(f.fileno(), 10)
watcher = EventLogWatcher(MOCK_PERIOD, self.events_dir, self.db)
self.assertEqual(watcher.GetEventLog(MOCK_LOG_NAME(0)), None)
diff --git a/py/utils/file_utils.py b/py/utils/file_utils.py
index 434c9bf..9f6f33e 100644
--- a/py/utils/file_utils.py
+++ b/py/utils/file_utils.py
@@ -304,7 +304,7 @@
Args:
path: The path to touch.
"""
- with file(path, 'a'):
+ with open(path, 'a'):
os.utime(path, None)