当前位置: 首页>>代码示例>>Python>>正文


Python moznetwork.get_ip函数代码示例

本文整理汇总了Python中moznetwork.get_ip函数的典型用法代码示例。如果您正苦于以下问题:Python get_ip函数的具体用法?Python get_ip怎么用?Python get_ip使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了get_ip函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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:
                ipAddr = moznetwork.get_ip()
            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)
开发者ID:MichaelKohler,项目名称:gecko-dev,代码行数:28,代码来源:devicemanagerSUT.py

示例2: setup_hosts

    def setup_hosts(self):
        hostnames = ["web-platform.test",
                     "www.web-platform.test",
                     "www1.web-platform.test",
                     "www2.web-platform.test",
                     "xn--n8j6ds53lwwkrqhv28a.web-platform.test",
                     "xn--lve-6lad.web-platform.test"]

        host_ip = moznetwork.get_ip()

        temp_dir = tempfile.mkdtemp()
        hosts_path = os.path.join(temp_dir, "hosts")
        remote_path = "/system/etc/hosts"
        try:
            self.device.getFile("/system/etc/hosts", hosts_path)

            with open(hosts_path) as f:
                hosts_file = HostsFile.from_file(f)

            for canonical_hostname in hostnames:
                hosts_file.set_host(HostsLine(host_ip, canonical_hostname))

            with open(hosts_path, "w") as f:
                hosts_file.to_file(f)

            self.logger.info("Installing hosts file")

            self.device.remount()
            self.device.removeFile(remote_path)
            self.device.pushFile(hosts_path, remote_path)
        finally:
            os.unlink(hosts_path)
            os.rmdir(temp_dir)
开发者ID:html-shell,项目名称:mozbuild,代码行数:33,代码来源:b2g.py

示例3: check_server

def check_server(device):
    logger.info("Checking access to host machine")

    if _adbflag:
        return True

    routes = [("GET", "/", test_handler)]

    host_ip = moznetwork.get_ip()

    for port in [8000, 8001]:
        try:
            server = wptserve.WebTestHttpd(host=host_ip, port=port, routes=routes)
            server.start()
        except:
            logger.critical("Error starting local server on port %s:\n%s" %
                            (port, traceback.format_exc()))
            return False

        try:
            device.shell_output("curl http://%s:%i" % (host_ip, port))
        except mozdevice.ADBError as e:
            if 'curl: not found' in e.message:
                logger.warning("Could not check access to host machine: curl not present.")
                logger.warning("If timeouts occur, check your network configuration.")
                break
            logger.critical("Failed to connect to server running on host machine ip %s port %i. Check network configuration." % (host_ip, port))
            return False
        finally:
            logger.debug("Stopping server")
            server.stop()

    return True
开发者ID:JJTC-PX,项目名称:fxos-certsuite,代码行数:33,代码来源:harness.py

示例4: 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:
                ipAddr = moznetwork.get_ip()
            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)
开发者ID:MichaelKohler,项目名称:gecko-dev,代码行数:32,代码来源:devicemanagerSUT.py

示例5: 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."""
    zc = Zeroconf(moznetwork.get_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
开发者ID:kleopatra999,项目名称:system-addons,代码行数:26,代码来源:droid.py

示例6: get_ip

 def get_ip(self):
     import moznetwork
     if os.name != "nt":
         return moznetwork.get_ip()
     else:
         self.error(
             "ERROR: you must specify a --remote-webserver=<ip address>\n")
开发者ID:kitcambridge,项目名称:gecko-dev,代码行数:7,代码来源:reftestcommandline.py

示例7: verifyRemoteOptions

    def verifyRemoteOptions(self, options):
        if options.remoteWebServer == None:
            if os.name != "nt":
                options.remoteWebServer = moznetwork.get_ip()
            else:
                self.error("You must specify a --remote-webserver=<ip address>")
        options.webServer = options.remoteWebServer

        if options.geckoPath and not options.emulator:
            self.error("You must specify --emulator if you specify --gecko-path")

        if options.logcat_dir and not options.emulator:
            self.error("You must specify --emulator if you specify --logcat-dir")

        if not os.path.isdir(options.xrePath):
            self.error("--xre-path '%s' is not a directory" % options.xrePath)
        xpcshell = os.path.join(options.xrePath, 'xpcshell')
        if not os.access(xpcshell, os.F_OK):
            self.error('xpcshell not found at %s' % xpcshell)
        if self.elf_arm(xpcshell):
            self.error('--xre-path points to an ARM version of xpcshell; it '
                       'should instead point to a version that can run on '
                       'your desktop')

        if options.pidFile != "":
            f = open(options.pidFile, 'w')
            f.write("%s" % os.getpid())
            f.close()

        return options
开发者ID:drexler,项目名称:releases-mozilla-aurora,代码行数:30,代码来源:mochitest_options.py

示例8: synchronizeTime

    def synchronizeTime(self):
        self._logger.info("Synchronizing time...")
        ntpdate_wait_time = 5
        ntpdate_retries = 5
        num_retries = 0
        synced_time = False
        while not synced_time:
            try:
                self.shellCheckOutput([self.DEFAULT_NTPDATE_LOCATION, "-c", "1", "-d",
                                       "-h", moznetwork.get_ip(), "-s"], root=True,
                                      timeout=ntpdate_wait_time)
                synced_time = True
            except mozdevice.DMError:
                # HACK: we need to force a reconnection here on SUT (until bug
                # 1009862 is fixed and lands in a released version of
                # mozdevice)
                self._sock = None
                if num_retries == ntpdate_retries:
                    raise Exception("Exceeded maximum number of retries "
                                    "synchronizing time!")

                # FIXME: as of this writing mozdevice doesn't distinguishing
                # between timeouts and other errors (bug 1010328), so we're
                # just gonna assume timeout
                num_retries+=1
                self._logger.info("Attempt to synchronize time failed, "
                                  "retrying (try %s/%s)..." % (num_retries,
                                                               ntpdate_retries))
        self._logger.info("Time synchronized!")
开发者ID:retornam,项目名称:eideticker,代码行数:29,代码来源:device.py

示例9: create_httpd

 def create_httpd(self, need_external_ip):
     host = "127.0.0.1"
     if need_external_ip:
         host = moznetwork.get_ip()
     root = self.server_root or os.path.join(os.path.dirname(here), "www")
     rv = httpd.FixtureServer(root, host=host)
     rv.start()
     return rv
开发者ID:emilio,项目名称:gecko-dev,代码行数:8,代码来源:base.py

示例10: validate

    def validate(self, parser, options, context):
        """Validate b2g options."""

        if options.remoteWebServer is None:
            if os.name != "nt":
                options.remoteWebServer = moznetwork.get_ip()
            else:
                parser.error(
                    "You must specify a --remote-webserver=<ip address>")
        options.webServer = options.remoteWebServer

        if not options.b2gPath and hasattr(context, 'b2g_home'):
            options.b2gPath = context.b2g_home

        if hasattr(context, 'device_name') and not options.emulator:
            if context.device_name.startswith('emulator'):
                options.emulator = 'x86' if 'x86' in context.device_name else 'arm'

        if options.geckoPath and not options.emulator:
            parser.error(
                "You must specify --emulator if you specify --gecko-path")

        if options.logdir and not options.emulator:
            parser.error("You must specify --emulator if you specify --logdir")
        elif not options.logdir and options.emulator and build_obj:
            options.logdir = os.path.join(
                build_obj.topobjdir, '_tests', 'testing', 'mochitest')

        if hasattr(context, 'xre_path'):
            options.xrePath = context.xre_path

        if not os.path.isdir(options.xrePath):
            parser.error("--xre-path '%s' is not a directory" % options.xrePath)

        xpcshell = os.path.join(options.xrePath, 'xpcshell')
        if not os.access(xpcshell, os.F_OK):
            parser.error('xpcshell not found at %s' % xpcshell)

        if self.elf_arm(xpcshell):
            parser.error('--xre-path points to an ARM version of xpcshell; it '
                         'should instead point to a version that can run on '
                         'your desktop')

        if not options.httpdPath and build_obj:
            options.httpdPath = os.path.join(
                build_obj.topobjdir, '_tests', 'testing', 'mochitest')

        # Bug 1071866 - B2G Mochitests do not always produce a leak log.
        options.ignoreMissingLeaks.append("default")
        # Bug 1070068 - Leak logging does not work for tab processes on B2G.
        options.ignoreMissingLeaks.append("tab")

        if options.pidFile != "":
            f = open(options.pidFile, 'w')
            f.write("%s" % os.getpid())
            f.close()

        return options
开发者ID:brendandahl,项目名称:positron,代码行数:58,代码来源:mochitest_options.py

示例11: test_get_ip_using_get_interface

def test_get_ip_using_get_interface(ip_addresses):
    """ Test that the control flow path for get_ip() using
    _get_interface_list() is works """

    if mozinfo.isLinux or mozinfo.isMac:

        with mock.patch('socket.gethostbyname') as byname:
            # Force socket.gethostbyname to return None
            byname.return_value = None
            assert moznetwork.get_ip() in ip_addresses
开发者ID:luke-chang,项目名称:gecko-1,代码行数:10,代码来源:test.py

示例12: run_capture

def run_capture(options, capture_file):
    device_prefs = eideticker.getDevicePrefs(options)

    capture_server = CaptureServer(capture_file, options.capture_device,
                                   options.mode,
                                   no_capture=options.no_capture)
    host = moznetwork.get_ip()
    docroot = eideticker.runtest.TEST_DIR
    httpd = mozhttpd.MozHttpd(port=0, host=host, docroot=docroot, urlhandlers=[
        {'method': 'GET',
         'path': '/api/captures/start/?',
         'function': capture_server.start_capture},
        {'method': 'GET',
         'path': '/api/captures/end/?',
         'function': capture_server.end_capture}])
    httpd.start(block=False)
    print "Serving '%s' at %s:%s" % (
        httpd.docroot, httpd.host, httpd.httpd.server_port)

    device = eideticker.getDevice(**device_prefs)
    mode = options.mode
    if not mode:
        mode = device.hdmiResolution

    url = "http://%s:%s/getdimensions.html" % (host, httpd.httpd.server_port)

    device.executeCommand("tap", [100, 100])
    if device_prefs['devicetype'] == 'android':
        device.launchFennec(options.appname, url=url)
    else:
        if not options.wifi_settings_file:
            print "WIFI settings file (see --help) required for B2G!"
            sys.exit(1)
        device.restartB2G()
        device.connectWIFI(json.loads(open(options.wifi_settings_file).read()))
        session = device.marionette.session
        if 'b2g' not in session:
            raise Exception("bad session value %s returned by start_session" %
                            session)

        device.unlock()
        # wait for device to become ready (yes, this is terrible, can we
        # detect this condition in marionette somehow?)
        time.sleep(5)
        device.marionette.execute_script("window.location.href='%s';" % url)

    while not capture_server.finished:
        time.sleep(0.25)

    capture_server.convert_capture()

    device.killProcess(options.appname)
    httpd.stop()
开发者ID:William-Hsu,项目名称:eideticker,代码行数:53,代码来源:getdimensions.py

示例13: write_hosts_file

def write_hosts_file(config, device):
    new_hosts = make_hosts_file(config, moznetwork.get_ip())
    current_hosts = device.get_file("/etc/hosts")
    if new_hosts == current_hosts:
        return
    hosts_fd, hosts_path = tempfile.mkstemp()
    try:
        with os.fdopen(hosts_fd, "w") as f:
            f.write(new_hosts)
        device.remount()
        device.push(hosts_path, "/etc/hosts")
    finally:
        os.remove(hosts_path)
开发者ID:mnot,项目名称:web-platform-tests,代码行数:13,代码来源:fennec.py

示例14: __init__

    def __init__(self, testinfo, options, device, capture_controller, use_actions=True):
        Test.__init__(self, testinfo, options, device, capture_controller,
                      track_start_frame=True, track_end_frame=True)

        # get actions for web tests
        actions_path = os.path.join(testinfo['here'], "actions.json")
        if use_actions:
            if os.path.exists(actions_path):
                self.actions = json.loads(open(actions_path).read())
            else:
                raise TestException("Test needs actions but no actions file '%s'" %
                                    actions_path)
        else:
            self.actions = None

        self.capture_server = CaptureServer(self)
        self.host = moznetwork.get_ip()
        self.http = mozhttpd.MozHttpd(
            docroot=TEST_DIR, host=self.host, port=0, log_requests=True,
            urlhandlers=[
                {'method': 'GET',
                 'path': '/api/captures/start/?',
                 'function': self.capture_server.start_capture},
                {'method': 'GET',
                 'path': '/api/captures/end/?',
                 'function': self.capture_server.end_capture},
                {'method': 'POST',
                 'path': '/api/captures/input/?',
                 'function': self.capture_server.input}])
        self.http.start(block=False)

        connected = False
        tries = 0
        while not connected and tries < 20:
            tries += 1
            import socket
            s = socket.socket()
            try:
                s.connect((self.host, self.http.httpd.server_port))
                connected = True
            except Exception:
                self.logger.info("Can't connect to %s:%s, retrying..." %
                                 (self.host, self.http.httpd.server_port))

        self.logger.info("Test URL is: %s" % self.url)

        if not connected:
            raise "Could not open webserver. Error!"
开发者ID:wlach,项目名称:eideticker,代码行数:48,代码来源:test.py

示例15: setup_hosts

    def setup_hosts(self):
        hosts = ["web-platform.test",
                 "www.web-platform.test",
                 "www1.web-platform.test",
                 "www2.web-platform.test",
                 "xn--n8j6ds53lwwkrqhv28a.web-platform.test",
                 "xn--lve-6lad.web-platform.test"]

        host_ip = moznetwork.get_ip()

        temp_dir = tempfile.mkdtemp()
        hosts_path = os.path.join(temp_dir, "hosts")
        remote_path = "/system/etc/hosts"
        try:
            self.device.getFile("/system/etc/hosts", hosts_path)

            with open(hosts_path, "a+") as f:
                hosts_present = set()
                for line in f:
                    line = line.strip()
                    if not line:
                        continue
                    ip, host = line.split()
                    hosts_present.add(host)

                    if host in hosts and ip != host_ip:
                        raise Exception("Existing hosts file has an ip for %s" % host)

                f.seek(f.tell() - 1)
                if f.read() != "\n":
                    f.write("\n")

                for host in hosts:
                    f.write("%s%s%s\n" % (host_ip, " " * (28 - len(host_ip)), host))

            self.logger.info("Installing hosts file")

            self.device.remount()
            self.device.removeFile(remote_path)
            self.device.pushFile(hosts_path, remote_path)
        finally:
            os.unlink(hosts_path)
            os.rmdir(temp_dir)
开发者ID:kleopatra999,项目名称:wptrunner,代码行数:43,代码来源:b2g.py


注:本文中的moznetwork.get_ip函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。