From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by finch.gentoo.org (Postfix) with ESMTPS id 6913F1382C5 for ; Fri, 18 Dec 2020 18:47:00 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id B483CE09F6; Fri, 18 Dec 2020 18:46:59 +0000 (UTC) Received: from zulu.geekplace.eu (zulu.geekplace.eu [5.45.100.158]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id 94E80E09F6 for ; Fri, 18 Dec 2020 18:46:59 +0000 (UTC) Received: from neo-pc.sch (55d474e6.access.ecotel.net [85.212.116.230]) by zulu.geekplace.eu (Postfix) with ESMTPA id 252E34A077A; Fri, 18 Dec 2020 19:46:58 +0100 (CET) From: Florian Schmaus To: gentoo-portage-dev@lists.gentoo.org Cc: Florian Schmaus Subject: [gentoo-portage-dev] [PATCH 2/2] env_update: use "with statement" on atomic_ofstream Date: Fri, 18 Dec 2020 19:46:39 +0100 Message-Id: <20201218184639.361607-2-flo@geekplace.eu> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20201218184639.361607-1-flo@geekplace.eu> References: <20201218184639.361607-1-flo@geekplace.eu> Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-portage-dev@lists.gentoo.org Reply-to: gentoo-portage-dev@lists.gentoo.org X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Archives-Salt: db48c5cd-6be0-444b-aece-95d564dc7351 X-Archives-Hash: 6049516e3a4576272777f1537882b811 Signed-off-by: Florian Schmaus --- lib/portage/util/env_update.py | 30 ++++++++++++------------------ 1 file changed, 12 insertions(+), 18 deletions(-) diff --git a/lib/portage/util/env_update.py b/lib/portage/util/env_update.py index dec086cf8c5b..5588931a84e7 100644 --- a/lib/portage/util/env_update.py +++ b/lib/portage/util/env_update.py @@ -342,18 +342,17 @@ def _env_update(makelinks, target_root, prev_mtimes, contents, env, #create /etc/profile.env for bash support profile_env_path = os.path.join(eroot, "etc", "profile.env") - outfile = atomic_ofstream(profile_env_path) - outfile.write(penvnotice) - - env_keys = [x for x in env if x != "LDPATH"] - env_keys.sort() - for k in env_keys: - v = env[k] - if v.startswith('$') and not v.startswith('${'): - outfile.write("export %s=$'%s'\n" % (k, v[1:])) - else: - outfile.write("export %s='%s'\n" % (k, v)) - outfile.close() + with atomic_ofstream(profile_env_path) as outfile: + outfile.write(penvnotice) + + env_keys = [x for x in env if x != "LDPATH"] + env_keys.sort() + for k in env_keys: + v = env[k] + if v.startswith('$') and not v.startswith('${'): + outfile.write("export %s=$'%s'\n" % (k, v[1:])) + else: + outfile.write("export %s='%s'\n" % (k, v)) # Create the systemd user environment configuration file # /etc/environment.d/10-gentoo-env.conf with the @@ -363,8 +362,7 @@ def _env_update(makelinks, target_root, prev_mtimes, contents, env, systemd_gentoo_env_path = os.path.join(systemd_environment_dir, "10-gentoo-env.conf") - systemd_gentoo_env = atomic_ofstream(systemd_gentoo_env_path) - try: + with atomic_ofstream(systemd_gentoo_env_path) as systemd_gentoo_env: senvnotice = notice + "\n\n" systemd_gentoo_env.write(senvnotice) @@ -384,10 +382,6 @@ def _env_update(makelinks, target_root, prev_mtimes, contents, env, line = f"{env_key}={env_key_value}\n" systemd_gentoo_env.write(line) - except: - systemd_gentoo_env.abort() - raise - systemd_gentoo_env.close() #create /etc/csh.env for (t)csh support outfile = atomic_ofstream(os.path.join(eroot, "etc", "csh.env")) -- 2.26.2