def handle_file(pbxfilename, parsertype='normal'): try: with open(bytestr(pbxfilename), 'rb') as f: xcodeproj = f.read() t0 = time.time() root, parseinfo = xcodeprojer.parse(xcodeproj, dictionarytype=dict, parsertype=parsertype) buf = StringIO() xcodeprojer.report_parse_status(root, parseinfo, filename=pbxfilename, fp=buf) if root is None: return LintResult(pbxfilename, False, buf.getvalue(), 0, 0, len(xcodeproj)) t1 = time.time() projname = xcodeprojer.projectname_for_path(pbxfilename) text = xcodeprojer.unparse(root, format='xcode', projectname=projname, parseinfo=parseinfo) t2 = time.time() return LintResult(pbxfilename, True, text, t1 - t0, t2 - t1, len(xcodeproj)) except Exception as e: e.traceback = traceback.format_exc() raise
def gidtable(filename): with open(filename, 'rb') as f: xcodeproj = f.read() root, parseinfo = xcodeprojer.parse(xcodeproj) if root is not None: unparser = xcodeprojer.Unparser(root) # We don't need the parse tree, only access to the gidcomments # that are built during the unparse. _ = unparser.unparse(root, projectname=xcodeprojer.projectname_for_path(filename)) gidcomments = unparser.gidcomments c = '.' else: gidcomments = {} c = 'X' sys.stdout.write(c) sys.stdout.flush() return filename, gidcomments
def handle_file(pbxfilename, parsertype='normal'): try: with open(bytestr(pbxfilename), 'rb') as f: xcodeproj = f.read() t0 = time.time() root, parseinfo = xcodeprojer.parse(xcodeproj, dictionarytype=dict, parsertype=parsertype) buf = StringIO() xcodeprojer.report_parse_status(root, parseinfo, filename=pbxfilename, fp=buf) if root is None: return LintResult(pbxfilename, False, buf.getvalue(), 0, 0, len(xcodeproj)) t1 = time.time() projname = xcodeprojer.projectname_for_path(pbxfilename) text = xcodeprojer.unparse(root, format='xcode', projectname=projname, parseinfo=parseinfo) t2 = time.time() return LintResult(pbxfilename, True, text, t1-t0, t2-t1, len(xcodeproj)) except Exception as e: e.traceback = traceback.format_exc() raise
def main(): filename = rel(INTL_PROJECT_FILENAME) with open(filename, 'rb') as f: xcodeproj = f.read() root, parseinfo = xcodeprojer.parse(xcodeproj, format='xcode') xcodeprojer.report_parse_status(root, parseinfo, filename=filename) if root is None: return PARSING_FAILED gen = xcodeprojer.UniqueXcodeIDGenerator() pbxproject = find_first(root, 'PBXProject') firsttarget = getobj(root, pbxproject['targets'][0]) # Construct a new buildphase as any other JSON object newbuildphase = {'isa': 'PBXShellScriptBuildPhase', 'buildActionMask': '2147483647', 'files': [], 'inputPaths': [], 'outputPaths': [], 'runOnlyForDeploymentPostprocessing': '0', 'shellPath': '/bin/sh', 'shellScript': "echo 'A new buildphase says hi!'"} id_newbuildphase = gen.generate() root['objects'][id_newbuildphase] = newbuildphase firsttarget['buildPhases'].insert(0, id_newbuildphase) projectname = xcodeprojer.projectname_for_path(filename) proj = xcodeprojer.unparse(root, format='xcode', projectname=projectname, parseinfo=parseinfo) with open(filename, 'wb') as f: f.write(proj) xcodeprojer.print_diff(xcodeproj, proj, filename=filename) return OK
def check_all_parsers(pbxdata, expected, desc, a, b): pbxfilename, data = pbxdata ret = parsable_variation(pbxdata, expected, desc, a, b) moddata = safe_replace(data, a, b) for parsertype in 'fast', 'classic': root, parseinfo = xcodeprojer.parse(moddata, format='xcode', parsertype=parsertype) if ret == 0: # Xcode parsed this. So if our parsers have anything to report, now is the time. xcodeprojer.report_parse_status(root, parseinfo, filename=pbxfilename) if root is None: print( "Error: parsertype %s failed where Xcode succeeded:\n %s: %r %r" % (parsertype, desc, a, b)) else: if root is not None: print( "Warning: parsertype %s succeeded where Xcode failed:\n %s: %r %r" % (parsertype, desc, a, b)) flush()
def parse(prj, report=True, fp=None, **kwargs): root, parseinfo = xcodeprojer.parse(prj, **kwargs) if report: xcodeprojer.report_parse_status(root, parseinfo, filename=None, fp=fp) return root, parseinfo
def create_project(interface, dest, name=None, version="1.0"): """ Copies the prototype project to `dest`, which must not already exists. Renames the Xcode project to `name`.xcodeproj. """ if name is None: name = os.path.basename(dest) if version is None: return shortname = re.sub(r'[^-_A-Za-z0-9]', '', name) if os.path.exists(dest): interface.fail("{} already exists. If you would like to create an new project, please move the existing project out of the way.".format(dest)) prototype = os.path.join(RENIOS, "prototype") interface.info("Copying prototype project...") shutil.copytree(prototype, dest) interface.info("Updating project with new name...") # Update the Xcode project. def rm(name): path = os.path.join(dest, name) if os.path.isdir(path): shutil.rmtree(path) elif os.path.exists(path): os.unlink(path) rm("base") rm("prototype.xcodeproj/project.xcworkspace") rm("prototype.xcodeproj/xcuserdata") os.rename(os.path.join(dest, "prototype.xcodeproj"), os.path.join(dest, name + ".xcodeproj")) pbxproj = os.path.join(dest, name + ".xcodeproj", "project.pbxproj") with open(pbxproj, "r") as f: root, _parseinfo = xcodeprojer.parse(f.read()) root = replace_name(root, "XHTE5H7Z79", "TEAMID") root = replace_name(root, "org.renpy.prototype", "com.domain." + shortname) root = replace_name(root, "prototype", name) output = xcodeprojer.unparse(root, format="xcode", projectname=name) with open(pbxproj + ".new", "w") as f: f.write(output) try: os.unlink(pbxproj) except: pass os.rename(pbxproj + ".new", pbxproj) plist = dict( CFBundleDevelopmentRegion="en", CFBundleDisplayName="$(PRODUCT_NAME)", CFBundleExecutable="$(EXECUTABLE_NAME)", CFBundleIdentifier="$(PRODUCT_BUNDLE_IDENTIFIER)", CFBundleInfoDictionaryVersion="6.0", CFBundleName="$(PRODUCT_NAME)", CFBundlePackageType="APPL", CFBundleShortVersionString=version, CFBundleSignature="????", CFBundleVersion=1, LSRequiresIPhoneOS=True, UIRequiresFullScreen=True, UIStatusBarHidden=True, UISupportedInterfaceOrientations=[ "UIInterfaceOrientationLandscapeRight", "UIInterfaceOrientationLandscapeLeft", ] ) plistlib.writePlist(plist, os.path.join(dest, "Info.plist")) interface.success("Created the Xcode project.")
def create_project(interface, dest, name=None, version="1.0"): """ Copies the prototype project to `dest`, which must not already exists. Renames the Xcode project to `name`.xcodeproj. """ if name is None: name = os.path.basename(dest) if version is None: return shortname = re.sub(r'[^-_A-Za-z0-9]', '', name) if os.path.exists(dest): interface.fail( "{} already exists. If you would like to create an new project, please move the existing project out of the way." .format(dest)) prototype = os.path.join(RENIOS, "prototype") interface.info("Copying prototype project...") shutil.copytree(prototype, dest) interface.info("Updating project with new name...") # Update the Xcode project. def rm(name): path = os.path.join(dest, name) if os.path.isdir(path): shutil.rmtree(path) elif os.path.exists(path): os.unlink(path) rm("base") rm("prototype.xcodeproj/project.xcworkspace") rm("prototype.xcodeproj/xcuserdata") os.rename(os.path.join(dest, "prototype.xcodeproj"), os.path.join(dest, name + ".xcodeproj")) pbxproj = os.path.join(dest, name + ".xcodeproj", "project.pbxproj") with open(pbxproj, "r") as f: root, _parseinfo = xcodeprojer.parse(f.read()) root = replace_name(root, "XHTE5H7Z79", "TEAMID") root = replace_name(root, "org.renpy.prototype", "com.domain." + shortname) root = replace_name(root, "prototype", name) output = xcodeprojer.unparse(root, format="xcode", projectname=name) with open(pbxproj + ".new", "w") as f: f.write(output) try: os.unlink(pbxproj) except: pass os.rename(pbxproj + ".new", pbxproj) plist = dict(CFBundleDevelopmentRegion="en", CFBundleDisplayName="$(PRODUCT_NAME)", CFBundleExecutable="$(EXECUTABLE_NAME)", CFBundleIdentifier="$(PRODUCT_BUNDLE_IDENTIFIER)", CFBundleInfoDictionaryVersion="6.0", CFBundleName="$(PRODUCT_NAME)", CFBundlePackageType="APPL", CFBundleShortVersionString=version, CFBundleSignature="????", CFBundleVersion=1, LSRequiresIPhoneOS=True, UIRequiresFullScreen=True, UIStatusBarHidden=True, UISupportedInterfaceOrientations=[ "UIInterfaceOrientationLandscapeRight", "UIInterfaceOrientationLandscapeLeft", ]) plistlib.writePlist(plist, os.path.join(dest, "Info.plist")) interface.success("Created the Xcode project.")