本文整理汇总了Python中devicemanager.NetworkTools类的典型用法代码示例。如果您正苦于以下问题:Python NetworkTools类的具体用法?Python NetworkTools怎么用?Python NetworkTools使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了NetworkTools类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: updateApp
def updateApp(self, appBundlePath, processName=None, destPath=None,
ipAddr=None, port=30000, wait=False):
# port ^^^ is here for backwards compatibility only, we now
# determine a port automatically and safely
wait = (wait or ipAddr)
cmd = 'updt '
if processName is None:
# Then we pass '' for processName
cmd += "'' " + appBundlePath
else:
cmd += processName + ' ' + appBundlePath
if destPath:
cmd += " " + destPath
if wait:
if not ipAddr:
nettools = NetworkTools()
ipAddr = nettools.getLanIp()
serverSocket = self._getRebootServerSocket(ipAddr)
cmd += " %s %s" % serverSocket.getsockname()
self._logger.debug("updateApp using command: " % cmd)
self._runCmds([{'cmd': cmd}])
if wait:
self._waitForRebootPing(serverSocket)
示例2: DroidConnectByHWID
def DroidConnectByHWID(hwid, timeout=30, **kwargs):
"""Try to connect to the given device by waiting for it to show up using mDNS with the given timeout."""
import re
if re.match('[0-9]+.[0-9]+.[0-9]+.[0-9]+', hwid):
print "Connected via SUT to %s" % (hwid)
return DroidSUT(hwid, **kwargs)
nt = NetworkTools()
local_ip = nt.getLanIp()
zc = Zeroconf(local_ip)
evt = threading.Event()
listener = ZeroconfListener(hwid, evt)
sb = ServiceBrowser(zc, "_sutagent._tcp.local.", listener)
foundIP = None
if evt.wait(timeout):
# we found the hwid
foundIP = listener.ip
sb.cancel()
zc.close()
if foundIP is not None:
return DroidSUT(foundIP, **kwargs)
print "Connected via SUT to %s [at %s]" % (hwid, foundIP)
# try connecting via adb
try:
sut = DroidADB(deviceSerial=hwid, **kwargs)
except:
return None
print "Connected via ADB to %s" % (hwid)
return sut
示例3: reboot
def reboot(self, ipAddr=None, port=30000, wait=False):
# port ^^^ is here for backwards compatibility only, we now
# determine a port automatically and safely
wait = (wait or ipAddr)
cmd = 'rebt'
self._logger.info("Rebooting device")
# if we're waiting, create a listening server and pass information on
# it to the device before rebooting (we do this instead of just polling
# to make sure the device actually rebooted -- yes, there are probably
# simpler ways of doing this like polling uptime, but this is what we're
# doing for now)
if wait:
if not ipAddr:
nettools = NetworkTools()
ipAddr = nettools.getLanIp()
serverSocket = self._getRebootServerSocket(ipAddr)
# The update.info command tells the SUTAgent to send a TCP message
# after restarting.
destname = '/data/data/com.mozilla.SUTAgentAndroid/files/update.info'
data = "%s,%s\rrebooting\r" % serverSocket.getsockname()
self._runCmds([{'cmd': 'push %s %s' % (destname, len(data)),
'data': data}])
cmd += " %s %s" % serverSocket.getsockname()
# actually reboot device
self._runCmds([{'cmd': cmd}])
# if we're waiting, wait for a callback ping from the agent before
# continuing (and throw an exception if we don't receive said ping)
if wait:
self._waitForRebootPing(serverSocket)
示例4: getCallbackIpAndPort
def getCallbackIpAndPort(self, aIp, aPort):
ip = aIp
nettools = NetworkTools()
if (ip == None):
ip = nettools.getLanIp()
if (aPort != None):
port = nettools.findOpenPort(ip, aPort)
else:
port = nettools.findOpenPort(ip, 30000)
return ip, port
示例5: reset_phones
def reset_phones(self):
nt = NetworkTools()
myip = nt.getLanIp()
for k,v in self._phonemap.iteritems():
logging.info("Rebooting %s:%s" % (k, v["name"]))
try:
dm = devicemanagerSUT.DeviceManagerSUT(v["ip"],v["port"])
dm.reboot(myip)
except:
logging.error("COULD NOT REBOOT PHONE: %s:%s" % (k, v["name"]))
示例6: __init__
def __init__(self, is_restarting=False, cachefile="daemon_cache.ini",
testconfig="test_config.ini", port=28001, logfile="daemon.log",
loglevel="DEBUG"):
self._stop = False
self._cache = cachefile
self._phonemap = {}
self._cachelock = threading.RLock()
logging.basicConfig(filename=logfile,
filemode="w",
level=loglevel,
format='%(asctime)s|%(levelname)s|%(message)s')
logging.info("Starting Daemon")
# Start the queue
self._jobs = Queue.Queue()
self._phonesstarted = False
if not os.path.exists(self._cache):
# If we don't have a cache you aren't restarting
is_restarting = False
open(self._cache, 'wb')
elif not is_restarting:
# If we have a cache and we are NOT restarting, then assume that
# cache is invalid. Blow it away and recreate it
os.remove(self._cache)
open(self._cache, 'wb')
if is_restarting:
self.read_cache()
self.reset_phones()
# Start our pulse listener for the birch builds
#self.pulsemonitor = start_pulse_monitor(buildCallback=self.on_build,
# tree=["birch"],
# platform=["linux-android"],
# mobile=False,
# buildtype="opt"
# )
nettools = NetworkTools()
ip = nettools.getLanIp()
self.server = CmdThreadedTCPServer((ip, int(port)), CmdTCPHandler)
server_thread = threading.Thread(target=self.server.serve_forever)
server_thread.setDaemon(True)
server_thread.start()
示例7: __init__
def __init__(self, is_restarting, reboot_phones, test_path, cachefile,
ipaddr, port, logfile, loglevel):
self._test_path = test_path
self._cache = cachefile
if ipaddr:
self.ipaddr = ipaddr
else:
nt = NetworkTools()
self.ipaddr = nt.getLanIp()
logging.info('IP address for phone callbacks not provided; using '
'%s.' % self.ipaddr)
self.port = port
self.logfile = logfile
self.loglevel = loglevel
self._stop = False
self.phone_workers = {} # indexed by mac address
self.worker_statuses = {}
self.worker_lock = threading.Lock()
self.cmd_lock = threading.Lock()
self._tests = []
logging.info('Starting autophone')
# queue for listening to status updates from tests
self.worker_msg_queue = multiprocessing.Queue()
self.read_tests()
if not os.path.exists(self._cache):
# If we don't have a cache you aren't restarting
is_restarting = False
open(self._cache, 'wb')
elif not is_restarting:
# If we have a cache and we are NOT restarting, then assume that
# cache is invalid. Blow it away and recreate it
os.remove(self._cache)
open(self._cache, 'wb')
if is_restarting:
self.read_cache()
if reboot_phones:
self.reset_phones()
self.server = None
self.server_thread = None
示例8: run
def run(self):
# Assume the script has been pushed to the phone, set up the path for adb
phonescript = self.testroot + "/" + os.path.split(self.script)[1]
for browser, app in self.apps.iteritems():
for rt in self.runtype:
for testname, url in self.urls.iteritems():
# Amend our testname to indicate our runtype
testname = testname + "-" + rt
self.log("Running %s with test: %s for %s iterations" %
(browser, testname, self.iterations))
for i in range(self.iterations):
if 'local' in testname:
# Then add in testroot as the server location in URL
u = url % (self.testroot, self.resultsip, self.phoneid, testname, browser, self.androidver, self.revision, self.builddate)
else:
# Then add in the webserver as the URL
u = url % (self.webserverip, self.resultsip, self.phoneid, testname, browser, self.androidver, self.revision, self.builddate)
# Pass in the browser application name so that the
# devicemanager knows which process to watch for
appname = app.split("/")[0]
cmd = ["sh", phonescript, app, u]
self.dm.launchProcess(cmd, appnameToCheck=appname)
# Give the html 5s to upload results
sleep(10)
if rt == "cold":
# reboot the device between runs
print "Rebooting device"
nettools = NetworkTools()
self.dm.reboot(nettools.getLanIp())
print "ok, done with reboot"
else:
# Then we do a warm startup, killing the process between runs
# The name of the process is to the left of the / in the activity manager string
self.dm.killProcess(app.split("/")[0])
if appname == "org.mozilla.fennec":
self.log("Removing session store files from fennec")
self._remove_sessionstore_files()
示例9: getLanIp
def getLanIp(self):
nettools = NetworkTools()
return nettools.getLanIp()