Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 23E3DC38A02 for ; Sun, 30 Oct 2022 01:49:58 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 9D9FD8516A; Sun, 30 Oct 2022 02:47:53 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="NGL9Ch5B"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 46B2D8515F; Sun, 30 Oct 2022 02:47:48 +0100 (CET) Received: from mail-il1-x134.google.com (mail-il1-x134.google.com [IPv6:2607:f8b0:4864:20::134]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id DCF9A8510F for ; Sun, 30 Oct 2022 02:47:44 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=sjg@chromium.org Received: by mail-il1-x134.google.com with SMTP id s9so4787798ilu.1 for ; Sat, 29 Oct 2022 18:47:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=W5ZzkPbDyiFvuqqREHkQtxkPgKQGTAuuW5+vwLsCIiA=; b=NGL9Ch5BlO1NTVFzyH2p4qPIIqFVfdp5ts6607z5fxGlhbu1l8hvJDdsCM7FdMFWN6 eA/akZvdwV2LalspASZOJxBgorpEN+zTp99zmda0YNbWz2RRR8Obj4CRVYIKQoS2kFJN ncR2hPKmVMbhmY2tPg09XMjZeSkoMtNb65QHs= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=W5ZzkPbDyiFvuqqREHkQtxkPgKQGTAuuW5+vwLsCIiA=; b=S/QXfwaPo2DLu0687sWMGDjGqwx0OA7jh9JEYAYrQ8mui6cFi5OP5WEv6bZOA+70/i ELAWOFbPawuuroJFTSeqR0PmMhgYfRkuOsW7QJsHOZY4FRvgpxY8CygTpqCEufsp+l5x 6W8jBfRKF43qAhZRkiq2sfzTC5dQSC8IPAog+CgQjtPz795/ct4Gmwe6BPgIvIRxCOOT KVhoDm4C65FmVlcADy3YCqpZ+rd6VrLvSqYADjbDc4IXPaE7jetSEUHCWPpE0yatE1wq FZVZ9dtDSZ7dEkDCRbs4HALDCyrGazbFTPaY4Pc7XIu59qe5y6nHyQs2b/S/6uQQkEOd w+zg== X-Gm-Message-State: ACrzQf0G7izs7Jyrp/8ibqwB4Dx1Hr6DwMXrggE327/erJkHRXUK5OYo aoYBf1lnsIwcIGIaIYz3uYqTXPfDD8D8vA== X-Google-Smtp-Source: AMsMyM5XJqD7pYIfEyT6cO+T1jrw3tJL1MsQLrHnphTlIPjVrDf7vKD8PN9Id35QkdiuiZICKN7WMw== X-Received: by 2002:a92:730c:0:b0:2f5:7dd7:45f7 with SMTP id o12-20020a92730c000000b002f57dd745f7mr3219186ilc.12.1667094463394; Sat, 29 Oct 2022 18:47:43 -0700 (PDT) Received: from sjg1.roam.corp.google.com (c-67-190-102-125.hsd1.co.comcast.net. [67.190.102.125]) by smtp.gmail.com with ESMTPSA id x66-20020a0294c8000000b00363c4307bb2sm810287jah.79.2022.10.29.18.47.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 29 Oct 2022 18:47:43 -0700 (PDT) From: Simon Glass To: U-Boot Mailing List Cc: Tom Rini , Heinrich Schuchardt , Simon Glass Subject: [PATCH 04/17] test: Correct pylint warnings in fs_helper Date: Sat, 29 Oct 2022 19:47:06 -0600 Message-Id: <20221030014719.147327-5-sjg@chromium.org> X-Mailer: git-send-email 2.38.1.273.g43a17bfeac-goog In-Reply-To: <20221030014719.147327-1-sjg@chromium.org> References: <20221030014719.147327-1-sjg@chromium.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.6 at phobos.denx.de X-Virus-Status: Clean Tidy this up so that pylint is happy. Use hex for the 1MB size and make sure it is not a floating-point value. Add a little main program to allow the code to be tried out, since at present is only called from a long-running test. Signed-off-by: Simon Glass --- test/py/tests/fs_helper.py | 38 +++++++++++++++++++++++++------------- 1 file changed, 25 insertions(+), 13 deletions(-) diff --git a/test/py/tests/fs_helper.py b/test/py/tests/fs_helper.py index 2d8f1f63add..9882ddb1daa 100644 --- a/test/py/tests/fs_helper.py +++ b/test/py/tests/fs_helper.py @@ -1,10 +1,10 @@ # SPDX-License-Identifier: GPL-2.0+ # -# Helper functions for dealing with filesystems -# # Copyright (c) 2018, Linaro Limited # Author: Takahiro Akashi +"""Helper functions for dealing with filesystems""" + import re import os from subprocess import call, check_call, check_output, CalledProcessError @@ -13,12 +13,16 @@ def mk_fs(config, fs_type, size, prefix): """Create a file system volume Args: + config (u_boot_config): U-Boot configuration fs_type (str): File system type, e.g. 'ext4' size (int): Size of file system in bytes prefix (str): Prefix string of volume's file name + + Raises: + CalledProcessError: if any error occurs when creating the filesystem """ - fs_img = '%s.%s.img' % (prefix, fs_type) - fs_img = config.persistent_data_dir + '/' + fs_img + fs_img = f'{prefix}.{fs_type}.img' + fs_img = os.path.join(config.persistent_data_dir, fs_img) if fs_type == 'fat16': mkfs_opt = '-F 16' @@ -32,23 +36,31 @@ def mk_fs(config, fs_type, size, prefix): else: fs_lnxtype = fs_type - count = (size + 1048576 - 1) / 1048576 + count = (size + 0x100000 - 1) // 0x100000 # Some distributions do not add /sbin to the default PATH, where mkfs lives if '/sbin' not in os.environ["PATH"].split(os.pathsep): os.environ["PATH"] += os.pathsep + '/sbin' try: - check_call('rm -f %s' % fs_img, shell=True) - check_call('dd if=/dev/zero of=%s bs=1M count=%d' - % (fs_img, count), shell=True) - check_call('mkfs.%s %s %s' - % (fs_lnxtype, mkfs_opt, fs_img), shell=True) + check_call(f'rm -f {fs_img}', shell=True) + check_call(f'dd if=/dev/zero of={fs_img} bs=1M count={count}', + shell=True) + check_call(f'mkfs.{fs_lnxtype} {mkfs_opt} {fs_img}', shell=True) if fs_type == 'ext4': - sb_content = check_output('tune2fs -l %s' % fs_img, shell=True).decode() + sb_content = check_output(f'tune2fs -l {fs_img}', + shell=True).decode() if 'metadata_csum' in sb_content: - check_call('tune2fs -O ^metadata_csum %s' % fs_img, shell=True) + check_call(f'tune2fs -O ^metadata_csum {fs_img}', shell=True) return fs_img except CalledProcessError: - call('rm -f %s' % fs_img, shell=True) + call(f'rm -f {fs_img}', shell=True) raise + +# Just for trying out +if __name__ == "__main__": + import collections + + CNF= collections.namedtuple('config', 'persistent_data_dir') + + mk_fs(CNF('.'), 'ext4', 0x1000000, 'pref') -- 2.38.1.273.g43a17bfeac-goog