[nfsometer PATCH 1/2] cmd.py: redefine CmdErrorCode

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Redefine CmdErrorCode so the error code itself can be checked.

Signed-off-by: Scott Mayhew <smayhew@xxxxxxxxxx>
---
 nfsometerlib/cmd.py | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/nfsometerlib/cmd.py b/nfsometerlib/cmd.py
index 9b6dbdd..a2ebcef 100644
--- a/nfsometerlib/cmd.py
+++ b/nfsometerlib/cmd.py
@@ -25,7 +25,15 @@ class CmdError(Exception):
     pass
 
 class CmdErrorCode(CmdError):
-    pass
+    def __init__(self, cmd, code, errstr):
+        self.cmd = cmd
+        self.code = code
+        self.errstr = errstr
+
+    def __str__(self):
+        return str.format(
+            'command "{:s}" exited with non-zero status: {:d}{:s}',
+            self.cmd, self.code, self.errstr)
 
 class CmdErrorOut(CmdError):
     pass
@@ -67,8 +75,7 @@ def cmd(args, raiseerrorcode=True, raiseerrorout=True, instr='',
         errstr = '\n%s' % errstr
 
     if raiseerrorcode and ret != 0:
-        raise CmdErrorCode('command "%s" exited with non-zero status: %u%s' %
-                            (args, ret, errstr))
+        raise CmdErrorCode(args, ret, errstr)
 
     if raiseerrorout and errstr:
         raise CmdErrorOut('command "%s" has output to stderr: %s' %
-- 
2.4.3

--
To unsubscribe from this list: send the line "unsubscribe linux-nfs" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Linux Filesystem Development]     [Linux USB Development]     [Linux Media Development]     [Video for Linux]     [Linux NILFS]     [Linux Audio Users]     [Yosemite Info]     [Linux SCSI]

  Powered by Linux