aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlorian Schmaus <flo@geekplace.eu>2020-12-18 19:46:39 +0100
committerZac Medico <zmedico@gentoo.org>2020-12-30 17:43:22 -0800
commit1574ae127b270739c4293271c959d1d981684906 (patch)
tree8bc476ce4835e0f46ad3f2c732873b284d355197
parentMake atomic_ofstream a Context Manager (diff)
downloadportage-1574ae12.tar.gz
portage-1574ae12.tar.bz2
portage-1574ae12.zip
env_update: use "with statement" on atomic_ofstream
Signed-off-by: Florian Schmaus <flo@geekplace.eu> Signed-off-by: Zac Medico <zmedico@gentoo.org>
-rw-r--r--lib/portage/util/env_update.py30
1 files 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"))