bug 624001 update devicemanager.py for reboot, getdirectory and isdir cleanup. r=mcote, a=NPOTB
authorJoel Maher <jmaher@mozilla.com>
Fri, 04 Feb 2011 13:49:37 -0500
changeset 61945 5a4ab9b3fd2ffac5712a894aa22b4ebae4eb5f05
parent 61944 dc85ecc5f1dcfdbad46f44867749a63a197443fd
child 61946 8dd5c5f90bf3cca9c167d13631747f3354edf036
push idunknown
push userunknown
push dateunknown
reviewersmcote, NPOTB
bugs624001
milestone2.0b12pre
bug 624001 update devicemanager.py for reboot, getdirectory and isdir cleanup. r=mcote, a=NPOTB
build/mobile/devicemanager.py
--- a/build/mobile/devicemanager.py
+++ b/build/mobile/devicemanager.py
@@ -496,17 +496,17 @@ class DeviceManager:
       data = self.verifySendCMD(['exec ' + appname])
     except(DMError):
       return None
 
     # wait up to 30 seconds for process to start up
     timeslept = 0
     while (timeslept <= 30):
       process = self.processExist(appname)
-      if (self.process is not None):
+      if (process is not None):
         break
       time.sleep(3)
       timeslept += 3
 
     if (self.debug >= 4): print "got pid: %s for process: %s" % (process, appname)
     return process
 
   # external function
@@ -738,40 +738,49 @@ class DeviceManager:
     fhandle.close()
     if not self.validateFile(remoteFile, localFile):
       print 'failed to validate file when downloading %s!' % remoteFile
       return None
     return retVal
 
   # copy directory structure from device (remoteDir) to host (localDir)
   # external function
+  # checkDir exists so that we don't create local directories if the
+  # remote directory doesn't exist but also so that we don't call isDir
+  # twice when recursing.
   # returns:
   #  success: list of files, string
   #  failure: None
-  def getDirectory(self, remoteDir, localDir):
+  def getDirectory(self, remoteDir, localDir, checkDir=True):
     if (self.debug >= 2): print "getting files in '" + remoteDir + "'"
+    if checkDir:
+      try:
+        is_dir = self.isDir(remoteDir)
+      except FileError:
+        return None
+      if not is_dir:
+        return None
+        
     filelist = self.listFiles(remoteDir)
-    if (filelist == []):
-      return None
     if (self.debug >= 3): print filelist
     if not os.path.exists(localDir):
       os.makedirs(localDir)
 
     for f in filelist:
       if f == '.' or f == '..':
         continue
       remotePath = remoteDir + '/' + f
       localPath = os.path.join(localDir, f)
       try:
         is_dir = self.isDir(remotePath)
       except FileError:
         print 'isdir failed on file "%s"; continuing anyway...' % remotePath
         continue
       if is_dir:
-        if (self.getDirectory(remotePath, localPath) == None):
+        if (self.getDirectory(remotePath, localPath, False) == None):
           print 'failed to get directory "%s"' % remotePath
           return None
       else:
         # It's sometimes acceptable to have getFile() return None, such as
         # when the agent encounters broken symlinks.
         # FIXME: This should be improved so we know when a file transfer really
         # failed.
         if self.getFile(remotePath, localPath) == None:
@@ -782,17 +791,20 @@ class DeviceManager:
   # returns:
   #  success: True
   #  failure: False
   #  Throws a FileError exception when null (invalid dir/filename)
   def isDir(self, remotePath):
     try:
       data = self.verifySendCMD(['isdir ' + remotePath])
     except(DMError):
-      data = None
+      # normally there should be no error here; a nonexistent file/directory will
+      # return the string "<filename>: No such file or directory".
+      # However, I've seen AGENT-WARNING returned before. 
+      return False
 
     retVal = self.stripPrompt(data).strip()
     if not retVal:
       raise FileError('isdir returned null')
     return retVal == 'TRUE'
 
   # true/false check if the two files have the same md5 sum
   # external function
@@ -966,27 +978,41 @@ class DeviceManager:
       return None
 
     return data
 
   # external function
   # returns:
   #  success: status from test agent
   #  failure: None
-  def reboot(self):
+  def reboot(self, wait = False):
     cmd = 'rebt'
-
-    if (self.debug > 3): print "INFO: sending rebt command"
+    if (self.debug >= 3): print "INFO: sending rebt command"
     
     try:
-      status = self.verifySendCMD([cmd])
+      status = self.sendCMD([cmd])
     except DMError:
       return None
 
-    if (self.debug > 3): print "INFO: rebt- got status back: " + str(status)
+    if (wait == True):
+      #this sleeps up to 5 minutes in 30 second intervals
+      count = 0
+      while (count < 10):
+        if (self.debug >= 4): print "DEBUG: sleeping 30 seconds while waiting for reboot"
+        time.sleep(30)
+        waitstatus = self.getDeviceRoot()
+        if (waitstatus is not None):
+          break
+        self.retries = 0
+        count += 1
+
+      if (count >= 10):
+        return None
+
+    if (self.debug >= 3): print "INFO: rebt- got status back: " + str(status)
     return status
 
   # validate localDir from host to remoteDir on the device
   # external function
   # returns:
   #  success: True
   #  failure: False
   def validateDir(self, localDir, remoteDir):