linux-wireless.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] rfkill.py: migrate to python3
@ 2020-12-14 17:01 Markus Theil
  0 siblings, 0 replies; only message in thread
From: Markus Theil @ 2020-12-14 17:01 UTC (permalink / raw)
  To: johannes; +Cc: linux-wireless, Markus Theil

Signed-off-by: Markus Theil <markus.theil@tu-ilmenau.de>
---
 rfkill.py | 28 +++++++++++++++-------------
 1 file changed, 15 insertions(+), 13 deletions(-)

diff --git a/rfkill.py b/rfkill.py
index 57dcddc..983671f 100755
--- a/rfkill.py
+++ b/rfkill.py
@@ -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"))
-- 
2.29.2


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2020-12-14 17:03 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-14 17:01 [PATCH] rfkill.py: migrate to python3 Markus Theil

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).