From: Ondrej Lichtner olichtne@redhat.com
This commit makes the function get_bg_process_result a method of class BGProcesses. It makes more sense here since it is used for accessing data from objects of this class.
I also moved the class BgProcessException to the same area so that it doesn't interfere with NetTestCommand* classes.
Signed-off-by: Ondrej Lichtner olichtne@redhat.com --- NetTest/NetTestCommand.py | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-)
diff --git a/NetTest/NetTestCommand.py b/NetTest/NetTestCommand.py index 1dbd2a2..8c0ef82 100644 --- a/NetTest/NetTestCommand.py +++ b/NetTest/NetTestCommand.py @@ -37,6 +37,14 @@ class CommandException(Exception): def __str__(self): return "CommandException: " + str(self.command)
+class BgProcessException(Exception): + """Base class for client errors.""" + def __init__(self, str): + self._str = str + + def __str__(self): + return "BgProcessError: " + self._str + class BGProcesses: def __init__(self): self._dict = {} @@ -55,6 +63,15 @@ class BGProcesses: def remove(self, bg_id): del self._dict[bg_id]
+ def get_bg_process_result(self, bg_id): + pipe = self.get_pipe(bg_id) + tmp = os.read(pipe, 4096*10) + result = pickle.loads(tmp) + if "Exception" in result: + raise BgProcessException(result["Exception"]) + os.close(pipe) + return result + bg_processes = BGProcesses()
def NetTestCommandTest(command): @@ -154,30 +171,13 @@ class NetTestCommandSystemConfig(NetTestCommandGeneric): res["res_data"] = res_data self.set_result(res)
-class BgProcessException(Exception): - """Base class for client errors.""" - def __init__(self, str): - self._str = str - - def __str__(self): - return "BgProcessError: " + self._str - -def get_bg_process_result(bg_id): - pipe = bg_processes.get_pipe(bg_id) - tmp = os.read(pipe, 4096*10) - result = pickle.loads(tmp) - if "Exception" in result: - raise BgProcessException(result["Exception"]) - os.close(pipe) - return result - class NetTestCommandWait(NetTestCommandGeneric): def run(self): bg_id = int(self._command["value"]) pid = bg_processes.get_pid(bg_id) logging.debug("Waiting for background id "%d", pid "%d"" % (bg_id, pid)) os.waitpid(pid, 0) - result = get_bg_process_result(bg_id) + result = bg_processes.get_bg_process_result(bg_id) bg_processes.remove(bg_id) self.set_result(result)
@@ -188,7 +188,7 @@ class NetTestCommandIntr(NetTestCommandGeneric): logging.debug("Interrupting background id "%d", pid "%d"" % (bg_id, pid)) os.killpg(os.getpgid(pid), signal.SIGINT) os.waitpid(pid, 0) - result = get_bg_process_result(bg_id) + result = bg_processes.get_bg_process_result(bg_id) bg_processes.remove(bg_id) self.set_result(result)
Whoops.. there is only 1 patch. Sorry about that.
Ondrej
----- Original Message ----- From: olichtne@redhat.com To: lnst-developers@lists.fedorahosted.org Cc: "Ondrej Lichtner" olichtne@redhat.com Sent: Friday, August 10, 2012 9:10:25 AM Subject: [PATCH 1/2] NetTestCommand: Code cleanup for bg processes
From: Ondrej Lichtner olichtne@redhat.com
This commit makes the function get_bg_process_result a method of class ...
Fri, Aug 10, 2012 at 09:14:05AM CEST, olichtne@redhat.com wrote:
Whoops.. there is only 1 patch. Sorry about that.
Okay. No worries.
Ondrej
----- Original Message ----- From: olichtne@redhat.com To: lnst-developers@lists.fedorahosted.org Cc: "Ondrej Lichtner" olichtne@redhat.com Sent: Friday, August 10, 2012 9:10:25 AM Subject: [PATCH 1/2] NetTestCommand: Code cleanup for bg processes
From: Ondrej Lichtner olichtne@redhat.com
This commit makes the function get_bg_process_result a method of class ... -- 1.7.11.2
LNST-developers mailing list LNST-developers@lists.fedorahosted.org https://lists.fedorahosted.org/mailman/listinfo/lnst-developers
lnst-developers@lists.fedorahosted.org