Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
An Exception is raised if an error occurs
"""
# convert the command to sequence if a string
if isinstance(command, str):
command = shlex.split(command)
try:
return Popen(command, stdout=PIPE, stderr=PIPE, close_fds=True).wait()
except Exception as e:
# make a pretty command for error loggings and...
if isinstance(command, str):
pretty_cmd = command
else:
pretty_cmd = " ".join(command)
msg = "Command `{cmd}` {error}".format(cmd=pretty_cmd, error=e.errno)
raise exceptions.CommandError(msg, error_code=e.errno)
def get_volume(self):
try:
line = self.command_output(self.cmd + ["--get-mute", "--get-volume"])
except CommandError as ce:
# pamixer throws error on zero percent. see #1135
line = ce.output
try:
muted, perc = line.split()
muted = muted == "true"
except ValueError:
muted, perc = None, None
return perc, muted
retcode = process.poll()
if retcode:
# under certain conditions a successfully run command may get a
# return code of -15 even though correct output was returned see
# #664. This issue seems to be related to arch linux but the
# reason is not entirely clear.
if retcode == -15:
msg = "Command `{cmd}` returned SIGTERM (ignoring)"
self.log(msg.format(cmd=pretty_cmd))
else:
msg = "Command `{cmd}` returned non-zero exit status {error}"
output_oneline = output.replace("\n", " ")
if output_oneline:
msg += " ({output})"
msg = msg.format(cmd=pretty_cmd, error=retcode, output=output_oneline)
raise exceptions.CommandError(
msg, error_code=retcode, error=error, output=output
)
return output
env = self._english_env if not localized else None
try:
process = Popen(
command,
stdout=PIPE,
stderr=stderr,
close_fds=True,
universal_newlines=True,
shell=shell,
env=env,
)
except Exception as e:
msg = "Command `{cmd}` {error}".format(cmd=pretty_cmd, error=e)
self.log(msg)
raise exceptions.CommandError(msg, error_code=e.errno)
output, error = process.communicate()
retcode = process.poll()
if retcode:
# under certain conditions a successfully run command may get a
# return code of -15 even though correct output was returned see
# #664. This issue seems to be related to arch linux but the
# reason is not entirely clear.
if retcode == -15:
msg = "Command `{cmd}` returned SIGTERM (ignoring)"
self.log(msg.format(cmd=pretty_cmd))
else:
msg = "Command `{cmd}` returned non-zero exit status {error}"
output_oneline = output.replace("\n", " ")
if output_oneline:
msg += " ({output})"
LOG_ERROR = "error"
"""Show as Error"""
LOG_INFO = "info"
"""Show as Informational"""
LOG_WARNING = "warning"
"""Show as Warning"""
# Shared by all Py3 Instances
_formatter = None
_gradients = Gradients()
_none_color = NoneColor()
_storage = Storage()
# Exceptions
Py3Exception = exceptions.Py3Exception
CommandError = exceptions.CommandError
RequestException = exceptions.RequestException
RequestInvalidJSON = exceptions.RequestInvalidJSON
RequestTimeout = exceptions.RequestTimeout
RequestURLError = exceptions.RequestURLError
def __init__(self, module=None):
self._audio = None
self._config_setting = {}
self._english_env = dict(os.environ)
self._english_env["LC_ALL"] = "C"
self._english_env["LANGUAGE"] = "C"
self._format_color_names = {}
self._format_placeholders = {}
self._format_placeholders_cache = {}
self._module = module
self._report_exception_cache = set()