Skip to content
This repository has been archived by the owner on Aug 20, 2018. It is now read-only.

Commit

Permalink
Bug 794539 - Fixup validateFile and pullFile logic in dmADB and bump,…
Browse files Browse the repository at this point in the history
… r=wlach
  • Loading branch information
ahal-test committed Sep 26, 2012
1 parent 16c9738 commit 4d43867
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 32 deletions.
4 changes: 1 addition & 3 deletions mozdevice/mozdevice/devicemanager.py
Expand Up @@ -308,7 +308,7 @@ def _getRemoteHash(self, filename):
"""

@staticmethod
def _getLocalHash(self, filename):
def _getLocalHash(filename):
"""
Return the MD5 sum of a file on the host
Expand All @@ -334,8 +334,6 @@ def _getLocalHash(self, filename):

f.close()
hexval = mdsum.hexdigest()
if (self.debug >= 3):
print "local hash returned: '" + hexval + "'"
return hexval

@abstractmethod
Expand Down
77 changes: 49 additions & 28 deletions mozdevice/mozdevice/devicemanagerADB.py
Expand Up @@ -480,18 +480,16 @@ def catFile(self, remoteFile):
success: filecontents, string
failure: None
"""
return self.pullFile(remotefile)
return self.pullFile(remoteFile)

def pullFile(self, remoteFile):
def _runPull(self, remoteFile, localFile):
"""
Returns contents of remoteFile using the "pull" command.
Pulls remoteFile from device to host
returns:
success: output of pullfile, string
success: path to localFile
failure: None
"""
# TODO: add debug flags and allow for printing stdout
localfile = '.tmpfile_dm_adb'
try:
# First attempt to pull file regularly
outerr = self._runCmd(["pull", remoteFile, localFile]).communicate()
Expand All @@ -512,40 +510,51 @@ def pullFile(self, remoteFile):
self._runCmd(["pull", remoteTmpFile, localFile]).stdout.read()
# Clean up temporary file
self._checkCmdAs(["shell", "rm", remoteTmpFile])
return localFile
except (OSError, ValueError):
return None

f = open(localFile)
ret = f.read()
f.close()
os.remove(localfile)
return ret
except:
def pullFile(self, remoteFile):
"""
Returns contents of remoteFile using the "pull" command.
returns:
success: output of pullfile, string
failure: None
"""
# TODO: add debug flags and allow for printing stdout
localFile = tempfile.mkstemp()[1]
localFile = self._runPull(remoteFile, localFile)

if localFile is None:
print 'Automation Error: failed to pull file %s!' % remoteFile
return None

def getFile(self, remoteFile, localFile = ''):
f = open(localFile, 'r')
ret = f.read()
f.close()
os.remove(localFile)
return ret

def getFile(self, remoteFile, localFile = 'temp.txt'):
"""
Copy file from device (remoteFile) to host (localFile)
returns:
success: contents of file, string
failure: None
"""
if localFile == '':
localFile = os.path.join(self.tempRoot, "temp.txt")

try:
contents = self.pullFile(remoteFile)
except:
return None

if contents == None:
if contents is None:
return None

fhandle = open(localFile, 'wb')
fhandle.write(contents)
fhandle.close()
if not self.validateFile(remoteFile, localFile):
print 'Automation Error: failed to validate file when downloading %s!' % remoteFile
return None
return contents


Expand Down Expand Up @@ -587,21 +596,33 @@ def validateFile(self, remoteFile, localFile):
Checks if the remoteFile has the same md5 hash as the localFile
returns:
success: True
failure: False
success: True/False
failure: None
"""
return self._getRemoteHash(remoteFile) == self._getLocalHash(localFile)
md5Remote = self._getRemoteHash(remoteFile)
md5Local = self._getLocalHash(localFile)
if md5Remote is None or md5Local is None:
return None
return md5Remote == md5Local

def _getRemoteHash(self, filename):
def _getRemoteHash(self, remoteFile):
"""
Return the md5 sum of a file on the device
returns:
success: MD5 hash for given filename
failure: None
"""
data = self._runCmd(["shell", "ls", "-l", filename]).stdout.read()
return data.split()[3]
localFile = tempfile.mkstemp()[1]
localFile = self._runPull(remoteFile, localFile)

if localFile is None:
return None

md5 = self._getLocalHash(localFile)
os.remove(localFile)

return md5

# setup the device root and cache its value
def _setupDeviceRoot(self):
Expand Down Expand Up @@ -981,7 +1002,7 @@ def _checkForRoot(self):
# Check whether we _are_ root by default (some development boards work
# this way, this is also the result of some relatively rare rooting
# techniques)
proc = self.runCmd(["shell", "id"])
proc = self._runCmd(["shell", "id"])
data = proc.stdout.read()
if data.find('uid=0(root)') >= 0:
self.haveRootShell = True
Expand All @@ -990,7 +1011,7 @@ def _checkForRoot(self):

# if root shell is not available, check if 'su' can be used to gain
# root
proc = self.runCmd(["shell", "su", "-c", "id"])
proc = self._runCmd(["shell", "su", "-c", "id"])

# wait for response for maximum of 15 seconds, in case su prompts for a
# password or triggers the Android SuperUser prompt
Expand Down
2 changes: 1 addition & 1 deletion mozdevice/setup.py
Expand Up @@ -5,7 +5,7 @@
import os
from setuptools import setup

PACKAGE_VERSION = '0.8'
PACKAGE_VERSION = '0.9'

# take description from README
here = os.path.dirname(os.path.abspath(__file__))
Expand Down

0 comments on commit 4d43867

Please sign in to comment.