Exemplo n.º 1
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.º 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)
Exemplo n.º 3
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 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.º 5
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
Exemplo 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)
Exemplo n.º 7
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)