How to use the pbxproj.write function in pbxproj

To help you get started, we’ve selected a few pbxproj examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github simonwagner / mergepbx / test / test_pbxparsing.py View on Github external
def test_fixtures(self):
        parsing_fixtures_path = fixture_path("parse")

        project_files = [file for file in listpath(parsing_fixtures_path) if file.endswith(".pbxproj")]

        self.logger.debug("parsing %d files..." % len(project_files))

        for project_file in project_files:
            self.logger.debug("trying to parse file %s" % project_file)

            data = pbxproj.read(project_file)
            f_o = wrap_with_codec(StringIO(), data.get_encoding())
            pbxproj.write(f_o, data)

            #now compare the content of the written file with the original file
            #this should stay the same
            original_content = open(project_file).read()
            new_content = f_o.getvalue()
            f_o.close()

            #if assert will fail, generate a diff for this failure
            if not new_content == original_content:
                self.logger.error("failed to generate an exact replica, diff follows:")
                diff_lines = difflib.unified_diff(original_content.splitlines(), new_content.splitlines())
                for line in diff_lines:
                    self.logger.error(line)

            self.assertEquals(new_content, original_content, "%s was not correctly parsed" % project_file)
github simonwagner / mergepbx / test / test_pbxmerge.py View on Github external
merge_projects = listpath(merge_fixtures_path)
        merge_tasks = [listpath(merge_project) for merge_project in merge_projects]

        for merge_task in chain.from_iterable(merge_tasks):
            task_files = listpath(merge_task)
            project_files = load_merge_task(task_files)

            self.logger.info("merging base %s with my %s and their %s and comparing with %s..." % project_files)

            projects = [pbxproj.read(project_file) for project_file in project_files]
            base, mine, theirs, merged = projects

            merged_buffer = StringIO()
            merged_buffer = wrap_with_codec(merged_buffer, codec=base.get_encoding())
            merged_project = merge_pbxs(base, mine, theirs)
            pbxproj.write(merged_buffer, merged_project)

            #now compare the content of the written file with the original file
            #this should stay the same
            expected_merged_content = open(project_files[-1]).read()
            merged_content = merged_buffer.getvalue()
            merged_buffer.close()

            #if assert will fail, generate a diff for this failure
            if not merged_content == expected_merged_content:
                self.logger.error("failed to generate an exact replica, diff follows:")
                diff_lines = difflib.unified_diff(expected_merged_content.splitlines(), merged_content.splitlines())
                for line in diff_lines:
                    self.logger.error(line)

            self.assertEquals(merged_content, expected_merged_content, "%s was not correctly merged" % merge_task)
github simonwagner / mergepbx / src / mergepbx.py View on Github external
def merge_pbx_files(basef, minef, theirsf, mergedf, clean=False):
    base, mine, theirs = read_pbxs((basef, minef, theirsf))

    if clean:
        for name, project in zip((basef, minef, theirsf), (base, mine, theirs)):
            files_removed = project.clean_files()
            if len(files_removed) > 0:
                print "WARNING: %d dangling file references removed from %s" % (len(files_removed), name)


    merged_project = merge_pbxs(base, mine, theirs)

    pbxproj.write(mergedf, merged_project)
github simonwagner / mergepbx / tools / merge_pbxproj_fixtures.py View on Github external
def merge_pbx_files(basef, minef, theirsf, mergedf):
    base, mine, theirs = read_pbxs((basef, minef, theirsf))

    merged_project = merge_pbxs(base, mine, theirs)

    pbxproj.write(mergedf, merged_project)