mirror of
https://github.com/alsa-project/alsa-tools.git
synced 2026-03-09 05:33:49 -04:00
hwmixvolume: use a with context to open files
This feature has been added in Python 2.5 and automatically closes an open file once the context exits. Signed-off-by: Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> Reviewed-by: Takashi Sakamoto <o-takashi@sakamocchi.jp> Signed-off-by: Takashi Iwai <tiwai@suse.de>
This commit is contained in:
parent
a21dda3d86
commit
213b28a5aa
1 changed files with 6 additions and 12 deletions
|
|
@ -138,26 +138,20 @@ class Stream:
|
||||||
subdevice = info.index
|
subdevice = info.index
|
||||||
filename = "/proc/asound/card%d/pcm%dp/sub%d/status" % (card, device, subdevice)
|
filename = "/proc/asound/card%d/pcm%dp/sub%d/status" % (card, device, subdevice)
|
||||||
try:
|
try:
|
||||||
f = open(filename, "r")
|
with open(filename, "r") as f:
|
||||||
|
for line in f:
|
||||||
|
if line[:9] == "owner_pid":
|
||||||
|
return int(line.split(':')[1].strip())
|
||||||
except IOError:
|
except IOError:
|
||||||
return None
|
return None
|
||||||
try:
|
|
||||||
for line in f.readlines():
|
|
||||||
if line[:9] == "owner_pid":
|
|
||||||
return int(line.split(':')[1].strip())
|
|
||||||
finally:
|
|
||||||
f.close()
|
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def get_pid_cmdline(self, pid):
|
def get_pid_cmdline(self, pid):
|
||||||
try:
|
try:
|
||||||
f = open("/proc/%d/cmdline" % pid, "r")
|
with open("/proc/%d/cmdline" % pid, "r") as f:
|
||||||
|
cmdline = f.read()
|
||||||
except IOError:
|
except IOError:
|
||||||
return None
|
return None
|
||||||
try:
|
|
||||||
cmdline = f.read()
|
|
||||||
finally:
|
|
||||||
f.close()
|
|
||||||
return cmdline.replace('\x00', ' ').strip()
|
return cmdline.replace('\x00', ' ').strip()
|
||||||
|
|
||||||
class MixerWindow(Gtk.Window):
|
class MixerWindow(Gtk.Window):
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue