commit: 1574ae127b270739c4293271c959d1d981684906
Author: Florian Schmaus <flo <AT> geekplace <DOT> eu>
AuthorDate: Fri Dec 18 18:46:39 2020 +0000
Commit: Zac Medico <zmedico <AT> gentoo <DOT> org>
CommitDate: Thu Dec 31 01:43:22 2020 +0000
URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=1574ae12
env_update: use "with statement" on atomic_ofstream
Signed-off-by: Florian Schmaus <flo <AT> geekplace.eu>
Signed-off-by: Zac Medico <zmedico <AT> gentoo.org>
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 dec086cf8..5588931a8 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"))