linux-wireless.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Markus Theil <markus.theil@tu-ilmenau.de>
To: johannes@sipsolutions.net
Cc: linux-wireless@vger.kernel.org,
	Markus Theil <markus.theil@tu-ilmenau.de>
Subject: [PATCH 1/4] rfkill.py: migrate to python3
Date: Sat, 16 Jan 2021 13:51:43 +0100	[thread overview]
Message-ID: <20210116125146.31932-2-markus.theil@tu-ilmenau.de> (raw)
In-Reply-To: <20210116125146.31932-1-markus.theil@tu-ilmenau.de>

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.30.0


  reply	other threads:[~2021-01-16 12:52 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-16 12:51 [PATCH 0/4] Updates for rfkill Markus Theil
2021-01-16 12:51 ` Markus Theil [this message]
2021-01-16 12:51 ` [PATCH 2/4] rfkill: update rfkill.h Markus Theil
2021-01-16 12:51 ` [PATCH 3/4] rfkill: support hard block reason in python code Markus Theil
2021-01-16 12:51 ` [PATCH 4/4] rfkill: support hard block reason in C code Markus Theil
2021-01-21 12:24 ` [PATCH 0/4] Updates for rfkill Johannes Berg

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210116125146.31932-2-markus.theil@tu-ilmenau.de \
    --to=markus.theil@tu-ilmenau.de \
    --cc=johannes@sipsolutions.net \
    --cc=linux-wireless@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).