# Path: Peach/Utilities/ADB.py
# class AccessDebugBridge(object):
#     def __init__(self, adbPath="adb", deviceSerial=None, isEmulator=False):
#     def verifyADB(self):
#     def verifyDevice(self):
#     def runCmd(self, args):
#     def checkCmd(self, args, timeout=None):
#     def getProcessList(self):
#     def killProcess(self, appname, forceKill=False):
#     def reboot(self, wait=False):
#     def getCurrentTime(self):
#     def getDeviceInformation(self, directive="all"):
#     def makeDeviceReport(self):
#     def makeBugReport(self):
#     def getPID(self, procName):
#     def getPIDs(self, procName):
#     def shell(self, command):
#     def command(self, command):
# 
# Path: Peach/Utilities/network.py
# def cleanupSocketProcesses():
# def getUnboundPort(host="", minRange=30000, maxRange=35000, socket_type=1, assignOnlyOnce=False):
# def runHTTPDThread():
# 
# Path: Peach/agent.py
# class Monitor(object):
#     """
#     Extend from this to implement a Monitor.
#     Monitors are run by an Agent and must operate in an async manner.
#     Any blocking tasks must be performed in another thread.
# 
#     Agent: onTestStarting()
#     Agent: onTestFinished()
#     Agent: redoTest()
#     Agent: Sending redoTest result [False]
#     Agent: detectFault()
#     Agent: Detected fault!
#     Agent: Sending detectFault result [True]
#     Agent: getMonitorData()
#     Agent: onFault()
#     Agent: stopRun()
#     Agent: onShutdown()
#     """
# 
#     def __init__(self, args):
#         """
#         Arguments are supplied via the Peach XML file.
# 
#         @type	args: Dictionary
#         @param	args: Dictionary of parameters
#         """
#         self._name = None
# 
#     def OnTestStarting(self):
#         """Called right before start of test case or variation."""
#         pass
# 
#     def OnTestFinished(self):
#         """Called right after a test case or variation."""
#         pass
# 
#     def GetMonitorData(self):
#         """Get any monitored data from a test case."""
#         return None
# 
#     def RedoTest(self):
#         """Should the current test be re-performed."""
#         return False
# 
#     def DetectedFault(self):
#         """Check if a fault was detected."""
#         return False
# 
#     def OnFault(self):
#         """Called when a fault was detected."""
#         pass
# 
#     def OnShutdown(self):
#         """Called when Agent is shutting down, typically at end of a test run or when a Stop-Run occurs."""
#         pass
# 
#     def StopRun(self):
#         """Return True to force test run to fail. This should return True if an unrecoverable error occurs."""
#         return False
# 
#     def PublisherCall(self, method):
#         """Called when a call action is being performed.
#         Call actions are used to launch programs, this gives the monitor a chance to determine if it should be
#         running the program under a debugger instead. Note: This is a bit of a hack to get this working.
#         """
#         pass
# 
# def MonitorDebug(monitor, msg):
#     print("Monitor[%s]: %s" % (monitor, highlight.info(msg)))
# 
# Path: Peach/Utilities/Gaia/gaia.py
# class LockScreen(object):
# class GaiaApp(object):
# class GaiaApps(object):
# class GaiaDevice(object):
#     def __init__(self, marionette):
#     def is_locked(self):
#     def unlock(self):
#     def __init__(self, origin=None, name=None, frame=None, src=None):
#     def __init__(self, marionette):
#     def get_permission(self, app_name, permission_name):
#     def set_permission(self, app_name, permission_name, value):
#     def launch(self, name, switch_to_frame=True, url=None):
#     def uninstall(self, name):
#     def kill(self, app):
#     def kill_all(self):
#     def runningApps(self):
#     def switch_to_frame(self, app_frame, url=None, timeout=30):
#             def check(now):
#             def check(now):
#     def __init__(self, marionette):
#     def manager(self):
#     def is_android_build(self):
#     def push_file(self, source, count=1, destination='', progress=None):
#     def restart_b2g(self):
#     def start_b2g(self):
#     def stop_b2g(self):


import os
import sys
import time
import subprocess
from Peach.Utilities import ADB, network
from Peach.agent import Monitor, MonitorDebug
    from marionette import Marionette
from Peach.Utilities.Gaia import gaia
            raise Exception("No publisher URL provided.")

        if args.has_key("EmulatorScript"):
            self.emulatorStartScript = str(args["EmulatorScript"]).replace("'''", "")
        else:
            raise Exception("No script provided to run the emulator.")

        if args.has_key("AppName"):
            self.appName = str(args["AppName"]).replace("'''", "")
        else:
            self.appName = "browser"

        if args.has_key("ScriptTimeout"):
            self.scriptTimeout = int(args["ScriptTimeout"]).replace("''", "")
        else:
            self.scriptTimeout = 600000

        if args.has_key("PortADB"):
            self.forwardedPortADB = int(args["PortADB"])
        else:
            self.forwardedPortADB = 2828

        self._name = "MarionetteEmulator"
        self.monitoringProcessId = -1
        self.monitoredProcessName = "/system/b2g/b2g"
        self.publisherHost = "10.0.2.2"
        self.publisherPort = network.runHTTPDThread()
        self.publisherURL = "http://%s:%d/%s" % (self.publisherHost, self.publisherPort, self.publisherRequestPath)
        self.isEmulatorInitialized = False
        self.isMonitorInitialized = False

# Path: Peach/Utilities/ADB.py
# class AccessDebugBridge(object):
#     def __init__(self, adbPath="adb", deviceSerial=None, isEmulator=False):
#     def verifyADB(self):
#     def verifyDevice(self):
#     def runCmd(self, args):
#     def checkCmd(self, args, timeout=None):
#     def getProcessList(self):
#     def killProcess(self, appname, forceKill=False):
#     def reboot(self, wait=False):
#     def getCurrentTime(self):
#     def getDeviceInformation(self, directive="all"):
#     def makeDeviceReport(self):
#     def makeBugReport(self):
#     def getPID(self, procName):
#     def getPIDs(self, procName):
#     def shell(self, command):
#     def command(self, command):
# 
# Path: Peach/Utilities/network.py
# def cleanupSocketProcesses():
# def getUnboundPort(host="", minRange=30000, maxRange=35000, socket_type=1, assignOnlyOnce=False):
# def runHTTPDThread():
# 
# Path: Peach/agent.py
# class Monitor(object):
#     """
#     Extend from this to implement a Monitor.
#     Monitors are run by an Agent and must operate in an async manner.
#     Any blocking tasks must be performed in another thread.
# 
#     Agent: onTestStarting()
#     Agent: onTestFinished()
#     Agent: redoTest()
#     Agent: Sending redoTest result [False]
#     Agent: detectFault()
#     Agent: Detected fault!
#     Agent: Sending detectFault result [True]
#     Agent: getMonitorData()
#     Agent: onFault()
#     Agent: stopRun()
#     Agent: onShutdown()
#     """
# 
#     def __init__(self, args):
#         """
#         Arguments are supplied via the Peach XML file.
# 
#         @type	args: Dictionary
#         @param	args: Dictionary of parameters
#         """
#         self._name = None
# 
#     def OnTestStarting(self):
#         """Called right before start of test case or variation."""
#         pass
# 
#     def OnTestFinished(self):
#         """Called right after a test case or variation."""
#         pass
# 
#     def GetMonitorData(self):
#         """Get any monitored data from a test case."""
#         return None
# 
#     def RedoTest(self):
#         """Should the current test be re-performed."""
#         return False
# 
#     def DetectedFault(self):
#         """Check if a fault was detected."""
#         return False
# 
#     def OnFault(self):
#         """Called when a fault was detected."""
#         pass
# 
#     def OnShutdown(self):
#         """Called when Agent is shutting down, typically at end of a test run or when a Stop-Run occurs."""
#         pass
# 
#     def StopRun(self):
#         """Return True to force test run to fail. This should return True if an unrecoverable error occurs."""
#         return False
# 
#     def PublisherCall(self, method):
#         """Called when a call action is being performed.
#         Call actions are used to launch programs, this gives the monitor a chance to determine if it should be
#         running the program under a debugger instead. Note: This is a bit of a hack to get this working.
#         """
#         pass
# 
# def MonitorDebug(monitor, msg):
#     print("Monitor[%s]: %s" % (monitor, highlight.info(msg)))
# 
# Path: Peach/Utilities/Gaia/gaia.py
# class LockScreen(object):
# class GaiaApp(object):
# class GaiaApps(object):
# class GaiaDevice(object):
#     def __init__(self, marionette):
#     def is_locked(self):
#     def unlock(self):
#     def __init__(self, origin=None, name=None, frame=None, src=None):
#     def __init__(self, marionette):
#     def get_permission(self, app_name, permission_name):
#     def set_permission(self, app_name, permission_name, value):
#     def launch(self, name, switch_to_frame=True, url=None):
#     def uninstall(self, name):
#     def kill(self, app):
#     def kill_all(self):
#     def runningApps(self):
#     def switch_to_frame(self, app_frame, url=None, timeout=30):
#             def check(now):
#             def check(now):
#     def __init__(self, marionette):
#     def manager(self):
#     def is_android_build(self):
#     def push_file(self, source, count=1, destination='', progress=None):
#     def restart_b2g(self):
#     def start_b2g(self):
#     def stop_b2g(self):


# Path: Peach/Agent/b2g.py
import os
import sys
import time
import subprocess
from Peach.Utilities import ADB, network
from Peach.agent import Monitor, MonitorDebug
    from marionette import Marionette
from Peach.Utilities.Gaia import gaia

            raise Exception("No publisher URL provided.")

        if args.has_key("EmulatorScript"):
            self.emulatorStartScript = str(args["EmulatorScript"]).replace("'''", "")
        else:
            raise Exception("No script provided to run the emulator.")

        if args.has_key("AppName"):
            self.appName = str(args["AppName"]).replace("'''", "")
        else:
            self.appName = "browser"

        if args.has_key("ScriptTimeout"):
            self.scriptTimeout = int(args["ScriptTimeout"]).replace("''", "")
        else:
            self.scriptTimeout = 600000

        if args.has_key("PortADB"):
            self.forwardedPortADB = int(args["PortADB"])
        else:
            self.forwardedPortADB = 2828

        self._name = "MarionetteEmulator"
        self.monitoringProcessId = -1
        self.monitoredProcessName = "/system/b2g/b2g"
        self.publisherHost = "10.0.2.2"
        self.publisherPort = network.runHTTPDThread()
        self.publisherURL = "http://%s:%d/%s" % (self.publisherHost, self.publisherPort, self.publisherRequestPath)
        self.isEmulatorInitialized = False
        self.isMonitorInitialized = False

        self.adb = ADB.AccessDebugBridge(isEmulator=True)