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
Example #2
0
    def check_format_tree(self, format):
        prj, filename = read_intl_project()
        prj = bytestr(prj)
        prjname = xcodeprojer.projectname_for_path(filename)
        plistroot, parseinfo = parse(prj, format='xcode')
        self.assertIsNotNone(plistroot)

        fmtfilename = os.path.join(dirname(filename), 'project.%s' % format)
        formattext = read_file(fmtfilename)
        root, parseinfo = parse(formattext, format=format)
        self.assertIsNotNone(root)
        self.assertEqual(root, plistroot)

        root, parseinfo = parse(prj)
        output = xcodeprojer.unparse(root, format=format, projectname=prjname)
        if formattext != output:
            xcodeprojer.print_diff(formattext, output, filename=filename)
        self.assertEqual(formattext, output)
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 check_format_tree(self, format):
        prj, filename = read_intl_project()
        prj = bytestr(prj)
        prjname = xcodeprojer.projectname_for_path(filename)
        plistroot, parseinfo = parse(prj, format='xcode')
        self.assertIsNotNone(plistroot)

        fmtfilename = os.path.join(dirname(filename), 'project.%s' % format)
        formattext = read_file(fmtfilename)
        root, parseinfo = parse(formattext, format=format)
        self.assertIsNotNone(root)
        self.assertEqual(root, plistroot)

        root, parseinfo = parse(prj)
        output = xcodeprojer.unparse(root, format=format, projectname=prjname)
        if formattext != output:
            xcodeprojer.print_diff(formattext, output, filename=filename)
        self.assertEqual(formattext, output)
    def test_i18n(self):
        prj, filename = read_intl_project()
        prj = bytestr(prj)
        prjname = xcodeprojer.projectname_for_path(filename)

        for parsertype in ['fast', 'classic']:
            root, parseinfo = parse(prj, format='xcode', parsertype=parsertype)
            self.assertIsNotNone(root, "parsing with parsertype %s failed" % parsertype)
            pbxproject = find_isa(root['objects'], 'PBXProject')
            orgname = pbxproject['attributes']['ORGANIZATIONNAME']
            self.assertEqual(orgname, u('🎫'),
                             "unexpected ORGANIZATIONNAME '%s' after parsing with parsertype %s."
                             % (pbxproject['attributes']['ORGANIZATIONNAME'], parsertype))

            output = xcodeprojer.unparse(root, format='xcode', projectname=prjname)
            if prj != output:
                xcodeprojer.print_diff(prj, output, filename=filename)

            self.assertEqual(prj, output)
Example #6
0
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
Example #7
0
    def test_i18n(self):
        prj, filename = read_intl_project()
        prj = bytestr(prj)
        prjname = xcodeprojer.projectname_for_path(filename)

        for parsertype in ['fast', 'classic']:
            root, parseinfo = parse(prj, format='xcode', parsertype=parsertype)
            self.assertIsNotNone(
                root, "parsing with parsertype %s failed" % parsertype)
            pbxproject = find_isa(root['objects'], 'PBXProject')
            orgname = pbxproject['attributes']['ORGANIZATIONNAME']
            self.assertEqual(
                orgname, u('🎫'),
                "unexpected ORGANIZATIONNAME '%s' after parsing with parsertype %s."
                % (pbxproject['attributes']['ORGANIZATIONNAME'], parsertype))

            output = xcodeprojer.unparse(root,
                                         format='xcode',
                                         projectname=prjname)
            if prj != output:
                xcodeprojer.print_diff(prj, output, filename=filename)

            self.assertEqual(prj, output)
Example #8
0
def unparse(root, **kwargs):
    return xcodeprojer.unparse(root, **kwargs).decode('utf-8')
def unparse(root, **kwargs):
    return xcodeprojer.unparse(root, **kwargs).decode('utf-8')
Example #10
0
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.")
Example #11
0
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.")