From 83be006e288c58a46f5b76c29b6886c1f417d88c Mon Sep 17 00:00:00 2001 From: Ɓukasz 'sil2100' Zemczak Date: Wed, 15 Mar 2017 10:19:34 +0100 Subject: Import patches-unapplied version 2.2.6-0ubuntu1 to ubuntu/zesty-proposed Imported using git-ubuntu import. Changelog parent: d064ab0bffd429382ea4fafeb144784d403848bd 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). --- azurelinuxagent/common/utils/shellutil.py | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) (limited to 'azurelinuxagent/common/utils/shellutil.py') 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 -- cgit v1.2.3