- Notifications
You must be signed in to change notification settings - Fork35
RemoteOperations::exec_command explicitly transfers LANG, LANGUAGE and LC_* envvars to the server side#187
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Changes fromall commits
f5fe166
2b1db89
4f0ba36
4eb8330
f4dc062
ee78bcd
5564938
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -87,7 +87,12 @@ def exec_command(self, cmd, wait_exit=False, verbose=False, expect_error=False, | ||
assert type(cmd_s) == str # noqa: E721 | ||
cmd_items = __class__._make_exec_env_list() | ||
cmd_items.append(cmd_s) | ||
env_cmd_s = ';'.join(cmd_items) | ||
ssh_cmd = ['ssh', self.ssh_dest] + self.ssh_args + [env_cmd_s] | ||
process = subprocess.Popen(ssh_cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE) | ||
assert not (process is None) | ||
@@ -510,6 +515,45 @@ def db_connect(self, dbname, user, password=None, host="localhost", port=5432): | ||
) | ||
return conn | ||
@staticmethod | ||
def _make_exec_env_list() -> list[str]: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. тут нужно self, либо добавить@staticmethod There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. self тут не нужен. Это статический метод. Хорошо, я добавлю этот декоратор. Я там в других местах тоже статические методы определял... Тогда я пока только в новом коде этого PR его добавлю, а потом, отдельным коммитом, добавим его во все остальные случаи. PS. Я этот питон на ходу изучаю, поэтому многие вещи использую неправильно )))) | ||
result = list[str]() | ||
for envvar in os.environ.items(): | ||
if not __class__._does_put_envvar_into_exec_cmd(envvar[0]): | ||
continue | ||
qvalue = __class__._quote_envvar(envvar[1]) | ||
assert type(qvalue) == str # noqa: E721 | ||
result.append(envvar[0] + "=" + qvalue) | ||
continue | ||
return result | ||
sm_envs_for_exec_cmd = ["LANG", "LANGUAGE"] | ||
@staticmethod | ||
def _does_put_envvar_into_exec_cmd(name: str) -> bool: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. тут нужно self, либо добавить@staticmethod | ||
assert type(name) == str # noqa: E721 | ||
name = name.upper() | ||
if name.startswith("LC_"): | ||
return True | ||
if name in __class__.sm_envs_for_exec_cmd: | ||
return True | ||
return False | ||
@staticmethod | ||
def _quote_envvar(value: str) -> str: | ||
assert type(value) == str # noqa: E721 | ||
result = "\"" | ||
for ch in value: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. Тут лучше append использоватьhttps://www.geeksforgeeks.org/difference-between-and-append-in-python/ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. Виктория, что-то я не догоняю. Куда тут append использовать? result - это str. У него нет метода append, но есть поддержка оператора +=, который по смыслу тот же append. Этот += тут и используется. Contributor
| ||
if ch == "\"": | ||
result += "\\\"" | ||
elif ch == "\\": | ||
result += "\\\\" | ||
else: | ||
result += ch | ||
result += "\"" | ||
return result | ||
def normalize_error(error): | ||
if isinstance(error, bytes): | ||