From patchwork Mon Dec 14 17:01:06 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Markus Theil X-Patchwork-Id: 11972505 X-Patchwork-Delegate: johannes@sipsolutions.net Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.7 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id AECFEC2BB48 for ; Mon, 14 Dec 2020 17:03:14 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 583A42250F for ; Mon, 14 Dec 2020 17:03:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2395200AbgLNRCo (ORCPT ); Mon, 14 Dec 2020 12:02:44 -0500 Received: from smail.rz.tu-ilmenau.de ([141.24.186.67]:48827 "EHLO smail.rz.tu-ilmenau.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2395530AbgLNRC2 (ORCPT ); Mon, 14 Dec 2020 12:02:28 -0500 Received: from isengard.fritz.box (unknown [93.209.13.218]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smail.rz.tu-ilmenau.de (Postfix) with ESMTPSA id 329D958007E; Mon, 14 Dec 2020 18:01:39 +0100 (CET) From: Markus Theil To: johannes@sipsolutions.net Cc: linux-wireless@vger.kernel.org, Markus Theil Subject: [PATCH] rfkill.py: migrate to python3 Date: Mon, 14 Dec 2020 18:01:06 +0100 Message-Id: <20201214170106.31420-1-markus.theil@tu-ilmenau.de> X-Mailer: git-send-email 2.29.2 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org Signed-off-by: Markus Theil --- 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"))