Applied. Fixed the FIXME note about stdout/stderr in process.info. Also raise exception when bad args are passed using the first line as the exception message. -- "An organisation that treats its programmers as morons will soon have programmers that are willing and able to act like morons only." -Bjarne Stroustrup
From 462b3fbe80a6f82d207652e737212a2dc94061b7 Mon Sep 17 00:00:00 2001 From: Steve 'Ashcrow' Milner <stevem@xxxxxxxxxxxx> Date: Mon, 14 Jan 2008 21:34:17 -0500 Subject: [PATCH] Fixed the FIXME note about stdout/stderr in process.info. Also raise exception when bad args are passed using the first line as the exception message. --- func/minion/modules/process.py | 26 +++++++++++++++++--------- 1 files changed, 17 insertions(+), 9 deletions(-) diff --git a/func/minion/modules/process.py b/func/minion/modules/process.py index 92c6d6a..bdd5193 100644 --- a/func/minion/modules/process.py +++ b/func/minion/modules/process.py @@ -32,22 +32,27 @@ class ProcessModule(func_module.FuncModule): } func_module.FuncModule.__init__(self) - def info(self,flags="-auxh"): + def info(self, flags="-auxh"): """ Returns a struct of hardware information. By default, this pulls down all of the devices. If you don't care about them, set with_devices to False. """ - flags.replace(";","") # prevent stupidity + flags.replace(";", "") # prevent stupidity + cmd = sub_process.Popen(["/bin/ps", flags], executable="/bin/ps", + stdout=sub_process.PIPE, + stderr=sub_process.PIPE, + shell=False) - #FIXME: we need to swallow stdout/stderr as well, right now it spews to the console - cmd = sub_process.Popen(["/bin/ps", flags] ,executable="/bin/ps", stdout=sub_process.PIPE,shell=False) - data = cmd.communicate()[0] + data, error = cmd.communicate() - results = [] + # We can get warnings for odd formatting. warnings != errors. + if error and error[:7] != "Warning": + raise codes.FuncException(error.split('\n')[0]) + results = [] for x in data.split("\n"): tokens = x.split() results.append(tokens) @@ -196,17 +201,20 @@ class ProcessModule(func_module.FuncModule): if pid == "0": raise codes.FuncException("Killing pid group 0 not permitted") if signal == "": - # this is default /bin/kill behaviour, it claims, but enfore it anyway + # this is default /bin/kill behaviour, + # it claims, but enfore it anyway signal = "-TERM" if signal[0] != "-": signal = "-%s" % signal - rc = sub_process.call(["/bin/kill",signal, pid], executable="/bin/kill", shell=False) + rc = sub_process.call(["/bin/kill",signal, pid], + executable="/bin/kill", shell=False) print rc return rc def pkill(self,name,level=""): # example killall("thunderbird","-9") - rc = sub_process.call(["/usr/bin/pkill", name, level], executable="/usr/bin/pkill", shell=False) + rc = sub_process.call(["/usr/bin/pkill", name, level], + executable="/usr/bin/pkill", shell=False) return rc methods = ProcessModule() -- 1.5.3.7
_______________________________________________ Func-list mailing list Func-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/func-list