Bug 900629 - Mirror mozdevice 0.29;r=ahal

This commit is contained in:
William Lachance 2013-08-01 16:08:18 -04:00
parent 2f4d765648
commit ce8c269b00
5 changed files with 15 additions and 24 deletions

View File

@ -169,7 +169,7 @@ class DeviceManager(object):
self.removeFile(tempScreenshotFile)
@abstractmethod
def pushFile(self, localFilename, remoteFilename, retryLimit=1):
def pushFile(self, localFilename, remoteFilename, retryLimit=1, createDir=True):
"""
Copies localname from the host to destname on the device.
"""

View File

@ -191,7 +191,7 @@ class DeviceManagerADB(DeviceManager):
def _disconnectRemoteADB(self):
self._checkCmd(["disconnect", self.host + ":" + str(self.port)])
def pushFile(self, localname, destname, retryLimit=None):
def pushFile(self, localname, destname, retryLimit=None, createDir=True):
# you might expect us to put the file *in* the directory in this case,
# but that would be different behaviour from devicemanagerSUT. Throw
# an exception so we have the same behaviour between the two
@ -232,7 +232,7 @@ class DeviceManagerADB(DeviceManager):
remoteZip = remoteDir + "/adbdmtmp.zip"
subprocess.Popen(["zip", "-r", localZip, '.'], cwd=localDir,
stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()
self.pushFile(localZip, remoteZip, retryLimit=retryLimit)
self.pushFile(localZip, remoteZip, retryLimit=retryLimit, createDir=False)
os.remove(localZip)
data = self._runCmdAs(["shell", "unzip", "-o", remoteZip,
"-d", remoteDir]).stdout.read()

View File

@ -230,7 +230,7 @@ class DeviceManagerSUT(DeviceManager):
# Get our response
try:
# Wait up to a second for socket to become ready for reading...
# Wait up to a second for socket to become ready for reading...
if select.select([self._sock], [], [], select_timeout)[0]:
temp = self._sock.recv(1024)
self._logger.debug("response: %s" % temp)
@ -338,9 +338,10 @@ class DeviceManagerSUT(DeviceManager):
# woops, we couldn't find an end of line/return value
raise DMError("Automation Error: Error finding end of line/return value when running '%s'" % cmdline)
def pushFile(self, localname, destname, retryLimit = None):
def pushFile(self, localname, destname, retryLimit=None, createDir=True):
retryLimit = retryLimit or self.retryLimit
self.mkDirs(destname)
if createDir:
self.mkDirs(destname)
try:
filesize = os.path.getsize(localname)
@ -382,8 +383,7 @@ class DeviceManagerSUT(DeviceManager):
self.mkDirs(remoteName)
existentDirectories.append(parent)
self.pushFile(os.path.join(root, f), remoteName, retryLimit=retryLimit)
self.pushFile(os.path.join(root, f), remoteName, retryLimit=retryLimit, createDir=False)
def dirExists(self, remotePath):
ret = self._runCmds([{ 'cmd': 'isdir ' + remotePath }]).strip()
@ -562,30 +562,23 @@ class DeviceManagerSUT(DeviceManager):
# the class level if we wanted to refactor sendCMD(). For now they are
# only used to pull files.
def uread(to_recv, error_msg, timeout=None):
def uread(to_recv, error_msg):
""" unbuffered read """
timer = 0
select_timeout = 1
if not timeout:
timeout = self.default_timeout
try:
if select.select([self._sock], [], [], select_timeout)[0]:
data = ""
if select.select([self._sock], [], [], self.default_timeout)[0]:
data = self._sock.recv(to_recv)
timer = 0
timer += select_timeout
if timer > timeout:
err('timeout in uread while retrieving file')
if not data:
# timed out waiting for response or error response
err(error_msg)
return data
except:
err(error_msg)
def read_until_char(c, buf, error_msg):
""" read until 'c' is found; buffer rest """
while not '\n' in buf:
while not c in buf:
data = uread(1024, error_msg)
buf += data
return buf.partition(c)

View File

@ -4,7 +4,7 @@
from setuptools import setup
PACKAGE_VERSION = '0.28'
PACKAGE_VERSION = '0.29'
setup(name='mozdevice',
version=PACKAGE_VERSION,

View File

@ -45,14 +45,12 @@ class PushTest(unittest.TestCase):
f.flush()
subTests = [ { 'cmds': [ ("isdir /mnt/sdcard/baz", "TRUE"),
("isdir /mnt/sdcard/baz", "TRUE"),
("push /mnt/sdcard/baz/%s %s\r\n%s" %
(os.path.basename(f.name), len(pushfile),
pushfile),
expectedFileResponse) ],
'expectException': False },
{ 'cmds': [ ("isdir /mnt/sdcard/baz", "TRUE"),
("isdir /mnt/sdcard/baz", "TRUE"),
("push /mnt/sdcard/baz/%s %s\r\n%s" %
(os.path.basename(f.name), len(pushfile),
pushfile),