Ejemplo n.º 1
0
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
Ejemplo n.º 2
0
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
Ejemplo n.º 3
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)
Ejemplo n.º 4
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
Ejemplo n.º 6
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)
Ejemplo n.º 7
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
Ejemplo n.º 8
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)