示例#1
0
文件: dt.py 项目: hellertang/QT4i
 def install(self, _file_path, _device_udid=None):
     '''通过udid指定真机安装IPA或模拟器安装APP(注意:真机所用IPA不能在模拟器上安装和使用,IPA与APP相互不兼容)
     
     :param _file_path: IPA或APP安装包的路径(注意:当前Mac机必须能访问到该路径)
     :type _file_path: str
     :param _device_udid: 设备的udid(当udid为None时,IPA包则安装到第一台连接上的真机上,APP包则安装到默认模拟器上)
     :type _device_udid: str
     :returns: bool
     '''
     self.install_error = ""
     from qt4i.driver.tools import logger
     log = logger.get_logger("task")
     
     if not _file_path:
         return True
     
     pkgcachedir = os.path.join(os.environ['HOME'],'pkg_cache')
     if not os.path.isdir(pkgcachedir):
         os.mkdir(pkgcachedir)
     pkgcachedir = os.path.join(pkgcachedir, str(_device_udid))
     file_path = self._prepare_package(_file_path, pkgcachedir)
     if os.path.exists(file_path) == False :
         self.install_error = 'file does not exist'
         return False
     if file_path.endswith("ipa"):
         if self.is_simulator(_device_udid):
             log.warn('Failed to install an ipa to a simulator.')
             return False
         ip = InstallationProxy(_device_udid)
         ret = ip.install(file_path)
         
     else:
         if not self.is_simulator(_device_udid):
             log.warn('Failed to install an app to a real device.')
             return False
         self.start_simulator(_device_udid)
         if _device_udid is None:
             _device_udid = "booted"
         ret = self._install_for_simulator(_device_udid, file_path)
     
     if ret[0]:
         if os.path.exists(pkgcachedir):
             shutil.rmtree(pkgcachedir)
     else:
         log.debug('install error: %s' % str(ret[1]))
     
     self.install_error = ret[1]
     return ret[0]
示例#2
0
文件: dt.py 项目: hellertang/QT4i
 def list_apps(self, udid, app_type): 
     '''获取设备上的app列表
     
     :param udid: 设备的udid
     :type udid: str 
     :param app_type: app的类型(user/system/all)
     :type app_type: str 
     :returns: list
     '''
     if self.is_simulator(udid):
         return self.list_apps_with_fbsimctl(udid, app_type)
     else:
         return InstallationProxy(udid).list_apps(app_type)
示例#3
0
文件: dt.py 项目: hellertang/QT4i
    def uninstall(self, _bundle_id, _device_udid=None):
        '''通过udid指定设备卸载指定bundle_id的APP
        
        :param _bundle_id: APP的bundle_id,例如:com.tencent.qq.dailybuild.test
        :type _bundle_id: str
        :param _device_udid: 设备的udid(当udid为None时,如果有真机连接,则卸载第一台连接上的真机内的APP,如果无真机连接,则卸载默认模拟器上的APP)
        :type _device_udid: str
        :returns: bool
        '''
        self.uninstall_error = ""
        simulator_flag = False
        if _device_udid:
            for device in self.get_devices():
                if _device_udid == device["udid"]:
                    simulator_flag = device["simulator"]
                    break
        else:
            devices = self.get_real_devices()
            if len(devices) > 0:
                _device_udid = devices[0]["udid"]
            else:
                devices = self.get_simulators()
                if len(devices) > 0:
                    _device_udid = devices[0]["udid"]
                    simulator_flag = True            

        if _device_udid is None:
            return False
        if simulator_flag:
            self.start_simulator(_device_udid)
            ret = self._uninstall_for_simulator(_device_udid, _bundle_id)
        else:
            ip = InstallationProxy(_device_udid)
            ret = ip.uninstall(_bundle_id)
        
        self.uninstall_error = ret[1]
        return ret[0] 
示例#4
0
 def list_apps(self, udid, app_type):
     '''获取设备上的app列表
     
     :param udid: 设备的udid
     :type udid: str 
     :param app_type: app的类型(user/system/all)
     :type app_type: str 
     :returns: list
     '''
     if self.is_simulator(udid):
         if self.compare_xcode_version("11.0") >= 0:
             self.start_simulator(udid)
             return self.list_apps_with_xcrun(udid, app_type)
         return self.list_apps_with_fbsimctl(udid, app_type)
     else:
         return InstallationProxy(udid).list_apps(app_type)