Пример #1
0
 def restart_host_driver(self, driver_type):
     socket.setdefaulttimeout(3)
     is_connected = False
     if sys.platform == 'darwin' and self._host_ip == '127.0.0.1':
         try:
             if driver_type == 'instruments':
                 subprocess.check_call('killall -9 instruments')
             xctestagent_path = os.path.join(os.path.expanduser('~'),
                                             'XCTestAgent')
             if driver_type == 'xctest' and not os.path.exists(
                     xctestagent_path):
                 unzip_agent_cmd = '%s setup' % self.qt4i_manage
                 subprocess.call(unzip_agent_cmd, shell=True)
             subprocess.call('%s restartdriver -t %s' %
                             (self.qt4i_manage, driver_type),
                             shell=True)
             self._driver = RPCClientProxy('/'.join(
                 [self.host_url, 'host/']),
                                           allow_none=True,
                                           encoding=ENCODING)
             is_connected = self._driver.echo()
         except:
             pass
     socket.setdefaulttimeout(None)
     return is_connected
Пример #2
0
 def __init__(self, host_ip, host_port):
     self._host_ip = host_ip
     self._host_url = 'http://%s:%s' % (host_ip, host_port)
     self._driver = RPCClientProxy('/'.join([self._host_url, 'host/']),
                                   allow_none=True,
                                   encoding=ENCODING)
     self._devices = None
Пример #3
0
 def __init__(self, host_url, device_udid):
     self._driver = RPCClientProxy('/'.join(
         [host_url, 'device', '%s/' % device_udid]),
                                   allow_none=True,
                                   encoding='utf-8')
     self.udid = device_udid
     self.devicelock = threading.RLock()
Пример #4
0
class HostDriver(object):
    '''设备主机的Driver
    '''
    def __init__(self, host_ip, host_port):
        self._host_ip = host_ip
        self._host_url = 'http://%s:%s' % (host_ip, host_port)
        self._driver = RPCClientProxy('/'.join([self._host_url, 'host/']),
                                      allow_none=True,
                                      encoding=ENCODING)
        self._devices = None
        self._qt4i_manage = None

    @property
    def host_url(self):
        return self._host_url

    @property
    def devices(self):
        return self._devices

    @property
    def qt4i_manage(self):
        if sys.platform == 'darwin':
            config_parser = ConfigParser.ConfigParser()
            settings_file = os.path.join(RESOURCE_PATH, 'uispy.conf')
            config_parser.read(settings_file)
            try:
                self._qt4i_manage = config_parser.get('uispy', 'qt4i-manage')
            except ConfigParser.NoOptionError:
                self._qt4i_manage = os.path.expanduser(
                    "~/Library/Python/2.7/bin/qt4i-manage")
                config_parser.set("uispy", "qt4i-manage", self._qt4i_manage)
                with open(settings_file, 'w') as fd:
                    config_parser.write(fd)
            return self._qt4i_manage
        else:
            raise Exception("Unsupported platform!")

    def connect_to_host(self, driver_type):
        socket.setdefaulttimeout(3)
        is_connected = False
        try:
            is_connected = self._driver.echo()
        except:
            is_connected = self.restart_host_driver(driver_type)
        finally:
            socket.setdefaulttimeout(None)
        return is_connected

    def restart_host_driver(self, driver_type):
        socket.setdefaulttimeout(3)
        is_connected = False
        if sys.platform == 'darwin' and self._host_ip == '127.0.0.1':
            try:
                if driver_type == 'instruments':
                    subprocess.check_call('killall -9 instruments')
                xctestagent_path = os.path.join(os.path.expanduser('~'),
                                                'XCTestAgent')
                if driver_type == 'xctest' and not os.path.exists(
                        xctestagent_path):
                    unzip_agent_cmd = '%s setup' % self.qt4i_manage
                    subprocess.call(unzip_agent_cmd, shell=True)
                subprocess.call('%s restartdriver -t %s' %
                                (self.qt4i_manage, driver_type),
                                shell=True)
                self._driver = RPCClientProxy('/'.join(
                    [self.host_url, 'host/']),
                                              allow_none=True,
                                              encoding=ENCODING)
                is_connected = self._driver.echo()
            except:
                pass
        socket.setdefaulttimeout(None)
        return is_connected

    def list_devices(self):
        self._devices = self._driver.list_devices()
        return self._devices

    def start_simulator(self, udid):
        self._driver.start_simulator(udid)
Пример #5
0
class HostDriver(object):
    '''设备主机的Driver
    '''
    def __init__(self, host_ip, host_port):
        self._host_ip = host_ip
        self._host_url = 'http://%s:%s' % (host_ip, host_port)
        self._driver = RPCClientProxy('/'.join([self._host_url, 'host/']),
                                      allow_none=True,
                                      encoding=ENCODING)
        self._devices = None

    @property
    def host_url(self):
        return self._host_url

    @property
    def devices(self):
        return self._devices

    def connect_to_host(self, driver_type):
        socket.setdefaulttimeout(3)
        is_connected = False
        try:
            is_connected = self._driver.echo()
        except:
            is_connected = self.restart_host_driver(driver_type)
        finally:
            socket.setdefaulttimeout(None)
        return is_connected

    def restart_host_driver(self, driver_type):
        socket.setdefaulttimeout(3)
        is_connected = False
        if sys.platform == 'darwin' and self._host_ip == '127.0.0.1':
            try:
                if driver_type == 'instruments':
                    subprocess.check_call('killall -9 instruments')
                xctestagent_path = os.path.join(os.path.expanduser('~'),
                                                'XCTestAgent')
                if driver_type == 'xctest' and not os.path.exists(
                        xctestagent_path):
                    unzip_agent_cmd = '%s setup' % QT4I_MANAGE
                    subprocess.call(unzip_agent_cmd, shell=True)
                subprocess.call('%s restartdriver -t %s' %
                                (QT4I_MANAGE, driver_type),
                                shell=True)
                self._driver = RPCClientProxy('/'.join(
                    [self.host_url, 'host/']),
                                              allow_none=True,
                                              encoding=ENCODING)
                is_connected = self._driver.echo()
            except:
                pass
        socket.setdefaulttimeout(None)
        return is_connected

    def list_devices(self):
        self._devices = self._driver.list_devices()
        return self._devices

    def start_simulator(self, udid):
        self._driver.start_simulator(udid)