tests: rfkill with python3 compatible version
Update rfkill helpers to not depend on python2 implicit conversions. Signed-off-by: Masashi Honma <masashi.honma@gmail.com>
This commit is contained in:
parent
a3e00682ab
commit
1cfaecf70e
1 changed files with 7 additions and 5 deletions
|
@ -97,20 +97,20 @@ class RFKill(object):
|
||||||
return self.blocked[1]
|
return self.blocked[1]
|
||||||
|
|
||||||
def block(self):
|
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)
|
s = struct.pack(_event_struct, self.idx, TYPE_ALL, _OP_CHANGE, 1, 0)
|
||||||
rfk.write(s)
|
rfk.write(s)
|
||||||
rfk.close()
|
rfk.close()
|
||||||
|
|
||||||
def unblock(self):
|
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)
|
s = struct.pack(_event_struct, self.idx, TYPE_ALL, _OP_CHANGE, 0, 0)
|
||||||
rfk.write(s)
|
rfk.write(s)
|
||||||
rfk.close()
|
rfk.close()
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def block_all(cls, t=TYPE_ALL):
|
def block_all(cls, t=TYPE_ALL):
|
||||||
rfk = open('/dev/rfkill', 'w')
|
rfk = open('/dev/rfkill', 'wb')
|
||||||
print(rfk)
|
print(rfk)
|
||||||
s = struct.pack(_event_struct, 0, t, _OP_CHANGE_ALL, 1, 0)
|
s = struct.pack(_event_struct, 0, t, _OP_CHANGE_ALL, 1, 0)
|
||||||
rfk.write(s)
|
rfk.write(s)
|
||||||
|
@ -118,7 +118,7 @@ class RFKill(object):
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def unblock_all(cls, t=TYPE_ALL):
|
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)
|
s = struct.pack(_event_struct, 0, t, _OP_CHANGE_ALL, 0, 0)
|
||||||
rfk.write(s)
|
rfk.write(s)
|
||||||
rfk.close()
|
rfk.close()
|
||||||
|
@ -126,13 +126,15 @@ class RFKill(object):
|
||||||
@classmethod
|
@classmethod
|
||||||
def list(cls):
|
def list(cls):
|
||||||
res = []
|
res = []
|
||||||
rfk = open('/dev/rfkill', 'r')
|
rfk = open('/dev/rfkill', 'rb')
|
||||||
fd = rfk.fileno()
|
fd = rfk.fileno()
|
||||||
flgs = fcntl.fcntl(fd, fcntl.F_GETFL)
|
flgs = fcntl.fcntl(fd, fcntl.F_GETFL)
|
||||||
fcntl.fcntl(fd, fcntl.F_SETFL, flgs | os.O_NONBLOCK)
|
fcntl.fcntl(fd, fcntl.F_SETFL, flgs | os.O_NONBLOCK)
|
||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
d = rfk.read(_event_sz)
|
d = rfk.read(_event_sz)
|
||||||
|
if d == None:
|
||||||
|
break
|
||||||
_idx, _t, _op, _s, _h = struct.unpack(_event_struct, d)
|
_idx, _t, _op, _s, _h = struct.unpack(_event_struct, d)
|
||||||
if _op != _OP_ADD:
|
if _op != _OP_ADD:
|
||||||
continue
|
continue
|
||||||
|
|
Loading…
Reference in a new issue