def update_ios(cookies, **kw): if not sys.platform.startswith('darwin'): raise Exception("iOS inspector can only be used on OS X.") previous_path = _update_target('ios-inspector', cookies=cookies) current_path = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..', 'inspector', 'ios-inspector')) # If we're updating copy the module source from the previous inspector if previous_path is not None: shutil.rmtree(os.path.join(current_path, 'ForgeModule')) shutil.copytree(os.path.join(previous_path, 'ForgeModule'), os.path.join(current_path, 'ForgeModule')) else: # Prepare example module code with open(os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..', 'module', 'manifest.json'))) as manifest_file: manifest = json.load(manifest_file) module_name = str(manifest['name']) for root, dirnames, filenames in os.walk(os.path.join(current_path, 'ForgeModule')): for filename in filenames: with open(os.path.join(root, filename), 'r') as source: lines = source.readlines() if 'templatemodule' in filename: os.remove(os.path.join(root, filename)) with open(os.path.join(root, filename.replace('templatemodule', module_name)), 'w') as output: for line in lines: output.write(line.replace('templatemodule', module_name)) # Update inspector with module specific build details try: build.apply_module_to_ios_project(os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..', 'module')), current_path, skip_a=True, inspector_config=True, include_tests=True, local_build_steps=os.path.join(current_path, 'ForgeInspector', 'assets', 'src')) except Exception: shutil.rmtree(current_path) try: raise #raise Exception("Applying build steps failed, check build steps and re-update inspector: %s" % e) finally: try: shutil.move(previous_path, current_path) except Exception: pass # Create hash for inspector with open(os.path.join(current_path, '.hash'), 'w') as hash_file: hash_file.write(hash_ios())
def update_ios(cookies, **kw): if not sys.platform.startswith('darwin'): raise Exception("iOS inspector can only be used on OS X.") previous_path = _update_target('ios-inspector', cookies=cookies) current_path = os.path.abspath( os.path.join(os.path.dirname(__file__), '..', '..', 'inspector', 'ios-inspector')) # If we're updating copy the module source from the previous inspector if previous_path is not None: shutil.rmtree(os.path.join(current_path, 'ForgeModule')) shutil.copytree(os.path.join(previous_path, 'ForgeModule'), os.path.join(current_path, 'ForgeModule')) else: # Prepare example module code with open( os.path.abspath( os.path.join(os.path.dirname(__file__), '..', '..', 'module', 'manifest.json'))) as manifest_file: manifest = json.load(manifest_file) module_name = str(manifest['name']) for root, dirnames, filenames in os.walk( os.path.join(current_path, 'ForgeModule')): for filename in filenames: with open(os.path.join(root, filename), 'r') as source: lines = source.readlines() if 'templatemodule' in filename: os.remove(os.path.join(root, filename)) with open( os.path.join( root, filename.replace('templatemodule', module_name)), 'w') as output: for line in lines: output.write( line.replace('templatemodule', module_name)) # Update inspector with module specific build details try: build.apply_module_to_ios_project(os.path.abspath( os.path.join(os.path.dirname(__file__), '..', '..', 'module')), current_path, skip_a=True, inspector_config=True, include_tests=True, local_build_steps=os.path.join( current_path, 'ForgeInspector', 'assets', 'src')) except Exception: shutil.rmtree(current_path) try: raise #raise Exception("Applying build steps failed, check build steps and re-update inspector: %s" % e) finally: try: shutil.move(previous_path, current_path) except Exception: pass # Create hash for inspector with open(os.path.join(current_path, '.hash'), 'w') as hash_file: hash_file.write(hash_ios())
def update_ios(cookies, dependencies, **kw): if not sys.platform.startswith('darwin'): raise Exception("iOS inspector can only be used on OS X.") previous_path = _update_target('ios-inspector', cookies=cookies) current_path = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..', 'inspector', 'ios-inspector')) with open(os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..', 'module', 'manifest.json'))) as manifest_file: manifest = json.load(manifest_file) if os.path.exists(os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..', 'module', 'identity.json'))): with open(os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..', 'module', 'identity.json'))) as identity_file: this_module_name = str(json.load(identity_file)['name']) else: this_module_name = str(manifest['name']) if 'namespace' in manifest: namespace = str(manifest['namespace']) else: namespace = this_module_name module_mapping = { 'inspector': 'inspector', namespace: this_module_name } # If we're updating copy the module source from the previous inspector if previous_path is not None: shutil.rmtree(os.path.join(current_path, 'ForgeModule')) shutil.copytree(os.path.join(previous_path, 'ForgeModule'), os.path.join(current_path, 'ForgeModule')) else: # Prepare example module code for root, dirnames, filenames in os.walk(os.path.join(current_path, 'ForgeModule')): for filename in filenames: with open(os.path.join(root, filename), 'r') as source: lines = source.readlines() if 'templatemodule' in filename: os.remove(os.path.join(root, filename)) with open(os.path.join(root, filename.replace('templatemodule', namespace)), 'w') as output: for line in lines: output.write(line.replace('templatemodule', namespace)) if os.path.exists(os.path.join(current_path, 'ForgeModule', 'forge_headers')): shutil.rmtree(os.path.join(current_path, 'ForgeModule', 'forge_headers')) # Include inspector_config.json in app_config.json/app_config.js inspector_config, app_config = _include_inspector_config_in_app_config(this_module_name, manifest['version'], current_path) # Dependencies if os.path.exists(os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..', 'module', 'inspector_config.json'))): cache_path = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', 'cache')) if "modules" in inspector_config: for module, details in inspector_config["modules"].items(): if details.get("disabled", False): continue version = details["version"] cached_version_path = os.path.join(cache_path, "%s-%s.zip" % (module, version)) if not os.path.exists(cached_version_path): # Do this import here so we can run without the toolkit from trigger import forge_tool forge_tool.singleton.remote._get_file(dependencies["%s-%s" % (module, version)], cached_version_path) with zipfile.ZipFile(cached_version_path) as module_zip: module_zip.extractall(os.path.join(cache_path, "%s-%s" % (module, version))) # Add to module_mapping manifest_path = os.path.join(cache_path, "%s-%s" % (module, version), 'manifest.json') with open(manifest_path) as manifest_file: module_manifest = json.load(manifest_file) if 'namespace' in module_manifest: module_namespace = module_manifest['namespace'] else: module_namespace = module module_mapping[module_namespace] = module build.apply_module_to_ios_project( os.path.join(cache_path, "%s-%s" % (module, version)), current_path, app_config=app_config, skip_a=False, include_tests=False, local_build_steps=os.path.join(current_path, 'ForgeInspector', 'assets', 'src') ) # Update inspector with module specific build details try: build.apply_module_to_ios_project( os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..', 'module')), current_path, app_config=app_config, skip_a=True, include_tests=True, local_build_steps=os.path.join(current_path, 'ForgeInspector', 'assets', 'src') ) except Exception: shutil.rmtree(current_path) try: raise #raise Exception("Applying build steps failed, check build steps and re-update inspector: %s" % e) finally: try: shutil.move(previous_path, current_path) except Exception: pass with open(os.path.join(current_path, 'ForgeInspector', 'assets', 'module_mapping.json'), 'w') as module_mapping_file: json.dump(module_mapping, module_mapping_file) with open(os.path.join(current_path, 'ForgeInspector', 'assets', 'app_config.json')) as app_config_json: app_config = json.load(app_config_json) with open(os.path.join(current_path, 'ForgeInspector', 'assets', 'forge', 'app_config.js'), 'w') as app_config_js: app_config_js.write("window.forge = {}; window.forge.config = %s; window.forge.module_mapping = %s;" % (json.dumps(app_config), json.dumps(module_mapping))) # Create hash for inspector with open(os.path.join(current_path, '.hash'), 'w') as hash_file: hash_file.write(hash_ios())