From mboxrd@z Thu Jan 1 00:00:00 1970 X-GM-THRID: 6657041487194226688 X-Received: by 2002:a05:600c:21d4:: with SMTP id x20mr182126wmj.25.1549963257885; Tue, 12 Feb 2019 01:20:57 -0800 (PST) X-BeenThere: isar-users@googlegroups.com Received: by 2002:adf:fb8c:: with SMTP id a12ls3098662wrr.2.gmail; Tue, 12 Feb 2019 01:20:57 -0800 (PST) X-Google-Smtp-Source: AHgI3IZRtnpEAHJGHnqYNj2s9PwIlD1EfN4UWaqTDqfdATkD1PXdtHa2PhV2ilr/opfXZQHzvIyl X-Received: by 2002:adf:9f42:: with SMTP id f2mr131095wrg.25.1549963257339; Tue, 12 Feb 2019 01:20:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549963257; cv=none; d=google.com; s=arc-20160816; b=vIp0lT40KJA7h2wkka+vC1ou6pXWwrb4hol3gT56OBnZm6y1B9oqgWxZXg5qykK57g dxBp/DqQUBk3VqBdx0s84+qauzuXrL2aci6Wbgv54fBq6i5tvkXRQoStJlR94sjLMxCz g4/uWZXrAF12n3qd/RL2rMPE7zHLJAXvHOeBKFHNXrpDG7vPQkVBkqT+l3o6r1e0Uaiy kfLMDvAMBQDZ7KIO2cPHxx5w5xM9Z0fU9kwU2xqkHcSGIx+qtia/ERIoprVk48etldRf CMw41yL+AWIOaxx+cF4vzNu8k9VEuVmlA4wjl6P1SB03e19BkbUGfjcCtK4cqlfOJirE etsA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from; bh=E7p33an3TRL62Yood4T2n8zCqeOR3kqSnesIjYQk1aU=; b=0US7Evm9EQysPW6C1tevUfGj7Bv+wK8Szks9DDqPBkSFXkfuen+4SxTdP23GImPeg8 UqCHGyUZWXbDl3UJToB7Qq7Bz6iyyS7kARCcKMejiIuuoKARmmCOTGv/6177SrZ/nv07 PH4a9F34HBJ3IQMBvmqvBSB/hWiWK0BwLfLUN7WQczFy83QG1Ic46/15BPRGUHhL02xF Sc4QAL5T+X5+URUBf3YEIf283Hfp/jUqvnzsY3EXk55uuGUIwD5kfpeQ6CwP2QYH/2xJ Z7/BMNqY3qCWOXar29wH2AUltrtTwU4C6dQPISd5iIALHEyFqOjLvJlH7qq7e8uVZLtZ V73A== ARC-Authentication-Results: i=1; gmr-mx.google.com; spf=neutral (google.com: 2001:a60:0:28:0:1:25:1 is neither permitted nor denied by best guess record for domain of hws@denx.de) smtp.mailfrom=hws@denx.de Return-Path: Received: from mail-out.m-online.net (mail-out.m-online.net. [2001:a60:0:28:0:1:25:1]) by gmr-mx.google.com with ESMTPS id z207si86104wmc.2.2019.02.12.01.20.57 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 12 Feb 2019 01:20:57 -0800 (PST) Received-SPF: neutral (google.com: 2001:a60:0:28:0:1:25:1 is neither permitted nor denied by best guess record for domain of hws@denx.de) client-ip=2001:a60:0:28:0:1:25:1; Authentication-Results: gmr-mx.google.com; spf=neutral (google.com: 2001:a60:0:28:0:1:25:1 is neither permitted nor denied by best guess record for domain of hws@denx.de) smtp.mailfrom=hws@denx.de Received: from frontend01.mail.m-online.net (unknown [192.168.8.182]) by mail-out.m-online.net (Postfix) with ESMTP id 43zHFj0sHHz1r0hB for ; Tue, 12 Feb 2019 10:20:57 +0100 (CET) Received: from localhost (dynscan1.mnet-online.de [192.168.6.70]) by mail.m-online.net (Postfix) with ESMTP id 43zHFj0k8rz1qvWq for ; Tue, 12 Feb 2019 10:20:57 +0100 (CET) X-Virus-Scanned: amavisd-new at mnet-online.de Received: from mail.mnet-online.de ([192.168.8.182]) by localhost (dynscan1.mail.m-online.net [192.168.6.70]) (amavisd-new, port 10024) with ESMTP id B5WLDbZD3oI4 for ; Tue, 12 Feb 2019 10:20:55 +0100 (CET) X-Auth-Info: pnF2Jq3as0dqZTCEH5MGZ6CNA5mP3M6Reu1+LdqjjKc= Received: from sandvich.fritz.box (p578a821c.dip0.t-ipconnect.de [87.138.130.28]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.mnet-online.de (Postfix) with ESMTPSA for ; Tue, 12 Feb 2019 10:20:55 +0100 (CET) From: Harald Seiler To: isar-users@googlegroups.com Subject: [PATCH 2/4] Use modern python formatting Date: Tue, 12 Feb 2019 10:20:44 +0100 Message-Id: <20190212092046.6508-3-hws@denx.de> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190212092046.6508-1-hws@denx.de> References: <20190212092046.6508-1-hws@denx.de> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-TUID: c4J50jId2GJx The use of % for formatting is discouraged because it has side- effects that are not immediately obvious. This commit refactors all uses of % to a better formatting style. As f-Strings are not availible in in some python versions we support (<3.6) the formatter of choice is .format() or manual concatenation in cases where it is more concise. This commit additionally refactors the showdata and listtasks tasks to make better use of the new formatter code. Signed-off-by: Harald Seiler --- meta/classes/base.bbclass | 37 +++++++++++++++------- meta/classes/wic-img.bbclass | 21 ++++++++---- .../recipes-core/isar-bootstrap/isar-bootstrap.inc | 12 +++---- 3 files changed, 46 insertions(+), 24 deletions(-) diff --git a/meta/classes/base.bbclass b/meta/classes/base.bbclass index 6fcf452..50c4fbf 100644 --- a/meta/classes/base.bbclass +++ b/meta/classes/base.bbclass @@ -32,27 +32,40 @@ do_showdata[nostamp] = "1" python do_showdata() { for e in d.keys(): if d.getVarFlag(e, 'python'): - bb.plain("\npython %s () {\n%s}\n" % (e, d.getVar(e, True))) + code = d.getVar(e, True) + if code.startswith("def"): + bb.plain("\n" + code + "\n") + else: + bb.plain( + "\npython {name} () {{\n{code}}}\n".format( + name=e, + code=code, + ) + ) } # Derived from Open Embedded: openembedded-core/meta/classes/utility-tasks.bbclass addtask listtasks do_listtasks[nostamp] = "1" python do_listtasks() { - taskdescs = {} + tasks = {} maxlen = 0 for e in d.keys(): if d.getVarFlag(e, 'task'): maxlen = max(maxlen, len(e)) if e.endswith('_setscene'): - desc = "%s (setscene version)" % (d.getVarFlag(e[:-9], 'doc') or '') + tasks[e] = (d.getVarFlag(e[:-9], 'doc') or '') + " (setscene version)" else: - desc = d.getVarFlag(e, 'doc') or '' - taskdescs[e] = desc - - tasks = sorted(taskdescs.keys()) - for taskname in tasks: - bb.plain("%s %s" % (taskname.ljust(maxlen), taskdescs[taskname])) + tasks[e] = d.getVarFlag(e, 'doc') or '' + + for name, desc in sorted(tasks.items()): + bb.plain( + "{0:{len}} {1}".format( + name, + desc, + len=maxlen, + ) + ) } root_cleandirs() { @@ -81,8 +94,10 @@ python() { for i in rcleandirs: if not i.startswith(tmpdir): - bb.fatal("root_cleandirs entry %s is not contained in " - "TMPDIR %s" % (i, tmpdir)) + bb.fatal( + "root_cleandirs entry {} is not contained in TMPDIR {}" + .format(i, tmpdir) + ) ws = re.match("^\s*", d.getVar(e, False)).group() if flags.get('python'): diff --git a/meta/classes/wic-img.bbclass b/meta/classes/wic-img.bbclass index 76602d8..9cb869c 100644 --- a/meta/classes/wic-img.bbclass +++ b/meta/classes/wic-img.bbclass @@ -5,6 +5,8 @@ # python () { + import itertools + wks_full_path = None wks_file = d.getVar('WKS_FILE', True) @@ -18,14 +20,21 @@ python () { wks_full_path = wks_file else: bbpaths = d.getVar('BBPATH', True).split(':') + corebase_paths = bbpaths + corebase = d.getVar('COREBASE', True) - search_path = ':'.join('%s/wic' % p for p in bbpaths) + ':' + \ - ':'.join('%s/scripts/lib/wic/canned-wks' % l \ - for l in (bbpaths + [corebase])) + if corebase is not None: + corebase_paths.append(corebase) + + search_path = ":".join(itertools.chain( + (p + "/wic" for p in bbpaths), + (l + "/scripts/lib/wic/canned-wks" + for l in (corebase_paths)), + )) wks_full_path = bb.utils.which(search_path, wks_file) if not wks_full_path: - bb.fatal("WKS_FILE '%s' not found" % wks_file) + bb.fatal("WKS_FILE '{}' not found".format(wks_file)) d.setVar('WKS_FULL_PATH', wks_full_path) } @@ -68,12 +77,12 @@ python do_rootfs_wicenv () { for var in wicvars.split(): value = d.getVar(var, True) if value: - envf.write('%s="%s"\n' % (var, value.strip())) + envf.write('{}="{}"\n'.format(var, value.strip())) # this part is stolen from OE ./meta/recipes-core/meta/wic-tools.bb with open(os.path.join(outdir, "wic-tools.env"), 'w') as envf: for var in ('RECIPE_SYSROOT_NATIVE', 'STAGING_DATADIR', 'STAGING_LIBDIR'): - envf.write('%s="%s"\n' % (var, d.getVar(var, True).strip())) + envf.write('{}="{}"\n'.format(var, d.getVar(var, True).strip())) } diff --git a/meta/recipes-core/isar-bootstrap/isar-bootstrap.inc b/meta/recipes-core/isar-bootstrap/isar-bootstrap.inc index 234d339..5114714 100644 --- a/meta/recipes-core/isar-bootstrap/isar-bootstrap.inc +++ b/meta/recipes-core/isar-bootstrap/isar-bootstrap.inc @@ -40,18 +40,16 @@ python () { d.setVar("DEBOOTSTRAP_KEYRING", "--keyring ${APTKEYRING}") for key in distro_apt_keys.split(): url = urlparse(key) - filename = ''.join([wd, url.path]) - d.appendVar("SRC_URI", " %s" % key) - d.appendVar("APTKEYFILES", " %s" % filename) + d.appendVar("SRC_URI", " " + key) + d.appendVar("APTKEYFILES", " " + wd + url.path) if bb.utils.to_boolean(d.getVar('ISAR_USE_CACHED_BASE_REPO')): own_pub_key = d.getVar("BASE_REPO_KEY", False) if own_pub_key: d.setVar("DEBOOTSTRAP_KEYRING", "--keyring ${APTKEYRING}") for key in own_pub_key.split(): url = urlparse(key) - filename = ''.join([wd, url.path]) - d.appendVar("SRC_URI", " %s" % key) - d.appendVar("APTKEYFILES", " %s" % filename) + d.appendVar("SRC_URI", " " + key) + d.appendVar("APTKEYFILES", " " + wd + url.path) } def aggregate_files(d, file_list, file_out): @@ -170,7 +168,7 @@ def get_distro_suite(d, is_host): def get_distro_components_argument(d, is_host): components = get_distro_primary_source_entry(d, is_host)[2] if components and components.strip(): - return "--components=%s" % ",".join(components.split()) + return "--components=" + ",".join(components.split()) else: return "" -- 2.14.1