Bug 792084 - add shellCheckOutput command to devicemanager, r=wlach
authorMalini Das <mdas@mozilla.com>
Wed, 26 Sep 2012 12:32:02 -0400
changeset 108260 0450cb4ef66ab6d4f23cb6868de8c87d0e08b783
parent 108259 5ebf745a3a40d1c489fab9fe95ad65fef8d18daf
child 108261 f341fc58f595ccb66760e03908057b9f538252dc
push id82
push usershu@rfrn.org
push dateFri, 05 Oct 2012 13:20:22 +0000
reviewerswlach
bugs792084
milestone18.0a1
Bug 792084 - add shellCheckOutput command to devicemanager, r=wlach
testing/mozbase/mozdevice/mozdevice/devicemanager.py
--- a/testing/mozbase/mozdevice/mozdevice/devicemanager.py
+++ b/testing/mozbase/mozdevice/mozdevice/devicemanager.py
@@ -44,16 +44,37 @@ class DeviceManager:
 
         timeout is specified in seconds, and if no timeout is given, 
         we will run until the script returns
         returns:
         success: Return code from command
         failure: None
         """
 
+    def shellCheckOutput(self, cmd, env=None, cwd=None, timeout=None, root=False):
+        """
+        executes shell command on device (with root privileges if
+        specified)  and returns the the output
+
+        timeout is specified in seconds, and if no timeout is given,
+        we will run until the script returns
+        returns:
+        success: Returns output of shell command
+        failure: DMError will be raised
+        """
+        buf = StringIO.StringIO()
+        retval = self.shell(cmd, buf, env=env, cwd=cwd, timeout=timeout, root=root)
+        output = str(buf.getvalue()[0:-1]).rstrip()
+        buf.close()
+        if retval is None:
+            raise DMError("Did not successfully run command %s (output: '%s', retval: 'None')" % (cmd, output))
+        if retval != 0:
+            raise DMError("Non-zero return code for command: %s (output: '%s', retval: '%i')" % (cmd, output, retval))
+        return output
+
     @abstractmethod
     def pushFile(self, localname, destname):
         """
         external function
         returns:
         success: True
         failure: False
         """