Bug 552441 Update devicemanager to have better error reporting for failed file transactions r=ctalbert a=dholbert for CLOSED TREE landing, NPOTB
authorJoel Maher <jmaher@mozilla.com>
Mon, 15 Mar 2010 15:45:00 -0700
changeset 39477 f1a43053f3b650492924264b5b3aaefad79d30e3
parent 39476 d348c121f6a6390032231af40c8eaf550616b0b1
child 39478 a48606cc04acfe1941530823ff4de2f59958f912
push idunknown
push userunknown
push dateunknown
reviewersctalbert, dholbert
bugs552441
milestone1.9.3a4pre
Bug 552441 Update devicemanager to have better error reporting for failed file transactions r=ctalbert a=dholbert for CLOSED TREE landing, NPOTB
build/mobile/devicemanager.py
--- a/build/mobile/devicemanager.py
+++ b/build/mobile/devicemanager.py
@@ -40,16 +40,24 @@ import time, datetime
 import os
 import re
 import hashlib
 import subprocess
 from threading import Thread
 import traceback
 import sys
 
+class FileError(Exception):
+  " Signifies an error which occurs while doing a file operation."
+
+  def __init__(self, msg = ''):
+    self.msg = msg
+
+  def __str__(self):
+    return self.msg
 
 class myProc(Thread):
   def __init__(self, hostip, hostport, cmd, new_line = True, sleeptime = 0):
     self.cmdline = cmd
     self.newline = new_line
     self.sleep = sleeptime
     self.host = hostip
     self.port = hostport
@@ -223,17 +231,20 @@ class DeviceManager:
   def pushFile(self, localname, destname):
     if (self.debug >= 2):
       print "in push file with: " + localname + ", and: " + destname
     if (self.validateFile(destname, localname) == True):
       if (self.debug >= 2):
         print "files are validated"
       return ''
 
-    self.mkDirs(destname)
+    if self.mkDirs(destname) == None:
+      print "unable to make dirs: " + destname
+      return None
+
     if (self.debug >= 2):
       print "sending: push " + destname
     
     # sleep 5 seconds / MB
     filesize = os.path.getsize(localname)
     sleepsize = 1024 * 1024
     sleepTime = (int(filesize / sleepsize) * 5) + 2
     f = open(localname, 'rb')
@@ -248,30 +259,31 @@ class DeviceManager:
     if (self.validateFile(destname, localname) == False):
       if (self.debug >= 2):
         print "file did not copy as expected"
       return None
 
     return retVal
   
   def mkDir(self, name):
-    return self.sendCMD(['mkdr ' + name, 'quit'])
+    return self.sendCMD(['mkdr ' + name])
   
   
   # make directory structure on the device
   def mkDirs(self, filename):
     parts = filename.split('/')
     name = ""
     for part in parts:
       if (part == parts[-1]): break
       if (part != ""):
         name += '/' + part
         if (self.mkDir(name) == None):
+          print "failed making directory: " + str(name)
           return None
-
+    return ''
 
   # push localDir from host to remoteDir on the device
   def pushDir(self, localDir, remoteDir):
     if (self.debug >= 2): print "pushing directory: " + localDir + " to " + remoteDir
     for root, dirs, files in os.walk(localDir):
       parts = root.split(localDir)
       for file in files:
         print "examining file: " + file
@@ -568,19 +580,48 @@ class DeviceManager:
 
   # Get a return code from process ending -- needs support on device-agent
   # this is a todo
   def getReturnCode(self, processID):
     # todo make this real
     return 0
 
   def unpackFile(self, filename):
-    self.sendCMD(['cd /tests', 'unzp ' + filename])
-    
-    
+    dir = ''
+    parts = filename.split('/')
+    if (len(parts) > 1):
+      if self.fileExists(filename):
+        dir = '/'.join(parts[:-1])
+    elif self.fileExists('/' + filename):
+      dir = '/' + filename
+    elif self.fileExists('/tests/' + filename):
+      dir = '/tests/' + filename
+    else:
+      return None
+
+    return self.sendCMD(['cd ' + dir, 'unzp ' + filename])
+
+
+  def reboot(self, wait = False):
+    self.sendCMD(['rebt'])
+
+    if wait == True:
+      time.sleep(30)
+      timeout = 270
+      done = False
+      while (not done):
+        if self.listFiles('/') != None:
+          return ''
+        print "sleeping another 10 seconds"
+        time.sleep(10)
+        timeout = timeout - 10
+        if (timeout <= 0):
+          return None
+    return ''
+
   # validate localDir from host to remoteDir on the device
   def validateDir(self, localDir, remoteDir):
     if (self.debug >= 2): print "validating directory: " + localDir + " to " + remoteDir
     for root, dirs, files in os.walk(localDir):
       parts = root.split(localDir)
       for file in files:
         remoteRoot = remoteDir + '/' + parts[1]
         remoteRoot = remoteRoot.replace('/', '/')