Bug 886882 - Mirror mozdevice 0.27;r=jhammel

This commit is contained in:
William Lachance 2013-06-25 10:50:37 -07:00
Родитель 228b79b0ec
Коммит d4ff842ffa
7 изменённых файлов: 57 добавлений и 15 удалений

Просмотреть файл

@ -180,9 +180,13 @@ class DeviceManager(object):
"""
@abstractmethod
def pullFile(self, remoteFilename):
def pullFile(self, remoteFilename, offset=None, length=None):
"""
Returns contents of remoteFile using the "pull" command.
:param remoteFilename: Path to file to pull from remote device.
:param offset: Offset in bytes from which to begin reading (optional)
:param length: Number of bytes to read (optional)
"""
@abstractmethod

Просмотреть файл

@ -386,13 +386,24 @@ class DeviceManagerADB(DeviceManager):
except (OSError, ValueError):
raise DMError("Error pulling remote file '%s' to '%s'" % (remoteFile, localFile))
def pullFile(self, remoteFile):
def pullFile(self, remoteFile, offset=None, length=None):
# TODO: add debug flags and allow for printing stdout
localFile = tempfile.mkstemp()[1]
self._runPull(remoteFile, localFile)
f = open(localFile, 'r')
ret = f.read()
# ADB pull does not support offset and length, but we can instead
# read only the requested portion of the local file
if offset is not None and length is not None:
f.seek(offset)
ret = f.read(length)
elif offset is not None:
f.seek(offset)
ret = f.read()
else:
ret = f.read()
f.close()
os.remove(localFile)
return ret

Просмотреть файл

@ -542,7 +542,7 @@ class DeviceManagerSUT(DeviceManager):
def getTempDir(self):
return self._runCmds([{ 'cmd': 'tmpd' }]).strip()
def pullFile(self, remoteFile):
def pullFile(self, remoteFile, offset=None, length=None):
# The "pull" command is different from other commands in that DeviceManager
# has to read a certain number of bytes instead of just reading to the
# next prompt. This is more robust than the "cat" command, which will be
@ -604,7 +604,14 @@ class DeviceManagerSUT(DeviceManager):
# <filename>,-1\n<error message>
# just send the command first, we read the response inline below
self._runCmds([{ 'cmd': 'pull ' + remoteFile }])
if offset is not None and length is not None:
cmd = 'pull %s %d %d' % (remoteFile, offset, length)
elif offset is not None:
cmd = 'pull %s %d' % (remoteFile, offset)
else:
cmd = 'pull %s' % remoteFile
self._runCmds([{ 'cmd': cmd }])
# read metadata; buffer the rest
metadata, sep, buf = read_until_char('\n', buf, 'could not find metadata')

Просмотреть файл

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

Просмотреть файл

@ -3,11 +3,17 @@
# Any copyright is dedicated to the Public Domain.
# http://creativecommons.org/publicdomain/zero/1.0/
import datetime
import socket
from threading import Thread
import time
from threading import Thread
class MockAgent(object):
MAX_WAIT_TIME_SECONDS = 10
SOCKET_TIMEOUT_SECONDS = 5
def __init__(self, tester, start_commands = None, commands = []):
if start_commands:
self.commands = start_commands
@ -37,10 +43,22 @@ class MockAgent(object):
while self.commands:
if not conn:
conn, addr = self._sock.accept()
conn.settimeout(self.SOCKET_TIMEOUT_SECONDS)
conn.send("$>\x00")
(command, response) = self.commands.pop(0)
data = conn.recv(1024).strip()
self.tester.assertEqual(data, command)
data = ''
timeout = datetime.datetime.now() + datetime.timedelta(
seconds=self.MAX_WAIT_TIME_SECONDS)
# The data might come in chunks, particularly if we are expecting
# multiple lines, as with push commands.
while (len(data) < len(command) and
datetime.datetime.now() < timeout):
try:
data += conn.recv(1024)
except socket.timeout:
# We handle timeouts in the main loop.
pass
self.tester.assertEqual(data.strip(), command)
# send response and prompt separately to test for bug 789496
# FIXME: Improve the mock agent, since overloading the meaning
# of 'response' is getting confusing.

Просмотреть файл

@ -16,7 +16,7 @@ class PushTest(unittest.TestCase):
# (good response, no exception), (bad response, exception)
for response in [ (expectedResponse, False), ("BADHASH", True) ]:
cmd = "push /mnt/sdcard/foobar %s" % len(pushfile)
cmd = "push /mnt/sdcard/foobar %s\r\n%s" % (len(pushfile), pushfile)
a = MockAgent(self, commands = [("isdir /mnt/sdcard", "TRUE"),
(cmd, response[0])])
exceptionThrown = False
@ -46,14 +46,16 @@ class PushTest(unittest.TestCase):
subTests = [ { 'cmds': [ ("isdir /mnt/sdcard//baz", "TRUE"),
("isdir /mnt/sdcard//baz", "TRUE"),
("push /mnt/sdcard//baz/%s %s" %
(os.path.basename(f.name), len(pushfile)),
("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" %
(os.path.basename(f.name), len(pushfile)),
("push /mnt/sdcard//baz/%s %s\r\n%s" %
(os.path.basename(f.name), len(pushfile),
pushfile),
"BADHASH") ],
'expectException': True },
{ 'cmds': [ ("isdir /mnt/sdcard//baz", "FALSE"),

Просмотреть файл

@ -10,7 +10,7 @@
[include:manifestdestiny/tests/manifest.ini]
[include:mozcrash/tests/manifest.ini]
# [include:mozdevice/tests/manifest.ini] bug 885784
[include:mozdevice/tests/manifest.ini]
[include:mozfile/tests/manifest.ini]
[include:mozhttpd/tests/manifest.ini]
[include:mozprocess/tests/manifest.ini]