Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp2763504pxu; Mon, 14 Dec 2020 10:17:09 -0800 (PST) X-Google-Smtp-Source: ABdhPJxaOH3TjFFqgfne/DYDDm5e9V7qQu9aDffMSPV6T6FGOTzxj6xYBt0bXXZ+2OzIdLvGge4F X-Received: by 2002:a17:906:179a:: with SMTP id t26mr4945878eje.49.1607969828851; Mon, 14 Dec 2020 10:17:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1607969828; cv=none; d=google.com; s=arc-20160816; b=OUIJ6neHoDikzJ8ch7yX0IgKc1wwKW/H7B9xGW4M/TqS6i0xfGE27ioVcX65aEMC82 rA1xNQTR663P7WieOSBTs+CqRa8K6bLYxjeBwQJzcIvxm0jeNwEBDWc0xapqlpujnzeq KdDEGYDCBCLO2bEsg7UIiQfLbzGmolZprIb2chi7IcA2d23w5u8ztCuqe/JoE5xKBvcp PV8DjlZfLJuzzolJVDLHrnECal3r2mYNbJIz8iK6RgYuomIex2KD71WWvCwpvi7+UxGg 1QC9FIAQAAmptBDfpN03X/YI8le5YRVKnyX0bTOFvcPG1trPKDEbV6FqJLYRaxQRbBEF +oZA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=ZCUeQonihv3NzSuoCHD4a4axjZ9nx+7YaTGgjugwR0w=; b=u4ynNaGQg4xSM1gIyLIinA+4zo2FroDFD8I+XY2my2qSqHzuPYHyZEHREJlnWehDHz uVLJnNeCIR04t/9V87F5p0TN/NEU+evVbGUoT1fjFOgTfN+hkIftVJ10wpPuHY2ZGJeM KzyFlYGxKm53lqj+JwUSgxdNv9DdMMqcY2UnqpwVSvhPCMtHBntLltNy/r28dpxVeo2B X9Db+XP5haqQMg6dkOmgXBKKTieoGdPmzzPXW0g0L8ZHL9g5m6JW1AKZ/drm4IP+i1db CIxQCZ49ZfMClgEj5tVI0i2czsIJ5rKaNVrx4Z99Jj+jKweKO+L23+iMZNg798SbTrwF 5EDA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a15si11145544edm.287.2020.12.14.10.16.26; Mon, 14 Dec 2020 10:17:08 -0800 (PST) Received-SPF: pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2395200AbgLNRCo (ORCPT + 99 others); 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 Content-Transfer-Encoding: 8bit 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")) -- 2.29.2