Exemplo 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
Exemplo n.º 2
0
 def test_unicode_in_unquoted(self):
     prj, filename = read_mini_project()
     prj = prj.replace(u('ORGANIZATIONNAME = "ACME Inc.";'),
                       u('ORGANIZATIONNAME = 🍏;'))
     prj = bytestr(prj)
     for format, parsertype in [(None, 'normal'), ('xcode', 'fast'), ('xcode', 'classic')]:
         buf = StringIO()
         root, parseinfo = parse(prj, format=format, parsertype=parsertype,
                                 report=True, fp=buf)
         self.assertIsNone(root)
Exemplo n.º 3
0
 def test_unicode_in_unquoted(self):
     prj, filename = read_mini_project()
     prj = prj.replace(u('ORGANIZATIONNAME = "ACME Inc.";'),
                       u('ORGANIZATIONNAME = 🍏;'))
     prj = bytestr(prj)
     for format, parsertype in [(None, 'normal'), ('xcode', 'fast'),
                                ('xcode', 'classic')]:
         buf = StringIO()
         root, parseinfo = parse(prj,
                                 format=format,
                                 parsertype=parsertype,
                                 report=True,
                                 fp=buf)
         self.assertIsNone(root)
Exemplo 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)
Exemplo n.º 5
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
Exemplo n.º 7
0
def find_projects(args, parser):
    root = args.find
    filenames = []
    for name in xcodeprojer.find_projectfiles(root):
        filenames.append(name)
        # This might take a while, report progress
        sys.stdout.write('.')
        sys.stdout.flush()
    print()

    if not filenames:
        print('No project.pbxproj files found in "%s"' % root)
        return

    fn = rel(LISTFILENAME)
    with open(fn, 'wb') as f:
        text = '\n'.join(filenames) + '\n'
        f.write(bytestr(text))
        print('\nWrote %d filename to "%s"' % (len(filenames), fn))
Exemplo 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)
def find_projects(args, parser):
    root = args.find
    filenames = []
    for name in xcodeprojer.find_projectfiles(root):
        filenames.append(name)
        # This might take a while, report progress
        sys.stdout.write('.')
        sys.stdout.flush()
    print()

    if not filenames:
        print('No project.pbxproj files found in "%s"' % root)
        return

    fn = rel(LISTFILENAME)
    with open(fn, 'wb') as f:
        text = '\n'.join(filenames) + '\n'
        f.write(bytestr(text))
        print('\nWrote %d filename to "%s"' % (len(filenames), fn))
Exemplo n.º 10
0
def handle_result(args, success, text, filename):
    if not success:
        print()
        print(text)
        return

    try:
        with open(bytestr(filename), 'rb') as f:
            origtext = f.read()
            if origtext[:1] not in [b'/', b'{']:
                # Only handle files in plist format.
                return
    except IOError as e:
        if e.errno not in (errno.ENOTDIR, errno.ENOENT):
            raise
        return

    if text == origtext:
        return

    xcodeprojer.print_diff(origtext, text, difftype=args.diff, filename=filename)
Exemplo n.º 11
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)
Exemplo n.º 12
0
def handle_result(args, success, text, filename):
    if not success:
        print()
        print(text)
        return

    try:
        with open(bytestr(filename), 'rb') as f:
            origtext = f.read()
            if origtext[:1] not in [b'/', b'{']:
                # Only handle files in plist format.
                return
    except IOError as e:
        if e.errno not in (errno.ENOTDIR, errno.ENOENT):
            raise
        return

    if text == origtext:
        return

    xcodeprojer.print_diff(origtext,
                           text,
                           difftype=args.diff,
                           filename=filename)