本文整理汇总了Python中resource_management.core.logger.Logger.filter_text方法的典型用法代码示例。如果您正苦于以下问题:Python Logger.filter_text方法的具体用法?Python Logger.filter_text怎么用?Python Logger.filter_text使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类resource_management.core.logger.Logger
的用法示例。
在下文中一共展示了Logger.filter_text方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: install_package
# 需要导入模块: from resource_management.core.logger import Logger [as 别名]
# 或者: from resource_management.core.logger.Logger import filter_text [as 别名]
def install_package(self, name, use_repos=[], skip_repos=[], is_upgrade=False):
if is_upgrade or use_repos or not self._check_existence(name):
cmd = INSTALL_CMD[self.get_logoutput()]
copied_sources_files = []
is_tmp_dir_created = False
if use_repos:
is_tmp_dir_created = True
apt_sources_list_tmp_dir = tempfile.mkdtemp(suffix="-ambari-apt-sources-d")
Logger.info("Temporal sources directory was created: %s" % apt_sources_list_tmp_dir)
if 'base' not in use_repos:
cmd = cmd + ['-o', 'Dir::Etc::SourceList=%s' % EMPTY_FILE]
for repo in use_repos:
if repo != 'base':
new_sources_file = os.path.join(apt_sources_list_tmp_dir, repo + '.list')
Logger.info("Temporal sources file will be copied: %s" % new_sources_file)
sudo.copy(os.path.join(APT_SOURCES_LIST_DIR, repo + '.list'), new_sources_file)
copied_sources_files.append(new_sources_file)
cmd = cmd + ['-o', 'Dir::Etc::SourceParts=%s' % apt_sources_list_tmp_dir]
cmd = cmd + [name]
Logger.info("Installing package %s ('%s')" % (name, string_cmd_from_args_list(cmd)))
code, out = self.call_with_retries(cmd, sudo=True, env=INSTALL_CMD_ENV, logoutput=self.get_logoutput())
if self.is_locked_output(out):
err_msg = Logger.filter_text("Execution of '%s' returned %d. %s" % (cmd, code, out))
raise Fail(err_msg)
# apt-get update wasn't done too long maybe?
if code:
Logger.info("Execution of '%s' returned %d. %s" % (cmd, code, out))
Logger.info("Failed to install package %s. Executing `%s`" % (name, string_cmd_from_args_list(REPO_UPDATE_CMD)))
code, out = self.call_with_retries(REPO_UPDATE_CMD, sudo=True, logoutput=self.get_logoutput())
if code:
Logger.info("Execution of '%s' returned %d. %s" % (REPO_UPDATE_CMD, code, out))
Logger.info("Retrying to install package %s" % (name))
self.checked_call_with_retries(cmd, sudo=True, env=INSTALL_CMD_ENV, logoutput=self.get_logoutput())
if is_tmp_dir_created:
for temporal_sources_file in copied_sources_files:
Logger.info("Removing temporal sources file: %s" % temporal_sources_file)
os.remove(temporal_sources_file)
Logger.info("Removing temporal sources directory: %s" % apt_sources_list_tmp_dir)
os.rmdir(apt_sources_list_tmp_dir)
else:
Logger.info("Skipping installation of existing package %s" % (name))
示例2: as_sudo
# 需要导入模块: from resource_management.core.logger import Logger [as 别名]
# 或者: from resource_management.core.logger.Logger import filter_text [as 别名]
def as_sudo(command, env=None, auto_escape=True):
"""
command - list or tuple of arguments.
env - when run as part of Execute resource, this SHOULD NOT be used.
It automatically gets replaced later by call, checked_call. This should be used in not_if, only_if
"""
if isinstance(command, (list, tuple)):
command = string_cmd_from_args_list(command, auto_escape=auto_escape)
else:
# Since ambari user sudoer privileges may be restricted,
# without having /bin/bash permission, and /bin/su permission.
# Running interpreted shell commands in scope of 'sudo' is not possible.
#
# In that case while passing string,
# any bash symbols eventually added to command like && || ; < > | << >> would cause problems.
err_msg = Logger.filter_text(("String command '%s' cannot be run as sudo. Please supply the command as a tuple of arguments") % (command))
raise Fail(err_msg)
env = _get_environment_str(_add_current_path_to_env(env)) if env else ENV_PLACEHOLDER
return "{0} {1} -H -E {2}".format(_get_sudo_binary(), env, command)
示例3: get_user_call_output
# 需要导入模块: from resource_management.core.logger import Logger [as 别名]
# 或者: from resource_management.core.logger.Logger import filter_text [as 别名]
def get_user_call_output(command, user, quiet=False, is_checked_call=True, **call_kwargs):
"""
This function eliminates only output of command inside the su, ignoring the su ouput itself.
This is useful since some users have motd messages setup by default on su -l.
@return: code, stdout, stderr
"""
command_string = shell.string_cmd_from_args_list(command) if isinstance(command, (list, tuple)) else command
out_files = []
try:
out_files.append(tempfile.NamedTemporaryFile())
out_files.append(tempfile.NamedTemporaryFile())
# other user should be able to write to it
for f in out_files:
os.chmod(f.name, 0666)
command_string += " 1>" + out_files[0].name
command_string += " 2>" + out_files[1].name
code, _ = shell.call(shell.as_user(command_string, user), quiet=quiet, **call_kwargs)
files_output = []
for f in out_files:
files_output.append(f.read().strip('\n'))
if code:
all_output = files_output[1] + '\n' + files_output[0]
err_msg = Logger.filter_text(("Execution of '%s' returned %d. %s") % (command_string, code, all_output))
if is_checked_call:
raise Fail(err_msg)
else:
Logger.warning(err_msg)
return code, files_output[0], files_output[1]
finally:
for f in out_files:
f.close()
示例4: ExecuteTimeoutException
# 需要导入模块: from resource_management.core.logger import Logger [as 别名]
# 或者: from resource_management.core.logger.Logger import filter_text [as 别名]
os.close(master_fd)
proc.wait()
out = out.strip('\n')
if timeout:
if not timeout_event.is_set():
t.cancel()
# timeout occurred
else:
raise ExecuteTimeoutException()
code = proc.returncode
if throw_on_failure and code:
err_msg = Logger.filter_text(("Execution of '%s' returned %d. %s") % (command_alias, code, out))
raise Fail(err_msg)
return code, out
def as_sudo(command, env=None, auto_escape=True):
"""
command - list or tuple of arguments.
env - when run as part of Execute resource, this SHOULD NOT be used.
It automatically gets replaced later by call, checked_call. This should be used in not_if, only_if
"""
if isinstance(command, (list, tuple)):
command = string_cmd_from_args_list(command, auto_escape=auto_escape)
else:
# Since ambari user sudoer privileges may be restricted,
# without having /bin/bash permission, and /bin/su permission.
示例5: ExecuteTimeoutException
# 需要导入模块: from resource_management.core.logger import Logger [as 别名]
# 或者: from resource_management.core.logger.Logger import filter_text [as 别名]
out = fd_to_string[proc.stdout].strip('\n')
err = fd_to_string[proc.stderr].strip('\n')
all_output = all_output.strip('\n')
if timeout:
if not timeout_event.is_set():
t.cancel()
# timeout occurred
else:
err_msg = "Execution of '{0}' was killed due timeout after {1} seconds".format(command, timeout)
raise ExecuteTimeoutException(err_msg)
code = proc.returncode
if throw_on_failure and code:
err_msg = Logger.filter_text("Execution of '{0}' returned {1}. {2}".format(command_alias, code, all_output))
raise Fail(err_msg)
# if separate stderr is enabled (by default it's redirected to out)
if stderr == subprocess.PIPE:
return code, out, err
return code, out
def as_sudo(command, env=None, auto_escape=True):
"""
command - list or tuple of arguments.
env - when run as part of Execute resource, this SHOULD NOT be used.
It automatically gets replaced later by call, checked_call. This should be used in not_if, only_if
"""
if isinstance(command, (list, tuple)):