1 |
commit: 1574ae127b270739c4293271c959d1d981684906 |
2 |
Author: Florian Schmaus <flo <AT> geekplace <DOT> eu> |
3 |
AuthorDate: Fri Dec 18 18:46:39 2020 +0000 |
4 |
Commit: Zac Medico <zmedico <AT> gentoo <DOT> org> |
5 |
CommitDate: Thu Dec 31 01:43:22 2020 +0000 |
6 |
URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=1574ae12 |
7 |
|
8 |
env_update: use "with statement" on atomic_ofstream |
9 |
|
10 |
Signed-off-by: Florian Schmaus <flo <AT> geekplace.eu> |
11 |
Signed-off-by: Zac Medico <zmedico <AT> gentoo.org> |
12 |
|
13 |
lib/portage/util/env_update.py | 30 ++++++++++++------------------ |
14 |
1 file changed, 12 insertions(+), 18 deletions(-) |
15 |
|
16 |
diff --git a/lib/portage/util/env_update.py b/lib/portage/util/env_update.py |
17 |
index dec086cf8..5588931a8 100644 |
18 |
--- a/lib/portage/util/env_update.py |
19 |
+++ b/lib/portage/util/env_update.py |
20 |
@@ -342,18 +342,17 @@ def _env_update(makelinks, target_root, prev_mtimes, contents, env, |
21 |
|
22 |
#create /etc/profile.env for bash support |
23 |
profile_env_path = os.path.join(eroot, "etc", "profile.env") |
24 |
- outfile = atomic_ofstream(profile_env_path) |
25 |
- outfile.write(penvnotice) |
26 |
- |
27 |
- env_keys = [x for x in env if x != "LDPATH"] |
28 |
- env_keys.sort() |
29 |
- for k in env_keys: |
30 |
- v = env[k] |
31 |
- if v.startswith('$') and not v.startswith('${'): |
32 |
- outfile.write("export %s=$'%s'\n" % (k, v[1:])) |
33 |
- else: |
34 |
- outfile.write("export %s='%s'\n" % (k, v)) |
35 |
- outfile.close() |
36 |
+ with atomic_ofstream(profile_env_path) as outfile: |
37 |
+ outfile.write(penvnotice) |
38 |
+ |
39 |
+ env_keys = [x for x in env if x != "LDPATH"] |
40 |
+ env_keys.sort() |
41 |
+ for k in env_keys: |
42 |
+ v = env[k] |
43 |
+ if v.startswith('$') and not v.startswith('${'): |
44 |
+ outfile.write("export %s=$'%s'\n" % (k, v[1:])) |
45 |
+ else: |
46 |
+ outfile.write("export %s='%s'\n" % (k, v)) |
47 |
|
48 |
# Create the systemd user environment configuration file |
49 |
# /etc/environment.d/10-gentoo-env.conf with the |
50 |
@@ -363,8 +362,7 @@ def _env_update(makelinks, target_root, prev_mtimes, contents, env, |
51 |
|
52 |
systemd_gentoo_env_path = os.path.join(systemd_environment_dir, |
53 |
"10-gentoo-env.conf") |
54 |
- systemd_gentoo_env = atomic_ofstream(systemd_gentoo_env_path) |
55 |
- try: |
56 |
+ with atomic_ofstream(systemd_gentoo_env_path) as systemd_gentoo_env: |
57 |
senvnotice = notice + "\n\n" |
58 |
systemd_gentoo_env.write(senvnotice) |
59 |
|
60 |
@@ -384,10 +382,6 @@ def _env_update(makelinks, target_root, prev_mtimes, contents, env, |
61 |
line = f"{env_key}={env_key_value}\n" |
62 |
|
63 |
systemd_gentoo_env.write(line) |
64 |
- except: |
65 |
- systemd_gentoo_env.abort() |
66 |
- raise |
67 |
- systemd_gentoo_env.close() |
68 |
|
69 |
#create /etc/csh.env for (t)csh support |
70 |
outfile = atomic_ofstream(os.path.join(eroot, "etc", "csh.env")) |