Skip to content

Commit fe9eb96

Browse files
linux.InternalPlatformUtils is refactored (normalization)
1 parent 1b7f2ce commit fe9eb96

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

src/impl/platforms/linux/internal_platform_utils.py

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,14 @@
1111

1212

1313
class InternalPlatformUtils(base.InternalPlatformUtils):
14+
C_BASH_EXE = "/bin/bash"
15+
16+
sm_exec_env = {
17+
"LANG": "en_US.UTF-8",
18+
"LC_ALL": "en_US.UTF-8",
19+
}
20+
21+
# --------------------------------------------------------------------
1422
def FindPostmaster(
1523
self,
1624
os_ops: OsOperations,
@@ -20,22 +28,22 @@ def FindPostmaster(
2028
assert isinstance(os_ops, OsOperations)
2129
assert type(bin_dir) == str # noqa: E721
2230
assert type(data_dir) == str # noqa: E721
31+
assert type(__class__.C_BASH_EXE) == str # noqa: E721
32+
assert type(__class__.sm_exec_env) == dict # noqa: E721
33+
assert len(__class__.C_BASH_EXE) > 0
34+
assert len(bin_dir) > 0
35+
assert len(data_dir) > 0
2336

2437
pg_path_e = re.escape(os_ops.build_path(bin_dir, "postgres"))
2538
data_dir_e = re.escape(data_dir)
2639

2740
assert type(pg_path_e) == str # noqa: E721
2841
assert type(data_dir_e) == str # noqa: E721
2942

30-
exec_env = {
31-
"LANG": "en_US.UTF-8",
32-
"LC_ALL": "en_US.UTF-8",
33-
}
34-
3543
regexp = r"^\s*[0-9]+\s+" + pg_path_e + r"(\s+.*)?\s+\-[D]\s+" + data_dir_e + r"(\s+.*)?"
3644

3745
cmd = [
38-
"/bin/bash",
46+
__class__.C_BASH_EXE,
3947
"-c",
4048
"ps -ewwo \"pid=,args=\" | grep -E " + shlex.quote(regexp),
4149
]
@@ -44,7 +52,7 @@ def FindPostmaster(
4452
cmd=cmd,
4553
ignore_errors=True,
4654
verbose=True,
47-
exec_env=exec_env,
55+
exec_env=__class__.sm_exec_env,
4856
)
4957

5058
assert type(output_b) == bytes # noqa: E721

0 commit comments

Comments
 (0)