From mboxrd@z Thu Jan 1 00:00:00 1970 X-GM-THRID: 6664521764891000832 X-Received: by 2002:a2e:85cd:: with SMTP id h13mr951349ljj.8.1551704893182; Mon, 04 Mar 2019 05:08:13 -0800 (PST) X-BeenThere: isar-users@googlegroups.com Received: by 2002:a2e:5d5d:: with SMTP id r90ls1937209ljb.7.gmail; Mon, 04 Mar 2019 05:08:12 -0800 (PST) X-Google-Smtp-Source: APXvYqwRs812VwKqDEY9/B4C4E9ZR37wjsbFG+BPBujgLbUQrABsRHaak40Bilmj6lmZBODN/1pU X-Received: by 2002:a2e:391d:: with SMTP id g29mr1011888lja.17.1551704892608; Mon, 04 Mar 2019 05:08:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1551704892; cv=none; d=google.com; s=arc-20160816; b=yJMJjzXNj/Zu8LklFK0q9JQ0bJCF0y+NG3LQSk6/pqUUax8I7Su7efj8mCrcY0Muxh lhlXeKxVhurUtHAEZ01B0lUyS4RcZ5P1O+alROQp1ZAvtKXLKxvCRxACT5qls9HATUF6 zi3TgqwQM0VgYjJD917G5AV0//ugh/bG6F6NmgTRRPKJY+vwOz7VoYhn7SHbYM2b9X7q yb7MSrXxKbUi7O0s8kzvTf23gTNEluNWQu6VXPA8Q2DmNcV+UK0aHocHVyAigOIjd8Fk KtcgR0xOmllfrVW/oPKHPv0ZR11vKadchKOl4rYoNfFDPqBF8Lm1Y4CbWVXD48fYilsv VexA== 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:cc:to:from; bh=NGFzeTK9yjwhcI1unH66jbssAosd15Xo3TXF2pmc7Qw=; b=wa18BY292p9tRpi3ankcGw+5MJM51jBg3TNT6QZ6Gal4SUqe6MW8Mbtl0T1/90lPVo 4NdaEqqFJb8ChjP/iS4y5RlQ3H4z5XWnjXoCQJb905qp+35XenTh8594HYbIeeFpIB0/ hKDbM8kdCohqbm7iMoG6q1DYWb8lo1UDY9iBAVnLCUra6wm/PsUNQsPjHW4icQj5kWEA pr9GfFLWs66WuCbjGaTfP+Q3iZMN2V/hzG1eHsHhXiIv13j+tpwmEr8yCJ50MSqQg2kg 9eIHV4NkF+zM8bLHi6Vvm4Ilegy/99P7XruVej3sYAdiRuVGe+ZhpmL99Bht7aXjoJ4B pbBw== ARC-Authentication-Results: i=1; gmr-mx.google.com; spf=pass (google.com: domain of claudius.heine.ext@siemens.com designates 192.35.17.2 as permitted sender) smtp.mailfrom=claudius.heine.ext@siemens.com Return-Path: Received: from thoth.sbs.de (thoth.sbs.de. [192.35.17.2]) by gmr-mx.google.com with ESMTPS id y1si144095lfj.5.2019.03.04.05.08.12 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 04 Mar 2019 05:08:12 -0800 (PST) Received-SPF: pass (google.com: domain of claudius.heine.ext@siemens.com designates 192.35.17.2 as permitted sender) client-ip=192.35.17.2; Authentication-Results: gmr-mx.google.com; spf=pass (google.com: domain of claudius.heine.ext@siemens.com designates 192.35.17.2 as permitted sender) smtp.mailfrom=claudius.heine.ext@siemens.com Received: from mail2.sbs.de (mail2.sbs.de [192.129.41.66]) by thoth.sbs.de (8.15.2/8.15.2) with ESMTPS id x24D8AIx005534 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 4 Mar 2019 14:08:10 +0100 Received: from ring.ppmd.siemens.net (linux-ses-ext02.ppmd.siemens.net [139.25.69.232]) by mail2.sbs.de (8.15.2/8.15.2) with ESMTP id x24D89Ws008505; Mon, 4 Mar 2019 14:08:10 +0100 From: claudius.heine.ext@siemens.com To: isar-users@googlegroups.com Cc: Harald Seiler Subject: [PATCH v4 3/6] Use modern python formatting Date: Mon, 4 Mar 2019 14:07:58 +0100 Message-Id: <20190304130801.20628-4-claudius.heine.ext@siemens.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190304130801.20628-1-claudius.heine.ext@siemens.com> References: <20190304130801.20628-1-claudius.heine.ext@siemens.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-TUID: 5oyvcLYtssXY From: Harald Seiler 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 | 58 ++++++++++++------- meta/classes/wic-img.bbclass | 21 +++++-- .../isar-bootstrap/isar-bootstrap.inc | 12 ++-- 3 files changed, 58 insertions(+), 33 deletions(-) diff --git a/meta/classes/base.bbclass b/meta/classes/base.bbclass index 1f415af..c9b9e9e 100644 --- a/meta/classes/base.bbclass +++ b/meta/classes/base.bbclass @@ -33,27 +33,35 @@ 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[e] = d.getVarFlag(e, 'doc') or '' - tasks = sorted(taskdescs.keys()) - for taskname in tasks: - bb.plain("%s %s" % (taskname.ljust(maxlen), taskdescs[taskname])) + for name, desc in sorted(tasks.items()): + bb.plain("{0:{len}} {1}".format(name, desc, len=maxlen)) } root_cleandirs() { @@ -71,30 +79,40 @@ root_cleandirs() { python() { import re + for e in d.keys(): flags = d.getVarFlags(e) if flags and flags.get('task'): rcleandirs = flags.get('root_cleandirs') if rcleandirs: tmpdir = os.path.normpath(d.getVar("TMPDIR", True)) - rcleandirs = list(os.path.normpath(d.expand(i)) - for i in rcleandirs.split()) + rcleandirs = list( + os.path.normpath(d.expand(i)) for i in rcleandirs.split() + ) 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'): - d.prependVar(e, ws + "d.setVar('ROOT_CLEANDIRS_DIRS', '" - + " ".join(rcleandirs) + "')\n" - + ws + "bb.build.exec_func(" - + "'root_cleandirs', d)\n") + cleandir_code = ( + "{ws}d.setVar('ROOT_CLEANDIRS_DIRS', '{dirlist}')\n" + "{ws}bb.build.exec_func('root_cleandirs', d)\n" + ) else: - d.prependVar(e, ws + "ROOT_CLEANDIRS_DIRS='" - + " ".join(rcleandirs) + "'\n" - + ws + "root_cleandirs\n") + cleandir_code = ( + "{ws}ROOT_CLEANDIRS_DIRS='{dirlist}'\n" + "{ws}root_cleandirs\n" + ) + + ws = re.match(r"^\s*", d.getVar(e, False)).group() + d.prependVar( + e, cleandir_code.format(ws=ws, dirlist=" ".join(rcleandirs)) + ) } # filter out all "apt://" URIs out of SRC_URI and stick them into SRC_APT diff --git a/meta/classes/wic-img.bbclass b/meta/classes/wic-img.bbclass index c9d90a9..14795a7 100644 --- a/meta/classes/wic-img.bbclass +++ b/meta/classes/wic-img.bbclass @@ -28,6 +28,8 @@ python do_write_wks_template () { } python () { + import itertools + wks_full_path = None wks_file = d.getVar('WKS_FILE', True) @@ -41,14 +43,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) @@ -117,12 +126,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.20.1