summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLumir Balhar <lbalhar@redhat.com>2017-11-06 10:34:53 +0100
committerJiri Kastner <jkastner@redhat.com>2017-11-20 13:59:01 +0100
commit6398eee30f27b6d4f7eb3a708dd8307e14972b5b (patch)
treeae67248355b7ad2053ee5c6d323166fb96462ef2
parent08fbd6dd49029e465116d3a6d7ecdf3b885c7fe2 (diff)
downloadpython-linux-procfs-6398eee30f27b6d4f7eb3a708dd8307e14972b5b.tar.gz
python3: `open()` is preferred way for opening files.
Moreover, `file()` is not available in Python 3. Signed-off-by: Lumir Balhar <lbalhar@redhat.com> Signed-off-by: Jiri Kastner <jkastner@redhat.com>
-rwxr-xr-xprocfs/procfs.py16
-rwxr-xr-xprocfs/sysctl.py4
2 files changed, 10 insertions, 10 deletions
diff --git a/procfs/procfs.py b/procfs/procfs.py
index 9627ac5..5a069a9 100755
--- a/procfs/procfs.py
+++ b/procfs/procfs.py
@@ -320,7 +320,7 @@ class process:
return hasattr(self, attr)
def load_cmdline(self):
- f = file("/proc/%d/cmdline" % self.pid)
+ f = open("/proc/%d/cmdline" % self.pid)
self.cmdline = f.readline().strip().split('\0')[:-1]
f.close()
@@ -330,7 +330,7 @@ class process:
del self.threads[self.pid]
def load_cgroups(self):
- f = file("/proc/%d/cgroup" % self.pid)
+ f = open("/proc/%d/cgroup" % self.pid)
self.cgroups = ""
for line in reversed(f.readlines()):
if len(self.cgroups):
@@ -366,7 +366,7 @@ class process:
>>>
"""
self.environ = {}
- f = file("/proc/%d/environ" % self.pid)
+ f = open("/proc/%d/environ" % self.pid)
for x in f.readline().split('\0'):
if len(x) > 0:
y = x.split('=')
@@ -623,7 +623,7 @@ class interrupts:
def parse_affinity(self, irq):
try:
- f = file("/proc/irq/%s/smp_affinity" % irq)
+ f = open("/proc/irq/%s/smp_affinity" % irq)
line = f.readline()
f.close()
return utilist.bitmasklist(line, self.nr_cpus)
@@ -703,7 +703,7 @@ class cmdline:
self.parse()
def parse(self):
- f = file("/proc/cmdline")
+ f = open("/proc/cmdline")
for option in f.readline().strip().split():
fields = option.split("=")
if len(fields) == 1:
@@ -775,7 +775,7 @@ class cpuinfo:
return self.tags
def parse(self, filename):
- f = file(filename)
+ f = open(filename)
for line in f.readlines():
line = line.strip()
if len(line) == 0:
@@ -898,7 +898,7 @@ class smaps:
return self.entries[index]
def reload(self):
- f = file("/proc/%d/smaps" % self.pid)
+ f = open("/proc/%d/smaps" % self.pid)
line = None
while True:
line = self.parse_entry(f, line)
@@ -982,7 +982,7 @@ class cpusstats:
def reload(self):
last_entries = self.entries
self.entries = {}
- f = file(self.filename)
+ f = open(self.filename)
for line in f.readlines():
fields = line.strip().split()
if fields[0][:3].lower() != "cpu":
diff --git a/procfs/sysctl.py b/procfs/sysctl.py
index 596fb19..8b256ab 100755
--- a/procfs/sysctl.py
+++ b/procfs/sysctl.py
@@ -45,7 +45,7 @@ class sysctl:
def read(self, key):
try:
- f = file("/proc/sys/%s" % key.replace(".", "/"))
+ f = open("/proc/sys/%s" % key.replace(".", "/"))
except:
return None
value = f.readline().strip()
@@ -54,7 +54,7 @@ class sysctl:
def write(self, key, value):
try:
- f = file("/proc/sys/%s" % key.replace(".", "/"), "w")
+ f = open("/proc/sys/%s" % key.replace(".", "/"), "w")
except:
return
f.write(value)