2010-02-23 08:48:16 -08:00
|
|
|
# ***** BEGIN LICENSE BLOCK *****
|
|
|
|
# Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
|
|
|
#
|
|
|
|
# The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
# 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
# the License. You may obtain a copy of the License at
|
|
|
|
# http://www.mozilla.org/MPL/
|
|
|
|
#
|
|
|
|
# Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
# for the specific language governing rights and limitations under the
|
|
|
|
# License.
|
|
|
|
#
|
|
|
|
# The Original Code is Test Automation Framework.
|
|
|
|
#
|
|
|
|
# The Initial Developer of the Original Code is Joel Maher.
|
|
|
|
#
|
|
|
|
# Portions created by the Initial Developer are Copyright (C) 2009
|
|
|
|
# the Initial Developer. All Rights Reserved.
|
|
|
|
#
|
|
|
|
# Contributor(s):
|
2010-07-19 08:55:42 -07:00
|
|
|
# Joel Maher <joel.maher@gmail.com> (Original Developer)
|
|
|
|
# Clint Talbert <cmtalbert@gmail.com>
|
2011-01-13 10:00:23 -08:00
|
|
|
# Mark Cote <mcote@mozilla.com>
|
2010-02-23 08:48:16 -08:00
|
|
|
#
|
|
|
|
# Alternatively, the contents of this file may be used under the terms of
|
|
|
|
# either the GNU General Public License Version 2 or later (the "GPL"), or
|
|
|
|
# the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
# in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
# of those above. If you wish to allow use of your version of this file only
|
|
|
|
# under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
# use your version of this file under the terms of the MPL, indicate your
|
|
|
|
# decision by deleting the provisions above and replace them with the notice
|
|
|
|
# and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
# the provisions above, a recipient may use your version of this file under
|
|
|
|
# the terms of any one of the MPL, the GPL or the LGPL.
|
|
|
|
#
|
|
|
|
# ***** END LICENSE BLOCK *****
|
|
|
|
|
2011-05-06 15:11:02 -07:00
|
|
|
import time
|
|
|
|
import hashlib
|
2010-02-23 08:48:16 -08:00
|
|
|
import socket
|
|
|
|
import os
|
2011-05-06 15:17:55 -07:00
|
|
|
import re
|
2010-02-23 08:48:16 -08:00
|
|
|
|
2010-03-15 15:45:00 -07:00
|
|
|
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
|
2010-02-23 08:48:16 -08:00
|
|
|
|
2011-01-13 10:00:23 -08:00
|
|
|
class DMError(Exception):
|
|
|
|
"generic devicemanager exception."
|
|
|
|
|
|
|
|
def __init__(self, msg= ''):
|
|
|
|
self.msg = msg
|
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
return self.msg
|
|
|
|
|
|
|
|
|
2010-02-23 08:48:16 -08:00
|
|
|
class DeviceManager:
|
2011-01-13 10:00:23 -08:00
|
|
|
# external function
|
|
|
|
# returns:
|
|
|
|
# success: True
|
|
|
|
# failure: False
|
2010-02-23 08:48:16 -08:00
|
|
|
def pushFile(self, localname, destname):
|
2011-05-06 15:11:02 -07:00
|
|
|
assert 0 == 1
|
|
|
|
return False
|
2010-02-23 08:48:16 -08:00
|
|
|
|
2011-01-13 10:00:23 -08:00
|
|
|
# external function
|
|
|
|
# returns:
|
|
|
|
# success: directory name
|
|
|
|
# failure: None
|
2010-02-23 08:48:16 -08:00
|
|
|
def mkDir(self, name):
|
2011-05-06 15:11:02 -07:00
|
|
|
assert 0 == 1
|
|
|
|
return None
|
2011-01-13 10:00:23 -08:00
|
|
|
|
2010-02-23 08:48:16 -08:00
|
|
|
# make directory structure on the device
|
2011-01-13 10:00:23 -08:00
|
|
|
# external function
|
|
|
|
# returns:
|
|
|
|
# success: directory structure that we created
|
|
|
|
# failure: None
|
2010-02-23 08:48:16 -08:00
|
|
|
def mkDirs(self, filename):
|
2011-05-06 15:11:02 -07:00
|
|
|
assert 0 == 1
|
|
|
|
return None
|
2010-02-23 08:48:16 -08:00
|
|
|
|
|
|
|
# push localDir from host to remoteDir on the device
|
2011-01-13 10:00:23 -08:00
|
|
|
# external function
|
|
|
|
# returns:
|
|
|
|
# success: remoteDir
|
|
|
|
# failure: None
|
2010-02-23 08:48:16 -08:00
|
|
|
def pushDir(self, localDir, remoteDir):
|
2011-05-06 15:11:02 -07:00
|
|
|
assert 0 == 1
|
|
|
|
return None
|
2010-02-23 08:48:16 -08:00
|
|
|
|
2011-01-13 10:00:23 -08:00
|
|
|
# external function
|
|
|
|
# returns:
|
|
|
|
# success: True
|
|
|
|
# failure: False
|
2010-02-23 08:48:16 -08:00
|
|
|
def dirExists(self, dirname):
|
2011-05-06 15:11:02 -07:00
|
|
|
assert 0 == 1
|
|
|
|
return False
|
2010-02-23 08:48:16 -08:00
|
|
|
|
|
|
|
# Because we always have / style paths we make this a lot easier with some
|
|
|
|
# assumptions
|
2011-01-13 10:00:23 -08:00
|
|
|
# external function
|
|
|
|
# returns:
|
|
|
|
# success: True
|
|
|
|
# failure: False
|
2010-02-23 08:48:16 -08:00
|
|
|
def fileExists(self, filepath):
|
2011-05-06 15:11:02 -07:00
|
|
|
assert 0 == 1
|
2010-02-23 08:48:16 -08:00
|
|
|
return False
|
|
|
|
|
|
|
|
# list files on the device, requires cd to directory first
|
2011-01-13 10:00:23 -08:00
|
|
|
# external function
|
|
|
|
# returns:
|
|
|
|
# success: array of filenames, ['file1', 'file2', ...]
|
|
|
|
# failure: []
|
2010-02-23 08:48:16 -08:00
|
|
|
def listFiles(self, rootdir):
|
2011-05-06 15:11:02 -07:00
|
|
|
assert 0 == 1
|
|
|
|
return []
|
2010-02-23 08:48:16 -08:00
|
|
|
|
2011-01-13 10:00:23 -08:00
|
|
|
# external function
|
|
|
|
# returns:
|
|
|
|
# success: output of telnet, i.e. "removing file: /mnt/sdcard/tests/test.txt"
|
|
|
|
# failure: None
|
2010-02-23 08:48:16 -08:00
|
|
|
def removeFile(self, filename):
|
2011-05-06 15:11:02 -07:00
|
|
|
assert 0 == 1
|
|
|
|
return False
|
2011-01-13 10:00:23 -08:00
|
|
|
|
2010-02-23 08:48:16 -08:00
|
|
|
# does a recursive delete of directory on the device: rm -Rf remoteDir
|
2011-01-13 10:00:23 -08:00
|
|
|
# external function
|
|
|
|
# returns:
|
|
|
|
# success: output of telnet, i.e. "removing file: /mnt/sdcard/tests/test.txt"
|
|
|
|
# failure: None
|
2010-02-23 08:48:16 -08:00
|
|
|
def removeDir(self, remoteDir):
|
2011-05-06 15:11:02 -07:00
|
|
|
assert 0 == 1
|
|
|
|
return None
|
2011-01-13 10:00:23 -08:00
|
|
|
|
|
|
|
# external function
|
|
|
|
# returns:
|
|
|
|
# success: array of process tuples
|
|
|
|
# failure: []
|
2010-02-23 08:48:16 -08:00
|
|
|
def getProcessList(self):
|
2011-05-06 15:11:02 -07:00
|
|
|
assert 0 == 1
|
|
|
|
return []
|
2010-02-23 08:48:16 -08:00
|
|
|
|
2011-01-13 10:00:23 -08:00
|
|
|
# external function
|
|
|
|
# returns:
|
|
|
|
# success: pid
|
|
|
|
# failure: None
|
2011-02-24 11:45:39 -08:00
|
|
|
def fireProcess(self, appname, failIfRunning=False):
|
2011-05-06 15:11:02 -07:00
|
|
|
assert 0 == 1
|
|
|
|
return None
|
2010-02-23 08:48:16 -08:00
|
|
|
|
2011-01-13 10:00:23 -08:00
|
|
|
# external function
|
|
|
|
# returns:
|
|
|
|
# success: output filename
|
|
|
|
# failure: None
|
2011-02-24 11:45:39 -08:00
|
|
|
def launchProcess(self, cmd, outputFile = "process.txt", cwd = '', env = '', failIfRunning=False):
|
2011-05-06 15:11:02 -07:00
|
|
|
assert 0 == 1
|
|
|
|
return None
|
2010-05-27 13:02:15 -07:00
|
|
|
|
2011-01-13 10:00:23 -08:00
|
|
|
# loops until 'process' has exited or 'timeout' seconds is reached
|
|
|
|
# loop sleeps for 'interval' seconds between iterations
|
|
|
|
# external function
|
|
|
|
# returns:
|
|
|
|
# success: [file contents, None]
|
|
|
|
# failure: [None, None]
|
|
|
|
def communicate(self, process, timeout = 600, interval = 5):
|
2010-02-23 08:48:16 -08:00
|
|
|
timed_out = True
|
|
|
|
if (timeout > 0):
|
|
|
|
total_time = 0
|
|
|
|
while total_time < timeout:
|
2010-05-27 13:02:15 -07:00
|
|
|
time.sleep(interval)
|
2011-01-13 10:00:23 -08:00
|
|
|
if self.processExist(process) == None:
|
2010-02-23 08:48:16 -08:00
|
|
|
timed_out = False
|
|
|
|
break
|
2010-05-27 13:02:15 -07:00
|
|
|
total_time += interval
|
2010-02-23 08:48:16 -08:00
|
|
|
|
|
|
|
if (timed_out == True):
|
2011-01-13 10:00:23 -08:00
|
|
|
return [None, None]
|
2010-02-23 08:48:16 -08:00
|
|
|
|
|
|
|
return [self.getFile(process, "temp.txt"), None]
|
|
|
|
|
2011-01-13 10:00:23 -08:00
|
|
|
# iterates process list and returns pid if exists, otherwise None
|
|
|
|
# external function
|
|
|
|
# returns:
|
|
|
|
# success: pid
|
|
|
|
# failure: None
|
2010-02-23 08:48:16 -08:00
|
|
|
def processExist(self, appname):
|
2011-01-13 10:00:23 -08:00
|
|
|
pid = None
|
2010-12-16 15:28:35 -08:00
|
|
|
|
2011-04-20 05:52:13 -07:00
|
|
|
#filter out extra spaces
|
2011-01-13 10:00:23 -08:00
|
|
|
parts = filter(lambda x: x != '', appname.split(' '))
|
2011-04-20 05:52:13 -07:00
|
|
|
appname = ' '.join(parts)
|
2010-12-16 15:28:35 -08:00
|
|
|
|
2011-04-20 05:52:13 -07:00
|
|
|
#filter out the quoted env string if it exists
|
|
|
|
#ex: '"name=value;name2=value2;etc=..." process args' -> 'process args'
|
|
|
|
parts = appname.split('"')
|
|
|
|
if (len(parts) > 2):
|
|
|
|
appname = ' '.join(parts[2:]).strip()
|
2010-02-23 08:48:16 -08:00
|
|
|
|
2010-05-27 13:02:15 -07:00
|
|
|
pieces = appname.split(' ')
|
|
|
|
parts = pieces[0].split('/')
|
|
|
|
app = parts[-1]
|
|
|
|
|
2010-02-23 08:48:16 -08:00
|
|
|
procList = self.getProcessList()
|
2011-01-13 10:00:23 -08:00
|
|
|
if (procList == []):
|
2010-02-23 08:48:16 -08:00
|
|
|
return None
|
|
|
|
|
|
|
|
for proc in procList:
|
2012-01-07 15:41:08 -08:00
|
|
|
procName = proc[1].split('/')[-1]
|
|
|
|
if (procName == app):
|
2010-02-23 08:48:16 -08:00
|
|
|
pid = proc[0]
|
|
|
|
break
|
|
|
|
return pid
|
|
|
|
|
2011-01-13 10:00:23 -08:00
|
|
|
# external function
|
|
|
|
# returns:
|
|
|
|
# success: output from testagent
|
|
|
|
# failure: None
|
2010-02-23 08:48:16 -08:00
|
|
|
def killProcess(self, appname):
|
2011-05-06 15:11:02 -07:00
|
|
|
assert 0 == 1
|
|
|
|
return None
|
2010-12-16 15:28:35 -08:00
|
|
|
|
2011-01-13 10:00:23 -08:00
|
|
|
# external function
|
|
|
|
# returns:
|
|
|
|
# success: filecontents
|
|
|
|
# failure: None
|
2010-12-16 15:28:35 -08:00
|
|
|
def catFile(self, remoteFile):
|
2011-05-06 15:11:02 -07:00
|
|
|
assert 0 == 1
|
|
|
|
return None
|
2011-01-13 10:00:23 -08:00
|
|
|
|
|
|
|
# external function
|
|
|
|
# returns:
|
|
|
|
# success: output of pullfile, string
|
|
|
|
# failure: None
|
2010-12-16 15:28:35 -08:00
|
|
|
def pullFile(self, remoteFile):
|
2011-05-06 15:11:02 -07:00
|
|
|
assert 0 == 1
|
|
|
|
return None
|
2010-12-16 15:28:35 -08:00
|
|
|
|
2010-02-23 08:48:16 -08:00
|
|
|
# copy file from device (remoteFile) to host (localFile)
|
2011-01-13 10:00:23 -08:00
|
|
|
# external function
|
|
|
|
# returns:
|
|
|
|
# success: output of pullfile, string
|
|
|
|
# failure: None
|
2010-02-23 08:48:16 -08:00
|
|
|
def getFile(self, remoteFile, localFile = ''):
|
2011-05-06 15:11:02 -07:00
|
|
|
assert 0 == 1
|
|
|
|
return None
|
2011-01-13 10:00:23 -08:00
|
|
|
|
2010-02-23 08:48:16 -08:00
|
|
|
# copy directory structure from device (remoteDir) to host (localDir)
|
2011-01-13 10:00:23 -08:00
|
|
|
# external function
|
2011-02-04 10:49:37 -08:00
|
|
|
# checkDir exists so that we don't create local directories if the
|
|
|
|
# remote directory doesn't exist but also so that we don't call isDir
|
|
|
|
# twice when recursing.
|
2011-01-13 10:00:23 -08:00
|
|
|
# returns:
|
|
|
|
# success: list of files, string
|
|
|
|
# failure: None
|
2011-02-04 10:49:37 -08:00
|
|
|
def getDirectory(self, remoteDir, localDir, checkDir=True):
|
2011-05-06 15:11:02 -07:00
|
|
|
assert 0 == 1
|
|
|
|
return None
|
2010-12-16 15:28:35 -08:00
|
|
|
|
2011-01-13 10:00:23 -08:00
|
|
|
# external function
|
|
|
|
# returns:
|
|
|
|
# success: True
|
|
|
|
# failure: False
|
|
|
|
# Throws a FileError exception when null (invalid dir/filename)
|
2010-12-16 15:28:35 -08:00
|
|
|
def isDir(self, remotePath):
|
2011-05-06 15:11:02 -07:00
|
|
|
assert 0 == 1
|
|
|
|
return False
|
2010-02-23 08:48:16 -08:00
|
|
|
|
|
|
|
# true/false check if the two files have the same md5 sum
|
2011-01-13 10:00:23 -08:00
|
|
|
# external function
|
|
|
|
# returns:
|
|
|
|
# success: True
|
|
|
|
# failure: False
|
2010-02-23 08:48:16 -08:00
|
|
|
def validateFile(self, remoteFile, localFile):
|
2011-05-06 15:11:02 -07:00
|
|
|
assert 0 == 1
|
2010-02-23 08:48:16 -08:00
|
|
|
return False
|
2011-05-06 15:11:02 -07:00
|
|
|
|
2010-02-23 08:48:16 -08:00
|
|
|
# return the md5 sum of a remote file
|
2011-01-13 10:00:23 -08:00
|
|
|
# internal function
|
|
|
|
# returns:
|
|
|
|
# success: MD5 hash for given filename
|
|
|
|
# failure: None
|
2010-02-23 08:48:16 -08:00
|
|
|
def getRemoteHash(self, filename):
|
2011-05-06 15:11:02 -07:00
|
|
|
assert 0 == 1
|
|
|
|
return None
|
2011-01-13 10:00:23 -08:00
|
|
|
|
2010-02-23 08:48:16 -08:00
|
|
|
# return the md5 sum of a file on the host
|
2011-01-13 10:00:23 -08:00
|
|
|
# internal function
|
|
|
|
# returns:
|
|
|
|
# success: MD5 hash for given filename
|
|
|
|
# failure: None
|
2010-02-23 08:48:16 -08:00
|
|
|
def getLocalHash(self, filename):
|
2010-12-16 15:28:35 -08:00
|
|
|
file = open(filename, 'rb')
|
|
|
|
if (file == None):
|
|
|
|
return None
|
2010-02-23 08:48:16 -08:00
|
|
|
|
2010-12-16 15:28:35 -08:00
|
|
|
try:
|
|
|
|
mdsum = hashlib.md5()
|
|
|
|
except:
|
|
|
|
return None
|
2010-02-23 08:48:16 -08:00
|
|
|
|
2010-12-16 15:28:35 -08:00
|
|
|
while 1:
|
|
|
|
data = file.read(1024)
|
|
|
|
if not data:
|
|
|
|
break
|
|
|
|
mdsum.update(data)
|
2010-02-23 08:48:16 -08:00
|
|
|
|
2010-12-16 15:28:35 -08:00
|
|
|
file.close()
|
|
|
|
hexval = mdsum.hexdigest()
|
|
|
|
if (self.debug >= 3): print "local hash returned: '" + hexval + "'"
|
|
|
|
return hexval
|
2010-02-23 08:48:16 -08:00
|
|
|
# Gets the device root for the testing area on the device
|
|
|
|
# For all devices we will use / type slashes and depend on the device-agent
|
2010-05-27 13:02:15 -07:00
|
|
|
# to sort those out. The agent will return us the device location where we
|
|
|
|
# should store things, we will then create our /tests structure relative to
|
|
|
|
# that returned path.
|
2010-02-23 08:48:16 -08:00
|
|
|
# Structure on the device is as follows:
|
|
|
|
# /tests
|
|
|
|
# /<fennec>|<firefox> --> approot
|
|
|
|
# /profile
|
|
|
|
# /xpcshell
|
|
|
|
# /reftest
|
|
|
|
# /mochitest
|
2011-01-13 10:00:23 -08:00
|
|
|
#
|
|
|
|
# external function
|
|
|
|
# returns:
|
|
|
|
# success: path for device root
|
|
|
|
# failure: None
|
2010-02-23 08:48:16 -08:00
|
|
|
def getDeviceRoot(self):
|
2011-05-06 15:11:02 -07:00
|
|
|
assert 0 == 1
|
|
|
|
return None
|
2010-02-23 08:48:16 -08:00
|
|
|
|
|
|
|
# Either we will have /tests/fennec or /tests/firefox but we will never have
|
|
|
|
# both. Return the one that exists
|
2011-01-13 10:00:23 -08:00
|
|
|
# TODO: ensure we can support org.mozilla.firefox
|
|
|
|
# external function
|
|
|
|
# returns:
|
|
|
|
# success: path for app root
|
|
|
|
# failure: None
|
2010-02-23 08:48:16 -08:00
|
|
|
def getAppRoot(self):
|
2012-01-07 15:41:08 -08:00
|
|
|
assert 0 == 1
|
2011-01-13 10:00:23 -08:00
|
|
|
return None
|
2010-02-23 08:48:16 -08:00
|
|
|
|
|
|
|
# Gets the directory location on the device for a specific test type
|
|
|
|
# Type is one of: xpcshell|reftest|mochitest
|
2011-01-13 10:00:23 -08:00
|
|
|
# external function
|
|
|
|
# returns:
|
|
|
|
# success: path for test root
|
|
|
|
# failure: None
|
2010-02-23 08:48:16 -08:00
|
|
|
def getTestRoot(self, type):
|
2011-01-13 10:00:23 -08:00
|
|
|
devroot = self.getDeviceRoot()
|
|
|
|
if (devroot == None):
|
|
|
|
return None
|
|
|
|
|
2010-02-23 08:48:16 -08:00
|
|
|
if (re.search('xpcshell', type, re.I)):
|
2011-01-13 10:00:23 -08:00
|
|
|
self.testRoot = devroot + '/xpcshell'
|
2010-02-23 08:48:16 -08:00
|
|
|
elif (re.search('?(i)reftest', type)):
|
2011-01-13 10:00:23 -08:00
|
|
|
self.testRoot = devroot + '/reftest'
|
2010-02-23 08:48:16 -08:00
|
|
|
elif (re.search('?(i)mochitest', type)):
|
2011-01-13 10:00:23 -08:00
|
|
|
self.testRoot = devroot + '/mochitest'
|
2010-02-23 08:48:16 -08:00
|
|
|
return self.testRoot
|
|
|
|
|
|
|
|
# Sends a specific process ID a signal code and action.
|
|
|
|
# For Example: SIGINT and SIGDFL to process x
|
|
|
|
def signal(self, processID, signalType, signalAction):
|
|
|
|
# currently not implemented in device agent - todo
|
|
|
|
pass
|
|
|
|
|
|
|
|
# Get a return code from process ending -- needs support on device-agent
|
|
|
|
def getReturnCode(self, processID):
|
2011-01-13 10:00:23 -08:00
|
|
|
# TODO: make this real
|
2010-02-23 08:48:16 -08:00
|
|
|
return 0
|
|
|
|
|
2011-01-13 10:00:23 -08:00
|
|
|
# external function
|
|
|
|
# returns:
|
|
|
|
# success: output of unzip command
|
|
|
|
# failure: None
|
2010-02-23 08:48:16 -08:00
|
|
|
def unpackFile(self, filename):
|
2011-05-06 15:11:02 -07:00
|
|
|
return None
|
2011-01-13 10:00:23 -08:00
|
|
|
|
|
|
|
# external function
|
|
|
|
# returns:
|
|
|
|
# success: status from test agent
|
|
|
|
# failure: None
|
2011-04-20 05:52:13 -07:00
|
|
|
def reboot(self, ipAddr=None, port=30000):
|
2011-05-06 15:11:02 -07:00
|
|
|
assert 0 == 1
|
|
|
|
return None
|
2010-03-15 15:45:00 -07:00
|
|
|
|
2010-02-23 08:48:16 -08:00
|
|
|
# validate localDir from host to remoteDir on the device
|
2011-01-13 10:00:23 -08:00
|
|
|
# external function
|
|
|
|
# returns:
|
|
|
|
# success: True
|
|
|
|
# failure: False
|
2010-02-23 08:48:16 -08:00
|
|
|
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('/', '/')
|
|
|
|
if (parts[1] == ""): remoteRoot = remoteDir
|
|
|
|
remoteName = remoteRoot + '/' + file
|
|
|
|
if (self.validateFile(remoteName, os.path.join(root, file)) <> True):
|
2011-01-13 10:00:23 -08:00
|
|
|
return False
|
2010-02-23 08:48:16 -08:00
|
|
|
return True
|
2010-05-27 13:02:15 -07:00
|
|
|
|
|
|
|
# Returns information about the device:
|
|
|
|
# Directive indicates the information you want to get, your choices are:
|
|
|
|
# os - name of the os
|
|
|
|
# id - unique id of the device
|
|
|
|
# uptime - uptime of the device
|
|
|
|
# systime - system time of the device
|
|
|
|
# screen - screen resolution
|
|
|
|
# memory - memory stats
|
|
|
|
# process - list of running processes (same as ps)
|
|
|
|
# disk - total, free, available bytes on disk
|
|
|
|
# power - power status (charge, battery temp)
|
2010-07-19 08:55:42 -07:00
|
|
|
# all - all of them - or call it with no parameters to get all the information
|
2011-01-13 10:00:23 -08:00
|
|
|
# returns:
|
|
|
|
# success: dict of info strings by directive name
|
|
|
|
# failure: {}
|
2010-07-19 08:55:42 -07:00
|
|
|
def getInfo(self, directive=None):
|
2011-05-06 15:11:02 -07:00
|
|
|
assert 0 == 1
|
|
|
|
return {}
|
2010-07-19 08:55:42 -07:00
|
|
|
|
2011-01-13 10:00:23 -08:00
|
|
|
# external function
|
|
|
|
# returns:
|
|
|
|
# success: output from agent for inst command
|
|
|
|
# failure: None
|
2010-07-19 08:55:42 -07:00
|
|
|
def installApp(self, appBundlePath, destPath=None):
|
2011-05-06 15:11:02 -07:00
|
|
|
assert 0 == 1
|
2010-11-18 13:03:44 -08:00
|
|
|
return None
|
2010-07-19 08:55:42 -07:00
|
|
|
|
2011-01-13 10:00:23 -08:00
|
|
|
# external function
|
|
|
|
# returns:
|
|
|
|
# success: True
|
|
|
|
# failure: None
|
2010-07-19 08:55:42 -07:00
|
|
|
def uninstallAppAndReboot(self, appName, installPath=None):
|
2011-05-06 15:11:02 -07:00
|
|
|
assert 0 == 1
|
|
|
|
return None
|
2010-05-27 13:02:15 -07:00
|
|
|
|
2011-01-13 10:00:23 -08:00
|
|
|
# external function
|
|
|
|
# returns:
|
|
|
|
# success: text status from command or callback server
|
|
|
|
# failure: None
|
2010-12-16 15:28:35 -08:00
|
|
|
def updateApp(self, appBundlePath, processName=None, destPath=None, ipAddr=None, port=30000):
|
2011-05-06 15:11:02 -07:00
|
|
|
assert 0 == 1
|
|
|
|
return None
|
2010-11-18 13:03:44 -08:00
|
|
|
|
2011-01-13 10:00:23 -08:00
|
|
|
# external function
|
|
|
|
# returns:
|
|
|
|
# success: time in ms
|
|
|
|
# failure: None
|
2010-09-17 17:18:06 -07:00
|
|
|
def getCurrentTime(self):
|
2011-05-06 15:11:02 -07:00
|
|
|
assert 0 == 1
|
|
|
|
return None
|
2011-04-20 05:52:13 -07:00
|
|
|
|
2010-11-18 13:03:44 -08:00
|
|
|
|
|
|
|
class NetworkTools:
|
|
|
|
def __init__(self):
|
|
|
|
pass
|
|
|
|
|
|
|
|
# Utilities to get the local ip address
|
|
|
|
def getInterfaceIp(self, ifname):
|
|
|
|
if os.name != "nt":
|
|
|
|
import fcntl
|
|
|
|
import struct
|
|
|
|
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
|
|
|
return socket.inet_ntoa(fcntl.ioctl(
|
|
|
|
s.fileno(),
|
|
|
|
0x8915, # SIOCGIFADDR
|
|
|
|
struct.pack('256s', ifname[:15])
|
|
|
|
)[20:24])
|
|
|
|
else:
|
|
|
|
return None
|
|
|
|
|
|
|
|
def getLanIp(self):
|
2012-01-03 12:15:02 -08:00
|
|
|
try:
|
|
|
|
ip = socket.gethostbyname(socket.gethostname())
|
|
|
|
except socket.gaierror:
|
|
|
|
ip = socket.gethostbyname(socket.gethostname() + ".local") # for Mac OS X
|
2010-11-18 13:03:44 -08:00
|
|
|
if ip.startswith("127.") and os.name != "nt":
|
|
|
|
interfaces = ["eth0","eth1","eth2","wlan0","wlan1","wifi0","ath0","ath1","ppp0"]
|
|
|
|
for ifname in interfaces:
|
|
|
|
try:
|
|
|
|
ip = self.getInterfaceIp(ifname)
|
|
|
|
break;
|
|
|
|
except IOError:
|
|
|
|
pass
|
|
|
|
return ip
|
|
|
|
|
|
|
|
# Gets an open port starting with the seed by incrementing by 1 each time
|
|
|
|
def findOpenPort(self, ip, seed):
|
|
|
|
try:
|
|
|
|
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
|
|
|
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
|
|
|
|
connected = False
|
|
|
|
if isinstance(seed, basestring):
|
|
|
|
seed = int(seed)
|
|
|
|
maxportnum = seed + 5000 # We will try at most 5000 ports to find an open one
|
|
|
|
while not connected:
|
|
|
|
try:
|
|
|
|
s.bind((ip, seed))
|
|
|
|
connected = True
|
|
|
|
s.close()
|
2011-01-13 10:00:23 -08:00
|
|
|
break
|
2010-11-18 13:03:44 -08:00
|
|
|
except:
|
|
|
|
if seed > maxportnum:
|
|
|
|
print "Could not find open port after checking 5000 ports"
|
|
|
|
raise
|
|
|
|
seed += 1
|
|
|
|
except:
|
|
|
|
print "Socket error trying to find open port"
|
|
|
|
|
|
|
|
return seed
|
2011-01-13 10:00:23 -08:00
|
|
|
|