@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
#
# rfkill control code
#
@@ -21,12 +21,12 @@ import os
TYPE_WWAN,
TYPE_GPS,
TYPE_FM,
- TYPE_NFC) = range(9)
+ TYPE_NFC) = list(range(9))
(_OP_ADD,
_OP_DEL,
_OP_CHANGE,
- _OP_CHANGE_ALL) = range(4)
+ _OP_CHANGE_ALL) = list(range(4))
_type_names = {
TYPE_ALL: "all",
@@ -84,7 +84,7 @@ class RFKill(object):
@property
def soft_blocked(self):
return self.blocked[0]
-
+
@soft_blocked.setter
def soft_blocked(self, block):
if block:
@@ -97,28 +97,28 @@ class RFKill(object):
return self.blocked[1]
def block(self):
- rfk = open('/dev/rfkill', 'w')
+ rfk = open('/dev/rfkill', 'wb')
s = struct.pack(_event_struct, self.idx, TYPE_ALL, _OP_CHANGE, 1, 0)
rfk.write(s)
rfk.close()
def unblock(self):
- rfk = open('/dev/rfkill', 'w')
+ rfk = open('/dev/rfkill', 'wb')
s = struct.pack(_event_struct, self.idx, TYPE_ALL, _OP_CHANGE, 0, 0)
rfk.write(s)
rfk.close()
@classmethod
def block_all(cls, t=TYPE_ALL):
- rfk = open('/dev/rfkill', 'w')
- print rfk
+ rfk = open('/dev/rfkill', 'wb')
+ print(rfk)
s = struct.pack(_event_struct, 0, t, _OP_CHANGE_ALL, 1, 0)
rfk.write(s)
rfk.close()
@classmethod
def unblock_all(cls, t=TYPE_ALL):
- rfk = open('/dev/rfkill', 'w')
+ rfk = open('/dev/rfkill', 'wb')
s = struct.pack(_event_struct, 0, t, _OP_CHANGE_ALL, 0, 0)
rfk.write(s)
rfk.close()
@@ -126,7 +126,7 @@ class RFKill(object):
@classmethod
def list(cls):
res = []
- rfk = open('/dev/rfkill', 'r')
+ rfk = open('/dev/rfkill', 'rb')
fd = rfk.fileno()
flgs = fcntl.fcntl(fd, fcntl.F_GETFL)
fcntl.fcntl(fd, fcntl.F_SETFL, flgs | os.O_NONBLOCK)
@@ -141,10 +141,12 @@ class RFKill(object):
res.append((r, _s, _h))
except IOError:
break
+ except TypeError:
+ break
return res
if __name__ == "__main__":
for r, s, h in RFKill.list():
- print "%d: %s: %s" % (r.idx, r.name, r.type_name)
- print "\tSoft blocked: %s" % ("yes" if s else "no")
- print "\tHard blocked: %s" % ("yes" if h else "no")
+ print("%d: %s: %s" % (r.idx, r.name, r.type_name))
+ print("\tSoft blocked: %s" % ("yes" if s else "no"))
+ print("\tHard blocked: %s" % ("yes" if h else "no"))
Signed-off-by: Markus Theil <markus.theil@tu-ilmenau.de> --- rfkill.py | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-)