diff --git a/mod_pbxproj.py b/mod_pbxproj.py index e4ce3963..27176dba 100644 --- a/mod_pbxproj.py +++ b/mod_pbxproj.py @@ -30,7 +30,7 @@ import site __author__ = 'kronenthaler' -__version__ = '2.0.0' +__version__ = '2.0.1' __package_name__ = 'mod_pbxproj_installer' try: diff --git a/pbxproj/__init__.py b/pbxproj/__init__.py index d5220067..b01bee2f 100644 --- a/pbxproj/__init__.py +++ b/pbxproj/__init__.py @@ -27,4 +27,4 @@ from pbxproj.XcodeProject import XcodeProject from pbxproj.pbxsections import * -__version__ = '2.0.0' +__version__ = '2.0.1' diff --git a/pbxproj/pbxextensions/ProjectGroups.py b/pbxproj/pbxextensions/ProjectGroups.py index 17ff6cc8..241009a9 100644 --- a/pbxproj/pbxextensions/ProjectGroups.py +++ b/pbxproj/pbxextensions/ProjectGroups.py @@ -43,10 +43,23 @@ def remove_group_by_id(self, group_id, recursive=True): if group is None: return False - # error removing the element or any of its children - if not group.remove(recursive): + result = True + # iterate over the children and determine if they are file/group and call the right method. + for subgroup_id in list(group.children): + subgroup = self.objects[subgroup_id] + if subgroup is None: + return False + + if recursive and isinstance(subgroup, PBXGroup): + result &= self.remove_group_by_id(subgroup.get_id(), recursive) + if isinstance(subgroup, PBXFileReference): + result &= self.remove_file_by_id(subgroup.get_id()) + + if not result: return False + del self.objects[group.get_id()] + # remove the reference from any other group object that could be containing it. for other_group in self.objects.get_objects_in_section(u'PBXGroup'): other_group.remove_child(group) diff --git a/pbxproj/pbxsections/PBXFileReference.py b/pbxproj/pbxsections/PBXFileReference.py index 7e51961a..2af4fc27 100644 --- a/pbxproj/pbxsections/PBXFileReference.py +++ b/pbxproj/pbxsections/PBXFileReference.py @@ -26,5 +26,11 @@ def set_last_known_file_type(self, file_type): def _print_object(self, indentation_depth=u'', entry_separator=u'\n', object_start=u'\n', indentation_increment=u'\t'): return super(PBXFileReference, self)._print_object(u'', entry_separator=u' ', object_start=u'', - indentation_increment=u'') + indentation_increment=u'') + + def remove(self, recursive=True): + # search on the BuildFiles if there is a build file to be removed, and remove it + # search for each phase that has a reference to the build file and remove it from it. + # remove the file reference from it's parent + pass diff --git a/setup.py b/setup.py index 843212c8..e837e694 100755 --- a/setup.py +++ b/setup.py @@ -45,7 +45,7 @@ def run_tests(self): ] }, url="http://github.com/kronenthaler/mod-pbxproj", - version='2.0.0', + version='2.0.1', license='MIT License', install_requires=['openstep_parser', 'docopt'], packages=find_packages(exclude=['tests']), diff --git a/tests/pbxextensions/TestProjectGroups.py b/tests/pbxextensions/TestProjectGroups.py index 63292e97..314db67e 100644 --- a/tests/pbxextensions/TestProjectGroups.py +++ b/tests/pbxextensions/TestProjectGroups.py @@ -21,6 +21,9 @@ def setUp(self): '6p': {'isa': 'PBXGroup', 'name': 'app', 'path': '..', 'children': []}, 'broken': {'isa': 'PBXGroup', 'name': 'broken', 'path': '..', 'children': ['broken1']}, 'broken1': {'isa': 'PBXGroup', 'name': 'b1', 'path': '..', 'children': ['broken2']}, + 'a': {'isa': 'PBXGroup', 'name': 'app', 'path': '..', 'children': ['b']}, + 'b': {'isa': 'PBXGroup', 'name': 'app', 'path': '..', 'children': ['c']}, + 'c': {'isa': 'PBXFileReference', 'name': 'app'}, } } @@ -140,6 +143,16 @@ def testRemoveByNameNonRecursive(self): self.assertIsNotNone(project.objects['2p']) self.assertIsNotNone(project.objects['3p']) + def testRemoveByIdRecursivelyWithFiles(self): + project = XcodeProject(self.obj) + group1 = project.objects['a'] + result = project.remove_group_by_id('a') + + self.assertTrue(result) + self.assertIsNone(project.objects['a']) + self.assertIsNone(project.objects['b']) + self.assertIsNone(project.objects['c']) + def testRemoveBrokenGroups(self): project = XcodeProject(self.obj) result = project.remove_group_by_id('broken')