summaryrefslogtreecommitdiff
path: root/azurelinuxagent/common/utils/shellutil.py
diff options
context:
space:
mode:
authorƁukasz 'sil2100' Zemczak <lukasz.zemczak@ubuntu.com>2017-03-15 10:19:34 +0100
committerusd-importer <ubuntu-server@lists.ubuntu.com>2017-03-17 13:08:24 +0000
commitc6339c307f36f77a4198d6faf1275acdf371200b (patch)
treec774046e1e30617514c09e5a2b896568706a25a8 /azurelinuxagent/common/utils/shellutil.py
parentdd73af563850762aad64e7ed2a9897377830af10 (diff)
parent2bc77af05fe602a2ba92569428c6006d1aebd19f (diff)
downloadvyos-walinuxagent-c6339c307f36f77a4198d6faf1275acdf371200b.tar.gz
vyos-walinuxagent-c6339c307f36f77a4198d6faf1275acdf371200b.zip
Import patches-applied version 2.2.6-0ubuntu1 to applied/ubuntu/zesty-proposed
Imported using git-ubuntu import. Changelog parent: dd73af563850762aad64e7ed2a9897377830af10 Unapplied parent: 2bc77af05fe602a2ba92569428c6006d1aebd19f New changelog entries: * New upstream release (LP: #1661750). * debian/control: - Change the maintainer to Ubuntu Developers (LP: #1657528). - Add the dependency of isc-dhcp-client as our maintainer scripts assume it's installed. - Add trailing commas to dependencies, add whitespaces. * Rename ephemeral-disk-warning.sh to ephemeral-disk-warning (lintian error). * debian/docs: - Remove LICENSE.txt as it's redundant. * debian/postinst: - Stop checking for update-initramfs existence using the absolute path, use the 'command' command instead to make lintian happy. * Remove debian/patches/disable-auto-update.patch: - We now ship with auto-updates enabled (LP: #1650522). * debian/maintscript: - Add a maintscript to rename the old logrotate file on upgrade from an ancient version of walinuxagent (LP: #1673152).
Diffstat (limited to 'azurelinuxagent/common/utils/shellutil.py')
-rw-r--r--azurelinuxagent/common/utils/shellutil.py28
1 files changed, 16 insertions, 12 deletions
diff --git a/azurelinuxagent/common/utils/shellutil.py b/azurelinuxagent/common/utils/shellutil.py
index d273c92..4efcbc4 100644
--- a/azurelinuxagent/common/utils/shellutil.py
+++ b/azurelinuxagent/common/utils/shellutil.py
@@ -17,13 +17,11 @@
# Requires Python 2.4+ and Openssl 1.0+
#
-import platform
-import os
import subprocess
-from azurelinuxagent.common.future import ustr
import azurelinuxagent.common.logger as logger
+from azurelinuxagent.common.future import ustr
-if not hasattr(subprocess,'check_output'):
+if not hasattr(subprocess, 'check_output'):
def check_output(*popenargs, **kwargs):
r"""Backport from subprocess module from python 2.7"""
if 'stdout' in kwargs:
@@ -39,51 +37,58 @@ if not hasattr(subprocess,'check_output'):
raise subprocess.CalledProcessError(retcode, cmd, output=output)
return output
+
# Exception classes used by this module.
class CalledProcessError(Exception):
def __init__(self, returncode, cmd, output=None):
self.returncode = returncode
self.cmd = cmd
self.output = output
+
def __str__(self):
return ("Command '{0}' returned non-zero exit status {1}"
"").format(self.cmd, self.returncode)
- subprocess.check_output=check_output
- subprocess.CalledProcessError=CalledProcessError
+ subprocess.check_output = check_output
+ subprocess.CalledProcessError = CalledProcessError
"""
Shell command util functions
"""
+
+
def run(cmd, chk_err=True):
"""
Calls run_get_output on 'cmd', returning only the return code.
If chk_err=True then errors will be reported in the log.
If chk_err=False then errors will be suppressed from the log.
"""
- retcode,out=run_get_output(cmd,chk_err)
+ retcode, out = run_get_output(cmd, chk_err)
return retcode
+
def run_get_output(cmd, chk_err=True, log_cmd=True):
"""
Wrapper for subprocess.check_output.
- Execute 'cmd'. Returns return code and STDOUT, trapping expected exceptions.
+ Execute 'cmd'. Returns return code and STDOUT, trapping expected
+ exceptions.
Reports exceptions to Error if chk_err parameter is True
"""
if log_cmd:
logger.verbose(u"run cmd '{0}'", cmd)
try:
- output=subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True)
+ output = subprocess.check_output(cmd, stderr=subprocess.STDOUT,
+ shell=True)
output = ustr(output, encoding='utf-8', errors="backslashreplace")
- except subprocess.CalledProcessError as e :
+ except subprocess.CalledProcessError as e:
output = ustr(e.output, encoding='utf-8', errors="backslashreplace")
if chk_err:
if log_cmd:
logger.error(u"run cmd '{0}' failed", e.cmd)
logger.error(u"Error Code:{0}", e.returncode)
logger.error(u"Result:{0}", output)
- return e.returncode, output
+ return e.returncode, output
return 0, output
@@ -103,5 +108,4 @@ def quote(word_list):
return " ".join(list("'{0}'".format(s.replace("'", "'\\''")) for s in word_list))
-
# End shell command util functions