def _init_fbsimctl(self): try: fbsimctl_zip = pkg_resources.resource_filename("qt4i", "driver/tools/fbsimctl/fbsimctl.zip") #@UndefinedVariable if not os.path.exists(fbsimctl_zip): raise Exception('fbsimctl not found') self.fbsimctl = DT.FBSIMCTL_DEFAULT_PATH except: try: os.environ['PATH'] += ':/usr/local/bin' result = subprocess.check_output("which fbsimctl", env=os.environ, shell=True, stderr=subprocess.STDOUT, ) if PY3: result = result.decode() self.fbsimctl = result.split('\n')[0] except subprocess.CalledProcessError: raise Exception('fbsimctl not found, use brew install') if self.fbsimctl == DT.FBSIMCTL_DEFAULT_PATH and not os.path.exists(self.fbsimctl): # 解压fbsimctl到默认路径 fbsimctl_root_path = os.path.split(DT.FBSIMCTL_DEFAULT_PATH)[0] zip_decompress(fbsimctl_zip, fbsimctl_root_path) os.chmod(self.fbsimctl, 0o755) fbsimctl_fmk_path = os.path.split(DT.FBSIMCTL_DEFAULT_PATH)[0] for root, dirs, _files in os.walk(fbsimctl_fmk_path): if root.endswith('.framework'): if 'Headers' not in dirs: # 为Framework添加Headers/Modules/Resources的外链 framework_name = os.path.splitext(os.path.basename(root))[0] for item in ['Headers', 'Modules', 'Resources', framework_name]: item_path = os.path.join(root, item) if os.path.exists(item_path) and not os.path.islink(item_path): os.remove(item_path) os.symlink('Versions/Current/%s' % item, item_path) if root.endswith('Versions'): if 'Current' not in dirs: current_path = os.path.join(root, 'Current') if os.path.exists(current_path) and not os.path.islink(current_path): os.remove(current_path) os.symlink('A', current_path)
def execute(self, args): '''执行过程 ''' egg_file = os.path.join(os.path.dirname(os.path.dirname(__file__))) proj_dir = os.path.join(os.path.expanduser('~'), 'XCTestAgent') is_updated = False if zipfile.is_zipfile(egg_file): zip_decompress(egg_file, '/tmp') agent_src_path = '/tmp/qt4i/driver/xctest/xctestproj/XCTestAgent' else: qt4i_path = os.path.dirname(__file__) agent_src_path = os.path.join(qt4i_path, 'driver/xctest/xctestproj/XCTestAgent') if os.path.exists(proj_dir): with open(os.path.join(proj_dir, 'version.txt'), 'r') as f: version = f.read() if not less_to(version, qt4i_version): return else: lib_dir = os.path.join(proj_dir, 'third') shutil.rmtree(lib_dir) lib_src_path = os.path.join(agent_src_path, 'third') shutil.copytree(lib_src_path, lib_dir) is_updated = True else: shutil.copytree(agent_src_path, proj_dir) proj_path = os.path.join(proj_dir, 'XCTestAgent.xcodeproj') os.popen('open %s' % proj_path) is_updated = True if is_updated: with open(os.path.join(proj_dir, 'version.txt'), 'w') as f: f.write(qt4i_version) if os.path.exists('/tmp/qt4i'): shutil.rmtree('/tmp/qt4i')
def execute(self, args): '''执行过程 ''' egg_file = os.path.join(os.path.dirname(os.path.dirname(__file__))) agent_src_path = "" if zipfile.is_zipfile(egg_file): zip_decompress(egg_file, '/tmp') agent_src_path = '/tmp/qt4i/driver/xctest/xctestproj/XCTestAgent' else: qt4i_path = os.path.dirname(__file__) agent_src_path = os.path.join(qt4i_path, 'driver/xctest/xctestproj/XCTestAgent') proj_dir = os.path.join(os.path.expanduser('~'), 'XCTestAgent') if os.path.exists(proj_dir): shutil.rmtree(proj_dir) shutil.copytree(agent_src_path, proj_dir) proj_path = os.path.join(proj_dir, 'XCTestAgent.xcodeproj') os.popen('open %s' % proj_path) with open(os.path.join(proj_dir, 'version.txt'), 'w') as f: f.write(qt4i_version) if os.path.exists('/tmp/qt4i'): shutil.rmtree('/tmp/qt4i')
def _extract_zip(self, filepath, dstpath): '''解压zip包 :param filepath: zip包路径 :type filepath: string :param dstpath: 解压后路径 :type dstpath: string ''' items = os.listdir(dstpath) #首先删除目录中已有的app文件,防止版本冲突 for it in items: if it.endswith('.app'): shutil.rmtree(os.path.join(dstpath, it)) zip_decompress(filepath, dstpath) items = os.listdir(dstpath) for it in items: if it.endswith('.app'): return os.path.join(dstpath, it)