From patchwork Fri May 7 11:16:45 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Tremer X-Patchwork-Id: 4249 Return-Path: Received: from mail01.ipfire.org (mail01.haj.ipfire.org [172.28.1.202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) client-signature ECDSA (P-384)) (Client CN "mail01.haj.ipfire.org", Issuer "R3" (verified OK)) by web04.haj.ipfire.org (Postfix) with ESMTPS id 4Fc7Fb4PWFz44R5 for ; Fri, 7 May 2021 11:17:07 +0000 (UTC) Received: from mail02.haj.ipfire.org (mail02.haj.ipfire.org [172.28.1.201]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) client-signature ECDSA (P-384)) (Client CN "mail02.haj.ipfire.org", Issuer "R3" (verified OK)) by mail01.ipfire.org (Postfix) with ESMTPS id 4Fc7FX4gt3z2cf; Fri, 7 May 2021 11:17:04 +0000 (UTC) Received: from mail02.haj.ipfire.org (localhost [127.0.0.1]) by mail02.haj.ipfire.org (Postfix) with ESMTP id 4Fc7FX3Cxnz2ylY; Fri, 7 May 2021 11:17:04 +0000 (UTC) Received: from mail01.ipfire.org (mail01.haj.ipfire.org [172.28.1.202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) client-signature ECDSA (P-384)) (Client CN "mail01.haj.ipfire.org", Issuer "R3" (verified OK)) by mail02.haj.ipfire.org (Postfix) with ESMTPS id 4Fc7FW3sfKz2xSX for ; Fri, 7 May 2021 11:17:03 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by mail01.ipfire.org (Postfix) with ESMTPSA id 4Fc7FV75Nhzxb; Fri, 7 May 2021 11:17:02 +0000 (UTC) DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=ipfire.org; s=202003ed25519; t=1620386223; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=0t4lGqZVpwU+o+6vIPl5P9sf9GULF+TWr2PAY5cqwpQ=; b=vevQo2DJYFrWMviFMK9shusltcBYIfeijX7XSzcJ7h8TLCzYuHTlXuRLAfwXEKXykS5hfH PALUjYL8C6PgYjAQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ipfire.org; s=202003rsa; t=1620386223; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=0t4lGqZVpwU+o+6vIPl5P9sf9GULF+TWr2PAY5cqwpQ=; b=RLRUp40oAGpkKIbPuMpKteQQ+2GW4HG0alx1gRyptFAT37izWgTHlDs2gLp6uRCe+yHYlW VPPtuASx/L1m/SXmkixBHY+/sAD64tusca2X6OUmArLHIxpJIxVadpgHSgK/ZpVuULc2Bw wPDteXMJ/ui0Oy1xqSyfM68N0PMQKyMneFY5RsQcGxwAXwVrmgNeHWNhaJLyr9yFxvUERO 69wcZCcSnQLvPvoaJNi+9Ir10C8QzALIaXz7tGjas7TxmOOBCybR4RybqBK1//UeGLUK22 36b3Un9xdbd5+CF28JPoeoKwOqE6HBqczlxZm3Zo1FRvbwBuCc2lxyEpTEBmJQ== From: Michael Tremer To: development@lists.ipfire.org Subject: [PATCH 01/10] configure: Link against Python 3 Date: Fri, 7 May 2021 11:16:45 +0000 Message-Id: <20210507111654.2397-2-michael.tremer@ipfire.org> In-Reply-To: <20210507111654.2397-1-michael.tremer@ipfire.org> References: <74B08C60-EBDB-4C2E-83E0-A5EB5A0C3C5E@ipfire.org> <20210507111654.2397-1-michael.tremer@ipfire.org> MIME-Version: 1.0 X-BeenThere: development@lists.ipfire.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: IPFire development talk List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Michael Tremer Errors-To: development-bounces@lists.ipfire.org Sender: "Development" Signed-off-by: Michael Tremer --- configure.ac | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index 4696d6b..1ce3329 100644 --- a/configure.ac +++ b/configure.ac @@ -90,7 +90,7 @@ CC_CHECK_FLAGS_APPEND([with_ldflags], [LDFLAGS], [\ AC_SUBST([OUR_LDFLAGS], $with_ldflags) # Python -AM_PATH_PYTHON([2.7]) +AM_PATH_PYTHON([3.7]) PKG_CHECK_MODULES([PYTHON_DEVEL], [python-${PYTHON_VERSION}]) AC_CONFIG_FILES([ From patchwork Fri May 7 11:16:46 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Tremer X-Patchwork-Id: 4250 Return-Path: Received: from mail01.ipfire.org (mail01.haj.ipfire.org [172.28.1.202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) client-signature ECDSA (P-384)) (Client CN "mail01.haj.ipfire.org", Issuer "R3" (verified OK)) by web04.haj.ipfire.org (Postfix) with ESMTPS id 4Fc7Fc4K89z44RX for ; Fri, 7 May 2021 11:17:08 +0000 (UTC) Received: from mail02.haj.ipfire.org (mail02.haj.ipfire.org [172.28.1.201]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) client-signature ECDSA (P-384)) (Client CN "mail02.haj.ipfire.org", Issuer "R3" (verified OK)) by mail01.ipfire.org (Postfix) with ESMTPS id 4Fc7FY41xCz2cD; Fri, 7 May 2021 11:17:05 +0000 (UTC) Received: from mail02.haj.ipfire.org (localhost [127.0.0.1]) by mail02.haj.ipfire.org (Postfix) with ESMTP id 4Fc7FY3vR3z2yjX; Fri, 7 May 2021 11:17:05 +0000 (UTC) Received: from mail01.ipfire.org (mail01.haj.ipfire.org [172.28.1.202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) client-signature ECDSA (P-384)) (Client CN "mail01.haj.ipfire.org", Issuer "R3" (verified OK)) by mail02.haj.ipfire.org (Postfix) with ESMTPS id 4Fc7FW4hX0z2ySY for ; Fri, 7 May 2021 11:17:03 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by mail01.ipfire.org (Postfix) with ESMTPSA id 4Fc7FW34kDzWZ; Fri, 7 May 2021 11:17:03 +0000 (UTC) DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=ipfire.org; s=202003ed25519; t=1620386223; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=O9IbwzAySZfDNncv40efKbi97hQjo3m+yYt3fYtbm1w=; b=GAAEGjOF3TEq3fVFB9wgtJhuqx2SdSnq2LICBH/WI2TMyG15bfpen4hXQRD+WZEVl7KMOI R3DdfojzU7r7o9AQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ipfire.org; s=202003rsa; t=1620386223; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=O9IbwzAySZfDNncv40efKbi97hQjo3m+yYt3fYtbm1w=; b=AD1yyh030ACHsN7TFWC0j/QSHDV4CBdabkZOA3IatL1NjtASaWe8tdngi1hnGa0q6NSiks NRdyLSV3QXCHEqQWdGRo58a38m6Tn718VO/GK3xW+Dcq1yxTBp8xPSRluQtpHoNXoldHYl GO/wFO/OOVWgDP5LYrgPcHuyvEidmLLcMjgorGJOg17kYrh7a8D5NZUy4XQBksWtGqYhPD I3vsyvzte3Oh6YRKS7kJoTUjt/wFsFHG2FeE9zUf5hKyUtZ1b3hYI2xOERY6vharN3g5ki c+5fS5FaUbVwDQZGzDqKPadevf8AcsZlo4lFeWelL+dXjX20X0wYutPFAuAk2g== From: Michael Tremer To: development@lists.ipfire.org Subject: [PATCH 02/10] _fireinfo: Migrate to Python 3 Date: Fri, 7 May 2021 11:16:46 +0000 Message-Id: <20210507111654.2397-3-michael.tremer@ipfire.org> In-Reply-To: <20210507111654.2397-1-michael.tremer@ipfire.org> References: <74B08C60-EBDB-4C2E-83E0-A5EB5A0C3C5E@ipfire.org> <20210507111654.2397-1-michael.tremer@ipfire.org> MIME-Version: 1.0 X-BeenThere: development@lists.ipfire.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: IPFire development talk List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Michael Tremer Errors-To: development-bounces@lists.ipfire.org Sender: "Development" Signed-off-by: Michael Tremer --- src/_fireinfo/fireinfo.c | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/src/_fireinfo/fireinfo.c b/src/_fireinfo/fireinfo.c index 6601c21..58ee7e2 100644 --- a/src/_fireinfo/fireinfo.c +++ b/src/_fireinfo/fireinfo.c @@ -185,7 +185,7 @@ do_detect_hypervisor() { if (!hypervisor_vendor) Py_RETURN_NONE; - return PyString_FromString(hypervisor_vendor); + return PyUnicode_FromString(hypervisor_vendor); } Py_RETURN_NONE; @@ -215,22 +215,30 @@ do_get_harddisk_serial(PyObject *o, PyObject *args) { strncpy(serial, (const char *)hd.serial_no, sizeof(serial) - 1); if (serial[0]) - return PyString_FromString(serial); + return PyUnicode_FromString(serial); } Py_RETURN_NONE; } -static PyMethodDef fireinfoModuleMethods[] = { +static PyMethodDef fireinfo_methods[] = { { "detect_hypervisor", (PyCFunction) do_detect_hypervisor, METH_NOARGS, NULL }, { "get_harddisk_serial", (PyCFunction) do_get_harddisk_serial, METH_VARARGS, NULL }, { NULL, NULL, 0, NULL } }; -void init_fireinfo(void) { - PyObject *m; +static struct PyModuleDef fireinfo_module = { + .m_base = PyModuleDef_HEAD_INIT, + .m_name = "_fireinfo", + .m_size = -1, + .m_doc = "Python module for fireinfo", + .m_methods = fireinfo_methods, +}; + +PyMODINIT_FUNC PyInit__fireinfo(void) { + PyObject* m = PyModule_Create(&fireinfo_module); + if (!m) + return NULL; - m = Py_InitModule("_fireinfo", fireinfoModuleMethods); - if (m == NULL) - return; + return m; } From patchwork Fri May 7 11:16:47 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Tremer X-Patchwork-Id: 4251 Return-Path: Received: from mail01.ipfire.org (mail01.haj.ipfire.org [172.28.1.202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) client-signature ECDSA (P-384)) (Client CN "mail01.haj.ipfire.org", Issuer "R3" (verified OK)) by web04.haj.ipfire.org (Postfix) with ESMTPS id 4Fc7Ff48KMz44R5 for ; Fri, 7 May 2021 11:17:10 +0000 (UTC) Received: from mail02.haj.ipfire.org (mail02.haj.ipfire.org [172.28.1.201]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) client-signature ECDSA (P-384)) (Client CN "mail02.haj.ipfire.org", Issuer "R3" (verified OK)) by mail01.ipfire.org (Postfix) with ESMTPS id 4Fc7FY4wgrz36v; Fri, 7 May 2021 11:17:05 +0000 (UTC) Received: from mail02.haj.ipfire.org (localhost [127.0.0.1]) by mail02.haj.ipfire.org (Postfix) with ESMTP id 4Fc7FY4dPLz2ylP; Fri, 7 May 2021 11:17:05 +0000 (UTC) Received: from mail01.ipfire.org (mail01.haj.ipfire.org [172.28.1.202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) client-signature ECDSA (P-384)) (Client CN "mail01.haj.ipfire.org", Issuer "R3" (verified OK)) by mail02.haj.ipfire.org (Postfix) with ESMTPS id 4Fc7FW5Tpqz2xpc for ; Fri, 7 May 2021 11:17:03 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by mail01.ipfire.org (Postfix) with ESMTPSA id 4Fc7FW3tRLz1Sm; Fri, 7 May 2021 11:17:03 +0000 (UTC) DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=ipfire.org; s=202003ed25519; t=1620386223; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=BMqV465+z5qsosOMUh++gNaf2kusnDVq4poBJ36ySZQ=; b=Vse3u4jIsxjbrHbWaFZlaOwXydqXHFC/DLuDZIVu0odcvmPEzwRcuqjmV3+8wdsZ6MHItz sh2so7buiHnI+NAg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ipfire.org; s=202003rsa; t=1620386223; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=BMqV465+z5qsosOMUh++gNaf2kusnDVq4poBJ36ySZQ=; b=Mzj2nF1pphxQ/rc+o1FH7HDP0Srn3ayebhgeWJJQf2XVpAUWE/kB3rQji3Qt4ntyA9j3Nx +hHCEVa5lmWCyuyEVwMY0tKC8T0sbSnWH2uccb0lD66Rm6GddasLqvC1/ebsV4LyX+pJOn t3LhstciE0yUNRaA0gChQ3qgD3/AN9/UEVv9dugGfvIworVYRLa1ZyadRDu1tT1K7H5ep+ PcHdoBZDNYzosG4Cj8H8Ggs6MKDHAXWO675cWRwri4b+AHGA6xq1/zBH0E5DZGMm0Lrkbh hdTMXNoGiM2xIGkdK3ZTWqLnNBWH+rx9zPPl5RiWxc1YcELVYV4JCpd9LZ9ZBg== From: Michael Tremer To: development@lists.ipfire.org Subject: [PATCH 03/10] _fireinfo: Refactor some code Date: Fri, 7 May 2021 11:16:47 +0000 Message-Id: <20210507111654.2397-4-michael.tremer@ipfire.org> In-Reply-To: <20210507111654.2397-1-michael.tremer@ipfire.org> References: <74B08C60-EBDB-4C2E-83E0-A5EB5A0C3C5E@ipfire.org> <20210507111654.2397-1-michael.tremer@ipfire.org> MIME-Version: 1.0 X-BeenThere: development@lists.ipfire.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: IPFire development talk List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Michael Tremer Errors-To: development-bounces@lists.ipfire.org Sender: "Development" No functional changes. This only makes the code more similar to what I am writing in other projects and makes it tidier. Signed-off-by: Michael Tremer --- src/_fireinfo/fireinfo.c | 35 ++++++++++++++++++----------------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/src/_fireinfo/fireinfo.c b/src/_fireinfo/fireinfo.c index 58ee7e2..75ccb2c 100644 --- a/src/_fireinfo/fireinfo.c +++ b/src/_fireinfo/fireinfo.c @@ -58,23 +58,22 @@ const char *hypervisor_vendors[] = { #define NEWLINE "\n\r" -char *truncate_nl(char *s) { +static void truncate_nl(char *s) { assert(s); - s[strcspn(s, NEWLINE)] = 0; - return s; + s[strcspn(s, NEWLINE)] = '\0'; } -int read_one_line_file(const char *filename, char **line) { - assert(filename); - assert(line); +static int read_one_line_file(const char *filename, char **line) { + char t[2048]; + + if (!filename || !line) + return -EINVAL; - FILE *f = NULL; - f = fopen(filename, "re"); + FILE* f = fopen(filename, "re"); if (!f) return -errno; - char t[2048]; if (!fgets(t, sizeof(t), f)) { if (ferror(f)) return errno ? -errno : -EIO; @@ -85,6 +84,7 @@ int read_one_line_file(const char *filename, char **line) { char *c = strdup(t); if (!c) return -ENOMEM; + truncate_nl(c); *line = c; @@ -171,7 +171,6 @@ int detect_hypervisor(int *hypervisor) { return 0; } - static PyObject * do_detect_hypervisor() { /* @@ -197,27 +196,29 @@ do_get_harddisk_serial(PyObject *o, PyObject *args) { Python wrapper around read_harddisk_serial. */ static struct hd_driveid hd; - int fd; const char *device = NULL; + char serial[21]; if (!PyArg_ParseTuple(args, "s", &device)) return NULL; - if ((fd = open(device, O_RDONLY | O_NONBLOCK)) < 0) { + int fd = open(device, O_RDONLY | O_NONBLOCK); + if (fd < 0) { PyErr_Format(PyExc_OSError, "Could not open block device: %s", device); return NULL; } if (!ioctl(fd, HDIO_GET_IDENTITY, &hd)) { - char serial[21]; - memset(serial, 0, sizeof(serial)); - - strncpy(serial, (const char *)hd.serial_no, sizeof(serial) - 1); + snprintf(serial, sizeof(serial) - 1, "%s", (const char *)hd.serial_no); - if (serial[0]) + if (*serial) { + close(fd); return PyUnicode_FromString(serial); + } } + close(fd); + Py_RETURN_NONE; } From patchwork Fri May 7 11:16:48 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Tremer X-Patchwork-Id: 4252 Return-Path: Received: from mail01.ipfire.org (mail01.haj.ipfire.org [172.28.1.202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) client-signature ECDSA (P-384)) (Client CN "mail01.haj.ipfire.org", Issuer "R3" (verified OK)) by web04.haj.ipfire.org (Postfix) with ESMTPS id 4Fc7Ff6DH5z44RX for ; Fri, 7 May 2021 11:17:10 +0000 (UTC) Received: from mail02.haj.ipfire.org (mail02.haj.ipfire.org [172.28.1.201]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) client-signature ECDSA (P-384)) (Client CN "mail02.haj.ipfire.org", Issuer "R3" (verified OK)) by mail01.ipfire.org (Postfix) with ESMTPS id 4Fc7FY70mmz4WD; Fri, 7 May 2021 11:17:05 +0000 (UTC) Received: from mail02.haj.ipfire.org (localhost [127.0.0.1]) by mail02.haj.ipfire.org (Postfix) with ESMTP id 4Fc7FY5MHXz2ylk; Fri, 7 May 2021 11:17:05 +0000 (UTC) Received: from mail01.ipfire.org (mail01.haj.ipfire.org [172.28.1.202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) client-signature ECDSA (P-384)) (Client CN "mail01.haj.ipfire.org", Issuer "R3" (verified OK)) by mail02.haj.ipfire.org (Postfix) with ESMTPS id 4Fc7FX1q0Zz2xpc for ; Fri, 7 May 2021 11:17:04 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by mail01.ipfire.org (Postfix) with ESMTPSA id 4Fc7FW4jQVzxb; Fri, 7 May 2021 11:17:03 +0000 (UTC) DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=ipfire.org; s=202003ed25519; t=1620386223; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=p2JEsI8JcFWH1BcBdJ4gVNNEQsAMiJPJklTRYYZdwjU=; b=v5bJNMLz2Iulf+Xsws+TsUywMZWcFI6fqKVfnIN/48lvHPS33VPxfk4CR9eLes6BmrkMcA MT2tFLoYbwcESXDg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ipfire.org; s=202003rsa; t=1620386223; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=p2JEsI8JcFWH1BcBdJ4gVNNEQsAMiJPJklTRYYZdwjU=; b=vrQzsYLALVa0iJl2EdeZ8Y6inB6gR+MXj9PNsBa95JDxes+MaXC0PXxo1JndSXZpzhH1FG ZDy2Z81ykPg7+7U7+MzOEX9QbK/xTk7CMpe6aPD030smOHGo4dcK9WsgQjNMoJCUw6bQsA /yz4GlffXx8SE0uw/Gdju9I1BHedJkxGMpeFNVYHjztmkM0I/UcbbEkVuI7F3MeIqX0qE+ JisSKPYPOLDJXjSUYQuMUQliy9MIQM9J8eWejseSU0C3whL5rGyMjhfkVFhLdVkxDKpQJ7 r9zvQRUBWQGg5dXXxZjeXAl3AufU+0Ir4jaoZIaVmrVgueDVLxWi/M1be81h+Q== From: Michael Tremer To: development@lists.ipfire.org Subject: [PATCH 04/10] Run 2to3 Date: Fri, 7 May 2021 11:16:48 +0000 Message-Id: <20210507111654.2397-5-michael.tremer@ipfire.org> In-Reply-To: <20210507111654.2397-1-michael.tremer@ipfire.org> References: <74B08C60-EBDB-4C2E-83E0-A5EB5A0C3C5E@ipfire.org> <20210507111654.2397-1-michael.tremer@ipfire.org> MIME-Version: 1.0 X-BeenThere: development@lists.ipfire.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: IPFire development talk List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Michael Tremer Errors-To: development-bounces@lists.ipfire.org Sender: "Development" This is the result of running the automatic conversion tool and I have not tested this, yet. There might be some bugs being introduced by this. Signed-off-by: Michael Tremer --- src/fireinfo/cpu.py | 20 ++++++++++---------- src/fireinfo/hypervisor.py | 6 +++--- src/fireinfo/network.py | 8 ++++---- src/fireinfo/system.py | 38 ++++++++++++++++++-------------------- src/sendprofile | 34 +++++++++++++++++----------------- 5 files changed, 52 insertions(+), 54 deletions(-) diff --git a/src/fireinfo/cpu.py b/src/fireinfo/cpu.py index dc76caf..e433a04 100644 --- a/src/fireinfo/cpu.py +++ b/src/fireinfo/cpu.py @@ -21,7 +21,7 @@ import os -import system +from . import system PROC_CPUINFO = "/proc/cpuinfo" @@ -188,12 +188,12 @@ class CPU(object): if __name__ == "__main__": c = CPU() - print "Vendor:", c.vendor - print "Model:", c.model - print "Stepping:", c.stepping - print "Flags:", c.flags - print "Bogomips:", c.bogomips - print "Speed:", c.speed - print "Family:", c.family - print "Count:", c.count - print "Model string:", c.model_string + print("Vendor:", c.vendor) + print("Model:", c.model) + print("Stepping:", c.stepping) + print("Flags:", c.flags) + print("Bogomips:", c.bogomips) + print("Speed:", c.speed) + print("Family:", c.family) + print("Count:", c.count) + print("Model string:", c.model_string) diff --git a/src/fireinfo/hypervisor.py b/src/fireinfo/hypervisor.py index 0c07cfa..e76aad5 100644 --- a/src/fireinfo/hypervisor.py +++ b/src/fireinfo/hypervisor.py @@ -20,7 +20,7 @@ ############################################################################### import _fireinfo -import system +from . import system class Hypervisor(object): def __init__(self): @@ -115,5 +115,5 @@ class Hypervisor(object): if __name__ == "__main__": h = Hypervisor() - print "Vendor:", h.vendor - print "Virtual:", h.virtual + print("Vendor:", h.vendor) + print("Virtual:", h.virtual) diff --git a/src/fireinfo/network.py b/src/fireinfo/network.py index 063e9ec..de58be3 100644 --- a/src/fireinfo/network.py +++ b/src/fireinfo/network.py @@ -47,7 +47,7 @@ class Network(object): if __name__ == "__main__": n = Network() - print "has_green", n.has_green() - print "has_red", n.has_red() - print "has_blue", n.has_blue() - print "has_orange", n.has_orange() + print("has_green", n.has_green()) + print("has_red", n.has_red()) + print("has_blue", n.has_blue()) + print("has_orange", n.has_orange()) diff --git a/src/fireinfo/system.py b/src/fireinfo/system.py index 73c3882..cfeb171 100644 --- a/src/fireinfo/system.py +++ b/src/fireinfo/system.py @@ -26,11 +26,11 @@ import string import _fireinfo -import bios -import cpu -import device -import hypervisor -import network +from . import bios +from . import cpu +from . import device +from . import hypervisor +from . import network PROFILE_VERSION = 0 @@ -84,9 +84,7 @@ def read_from_file(filename): except IOError: pass -class System(object): - __metaclass__ = Singleton - +class System(object, metaclass=Singleton): def __init__(self): self.bios = bios.BIOS(self) @@ -338,7 +336,7 @@ class System(object): if s is None: return - return filter(lambda x: x in string.printable, s) + return [x for x in s if x in string.printable] @property def vendor(self): @@ -373,7 +371,7 @@ class System(object): ret = read_from_file("/proc/device-tree/model") if ret: # replace the NULL byte with which the DT string ends - ret = ret.replace(u"\u0000", "") + ret = ret.replace("\u0000", "") # Fall back to read /proc/cpuinfo if not ret: @@ -485,13 +483,13 @@ class System(object): if __name__ == "__main__": s=System() - print s.arch - print s.language - print s.release - print s.bios_vendor - print s.memory - print s.kernel - print s.root_disk - print s.root_size - print "------------\n", s.devices, "\n------------\n" - print json.dumps(s.profile(), sort_keys=True, indent=4) + print(s.arch) + print(s.language) + print(s.release) + print(s.bios_vendor) + print(s.memory) + print(s.kernel) + print(s.root_disk) + print(s.root_size) + print("------------\n", s.devices, "\n------------\n") + print(json.dumps(s.profile(), sort_keys=True, indent=4)) diff --git a/src/sendprofile b/src/sendprofile index 3ce68b9..5fc6c86 100755 --- a/src/sendprofile +++ b/src/sendprofile @@ -24,8 +24,8 @@ import logging import logging.handlers import os import sys -import urllib -import urllib2 +import urllib.request, urllib.parse, urllib.error +import urllib.request, urllib.error, urllib.parse import fireinfo @@ -67,8 +67,8 @@ def send_profile(profile): for line in json.dumps(profile, sort_keys=True, indent=4).splitlines(): logging.debug(line) - request = urllib2.Request(PROFILE_URL % profile, - data = urllib.urlencode({"profile" : json.dumps(profile)}), + request = urllib.request.Request(PROFILE_URL % profile, + data = urllib.parse.urlencode({"profile" : json.dumps(profile)}), ) request.add_header("User-Agent", "fireinfo/%s" % fireinfo.__version__) @@ -80,22 +80,22 @@ def send_profile(profile): if proxy["user"] and proxy["pass"]: prx_auth_string = "http://%s:%s@%s/" % (proxy["user"], proxy["pass"], proxy["host"]) - proxy_handler = urllib2.ProxyHandler({'http': prx_auth_string, 'https': prx_auth_string}) - auth = urllib2.HTTPBasicAuthHandler() - opener = urllib2.build_opener(proxy_handler, auth, urllib2.HTTPHandler) - urllib2.install_opener(opener) + proxy_handler = urllib.request.ProxyHandler({'http': prx_auth_string, 'https': prx_auth_string}) + auth = urllib.request.HTTPBasicAuthHandler() + opener = urllib.request.build_opener(proxy_handler, auth, urllib.request.HTTPHandler) + urllib.request.install_opener(opener) else: request.set_proxy(proxy["host"], "http") request.set_proxy(proxy["host"], "https") try: - urllib2.urlopen(request, timeout=60) - except (urllib2.HTTPError, urllib2.URLError), e: + urllib.request.urlopen(request, timeout=60) + except (urllib.error.HTTPError, urllib.error.URLError) as e: reason = "Unknown reason" - if isinstance(e, urllib2.HTTPError): + if isinstance(e, urllib.error.HTTPError): reason = "%s" % e - elif isinstance(e, urllib2.URLError): + elif isinstance(e, urllib.error.URLError): reason = e.reason logging.error("Profile was not sent propertly: %s" % reason) @@ -114,19 +114,19 @@ def main(): # it contains no information and may confuse people. del profile["private_id"] - print json.dumps(profile, sort_keys=True, indent=4) + print(json.dumps(profile, sort_keys=True, indent=4)) return 0 if "--secret-id" in sys.argv: - print system.secret_id + print(system.secret_id) return 0 if "--hardware-string" in sys.argv: - print system._unique_id + print(system._unique_id) return 0 if "--public-id" in sys.argv: - print system.public_id + print(system.public_id) return 0 if not os.path.exists(ENABLED_FILE): @@ -134,7 +134,7 @@ def main(): try: send_profile(profile) - except urllib2.URLError: + except urllib.error.URLError: return 1 return 0