Skip to content

Commit

Permalink
Merge pull request #114 from kronenthaler/recursive-groups-removal
Browse files Browse the repository at this point in the history
fix: remove groups recusively now delete the files as well (issue #112)
  • Loading branch information
kronenthaler authored Jan 8, 2017
2 parents f915a19 + 14730fa commit 90ce0b6
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 6 deletions.
2 changes: 1 addition & 1 deletion mod_pbxproj.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
import site

__author__ = 'kronenthaler'
__version__ = '2.0.0'
__version__ = '2.0.1'
__package_name__ = 'mod_pbxproj_installer'

try:
Expand Down
2 changes: 1 addition & 1 deletion pbxproj/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@
from pbxproj.XcodeProject import XcodeProject
from pbxproj.pbxsections import *

__version__ = '2.0.0'
__version__ = '2.0.1'
17 changes: 15 additions & 2 deletions pbxproj/pbxextensions/ProjectGroups.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 7 additions & 1 deletion pbxproj/pbxsections/PBXFileReference.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']),
Expand Down
13 changes: 13 additions & 0 deletions tests/pbxextensions/TestProjectGroups.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'},
}
}

Expand Down Expand Up @@ -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')
Expand Down

0 comments on commit 90ce0b6

Please sign in to comment.