Bug 774293 - Fix issues in devicemanager revealed by pyflakes;r=wlach

This commit is contained in:
Dominik Oepen 2012-08-14 10:41:11 -04:00
parent 8ee7419879
commit 822e64b426
5 changed files with 29 additions and 34 deletions

View File

@ -2,7 +2,6 @@
# License, v. 2.0. If a copy of the MPL was not distributed with this file, # License, v. 2.0. If a copy of the MPL was not distributed with this file,
# You can obtain one at http://mozilla.org/MPL/2.0/. # You can obtain one at http://mozilla.org/MPL/2.0/.
import time
import hashlib import hashlib
import socket import socket
import os import os

View File

@ -6,8 +6,8 @@ import subprocess
from devicemanager import DeviceManager, DMError, _pop_last_line from devicemanager import DeviceManager, DMError, _pop_last_line
import re import re
import os import os
import sys
import tempfile import tempfile
import time
class DeviceManagerADB(DeviceManager): class DeviceManagerADB(DeviceManager):
@ -65,7 +65,7 @@ class DeviceManagerADB(DeviceManager):
self.useRunAs = False self.useRunAs = False
try: try:
self.verifyRoot() self.verifyRoot()
except DMError, e: except DMError:
try: try:
self.checkCmd(["root"]) self.checkCmd(["root"])
# The root command does not fail even if ADB cannot get # The root command does not fail even if ADB cannot get
@ -394,7 +394,9 @@ class DeviceManagerADB(DeviceManager):
args.append("-9") args.append("-9")
args.append(pid) args.append(pid)
p = self.runCmdAs(args) p = self.runCmdAs(args)
didKillProcess = True p.communicate()
if p.returncode == 0:
didKillProcess = True
return didKillProcess return didKillProcess
@ -499,11 +501,11 @@ class DeviceManagerADB(DeviceManager):
# success: MD5 hash for given filename # success: MD5 hash for given filename
# failure: None # failure: None
def getRemoteHash(self, filename): def getRemoteHash(self, filename):
data = p = self.runCmd(["shell", "ls", "-l", filename]).stdout.read() data = self.runCmd(["shell", "ls", "-l", filename]).stdout.read()
return data.split()[3] return data.split()[3]
def getLocalHash(self, filename): def getLocalHash(self, filename):
data = p = subprocess.Popen(["ls", "-l", filename], stdout=subprocess.PIPE).stdout.read() data = subprocess.Popen(["ls", "-l", filename], stdout=subprocess.PIPE).stdout.read()
return data.split()[4] return data.split()[4]
# Internal method to setup the device root and cache its value # Internal method to setup the device root and cache its value
@ -693,7 +695,7 @@ class DeviceManagerADB(DeviceManager):
return ret return ret
def runCmd(self, args): def runCmd(self, args):
# If we are not root but have run-as, and we're trying to execute # If we are not root but have run-as, and we're trying to execute
# a shell command then using run-as is the best we can do # a shell command then using run-as is the best we can do
finalArgs = [self.adbPath] finalArgs = [self.adbPath]
if self.deviceSerial: if self.deviceSerial:
@ -711,7 +713,7 @@ class DeviceManagerADB(DeviceManager):
return self.runCmd(args) return self.runCmd(args)
def checkCmd(self, args): def checkCmd(self, args):
# If we are not root but have run-as, and we're trying to execute # If we are not root but have run-as, and we're trying to execute
# a shell command then using run-as is the best we can do # a shell command then using run-as is the best we can do
finalArgs = [self.adbPath] finalArgs = [self.adbPath]
if self.deviceSerial: if self.deviceSerial:

View File

@ -5,17 +5,14 @@
import select import select
import socket import socket
import SocketServer import SocketServer
import time, datetime import time
import os import os
import re import re
import hashlib
import posixpath import posixpath
import subprocess import subprocess
from threading import Thread from threading import Thread
import traceback
import sys
import StringIO import StringIO
from devicemanager import DeviceManager, DMError, FileError, NetworkTools, _pop_last_line from devicemanager import DeviceManager, FileError, NetworkTools, _pop_last_line
import errno import errno
class AgentError(Exception): class AgentError(Exception):
@ -126,7 +123,6 @@ class DeviceManagerSUT(DeviceManager):
one fails. this is necessary in particular for pushFile(), where we don't want one fails. this is necessary in particular for pushFile(), where we don't want
to accidentally send extra data if a failure occurs during data transmission. to accidentally send extra data if a failure occurs during data transmission.
''' '''
done = False
while self.retries < self.retrylimit: while self.retries < self.retrylimit:
try: try:
self._doCmds(cmdlist, outputfile, timeout) self._doCmds(cmdlist, outputfile, timeout)
@ -503,7 +499,7 @@ class DeviceManagerSUT(DeviceManager):
return None return None
try: try:
data = self.runCmds([{ 'cmd': 'exec ' + appname }]) self.runCmds([{ 'cmd': 'exec ' + appname }])
except AgentError: except AgentError:
return None return None
@ -547,7 +543,7 @@ class DeviceManagerSUT(DeviceManager):
if forceKill: if forceKill:
print "WARNING: killProcess(): forceKill parameter unsupported on SUT" print "WARNING: killProcess(): forceKill parameter unsupported on SUT"
try: try:
data = self.runCmds([{ 'cmd': 'kill ' + appname }]) self.runCmds([{ 'cmd': 'kill ' + appname }])
except AgentError: except AgentError:
return False return False
@ -640,7 +636,8 @@ class DeviceManagerSUT(DeviceManager):
# or, if error, # or, if error,
# <filename>,-1\n<error message> # <filename>,-1\n<error message>
try: try:
data = self.runCmds([{ 'cmd': 'pull ' + remoteFile }]) # just send the command first, we read the response inline below
self.runCmds([{ 'cmd': 'pull ' + remoteFile }])
except AgentError: except AgentError:
return None return None
@ -880,7 +877,6 @@ class DeviceManagerSUT(DeviceManager):
cmd = 'rebt' cmd = 'rebt'
if (self.debug > 3): print "INFO: sending rebt command" if (self.debug > 3): print "INFO: sending rebt command"
callbacksvrstatus = None
if (ipAddr is not None): if (ipAddr is not None):
#create update.info file: #create update.info file:

View File

@ -268,10 +268,9 @@ class Emulator(object):
local_port = s.getsockname()[1] local_port = s.getsockname()[1]
s.close() s.close()
output = self._run_adb(['-s', 'emulator-%d' % self.port, self._run_adb(['-s', 'emulator-%d' % self.port, 'forward',
'forward', 'tcp:%d' % local_port,
'tcp:%d' % local_port, 'tcp:%d' % remote_port])
'tcp:%d' % remote_port])
self.local_port = local_port self.local_port = local_port

View File

@ -3,19 +3,18 @@
# file, You can obtain one at http://mozilla.org/MPL/2.0/. # file, You can obtain one at http://mozilla.org/MPL/2.0/.
import time import time
import sys
import os import os
import socket
import automationutils import automationutils
import tempfile import tempfile
import shutil import shutil
import subprocess
from automation import Automation from automation import Automation
from devicemanager import DeviceManager, NetworkTools from devicemanager import NetworkTools
class RemoteAutomation(Automation): class RemoteAutomation(Automation):
_devicemanager = None _devicemanager = None
def __init__(self, deviceManager, appName = '', remoteLog = None): def __init__(self, deviceManager, appName = '', remoteLog = None):
self._devicemanager = deviceManager self._devicemanager = deviceManager
self._appName = appName self._appName = appName
@ -28,7 +27,7 @@ class RemoteAutomation(Automation):
def setDeviceManager(self, deviceManager): def setDeviceManager(self, deviceManager):
self._devicemanager = deviceManager self._devicemanager = deviceManager
def setAppName(self, appName): def setAppName(self, appName):
self._appName = appName self._appName = appName
@ -37,7 +36,7 @@ class RemoteAutomation(Automation):
def setProduct(self, product): def setProduct(self, product):
self._product = product self._product = product
def setRemoteLog(self, logfile): def setRemoteLog(self, logfile):
self._remoteLog = logfile self._remoteLog = logfile
@ -88,11 +87,11 @@ class RemoteAutomation(Automation):
if (self._remoteProfile): if (self._remoteProfile):
profileDir = self._remoteProfile profileDir = self._remoteProfile
# Hack for robocop, if app & testURL == None and extraArgs contains the rest of the stuff, lets # Hack for robocop, if app & testURL == None and extraArgs contains the rest of the stuff, lets
# assume extraArgs is all we need # assume extraArgs is all we need
if app == "am" and extraArgs[0] == "instrument": if app == "am" and extraArgs[0] == "instrument":
return app, extraArgs return app, extraArgs
cmd, args = Automation.buildCommandLine(self, app, debuggerInfo, profileDir, testURL, extraArgs) cmd, args = Automation.buildCommandLine(self, app, debuggerInfo, profileDir, testURL, extraArgs)
# Remove -foreground if it exists, if it doesn't this just returns # Remove -foreground if it exists, if it doesn't this just returns
try: try:
@ -113,7 +112,7 @@ class RemoteAutomation(Automation):
return self.RProcess(self._devicemanager, cmd, stdout, stderr, env, cwd) return self.RProcess(self._devicemanager, cmd, stdout, stderr, env, cwd)
# be careful here as this inner class doesn't have access to outer class members # be careful here as this inner class doesn't have access to outer class members
class RProcess(object): class RProcess(object):
# device manager process # device manager process
dm = None dm = None
@ -162,7 +161,7 @@ class RemoteAutomation(Automation):
if (hexpid == None): if (hexpid == None):
hexpid = "0x0" hexpid = "0x0"
return int(hexpid, 0) return int(hexpid, 0)
@property @property
def stdout(self): def stdout(self):
t = self.dm.getFile(self.proc) t = self.dm.getFile(self.proc)
@ -171,7 +170,7 @@ class RemoteAutomation(Automation):
retVal = t[self.stdoutlen:] retVal = t[self.stdoutlen:]
self.stdoutlen = tlen self.stdoutlen = tlen
return retVal.strip('\n').strip() return retVal.strip('\n').strip()
def wait(self, timeout = None): def wait(self, timeout = None):
timer = 0 timer = 0
interval = 5 interval = 5
@ -190,6 +189,6 @@ class RemoteAutomation(Automation):
if (timer >= timeout): if (timer >= timeout):
return 1 return 1
return 0 return 0
def kill(self): def kill(self):
self.dm.killProcess(self.procName) self.dm.killProcess(self.procName)