GithubHelp home page GithubHelp logo

Comments (20)

kronenthaler avatar kronenthaler commented on September 26, 2024

Please, read the method signature. remove_group uses an id to remove the group.
remove_group_by_name removes the group based on the name.
BTW, You are not passing either of them to the method you are calling, you are passing an object group.

from mod-pbxproj.

da-mian avatar da-mian commented on September 26, 2024

Sorry, doesn't get_or_create_group return an id too?

from mod-pbxproj.

kronenthaler avatar kronenthaler commented on September 26, 2024

It returns a group object, those objects are required by other methods for instance to add_file, you may want to specify that the file goes under a specific group (object)

from mod-pbxproj.

da-mian avatar da-mian commented on September 26, 2024

I see. Then what's the way to remove a group? I don't seem to succeed with remove_group_by_name either.
This leaves the project with the group named "Hola":

    group = project.get_or_create_group("Hola")
    project.remove_group(group)
    project.remove_group(group.id)
    project.remove_group_by_name("Hola")
    project.save()

Thanks

from mod-pbxproj.

huazi2015 avatar huazi2015 commented on September 26, 2024

i also ask this question , please

from mod-pbxproj.

kronenthaler avatar kronenthaler commented on September 26, 2024

I checked it. It was a bug, and it's fixed already in the master branch. Pull request #57 if you are curious about the changes.

from mod-pbxproj.

da-mian avatar da-mian commented on September 26, 2024

Thanks @kronenthaler, The group is removed now.
Anyway I have one more question about this:
If the group contains source files, these are not removed from the Compile Sources build phase.
What would be the approach to take regarding this?

from mod-pbxproj.

kronenthaler avatar kronenthaler commented on September 26, 2024

try with the recursive flag of the method.
remove_group_by_name('name', True)

from mod-pbxproj.

da-mian avatar da-mian commented on September 26, 2024

With the recursive flag it fails with this error:

Traceback (most recent call last):
  File "./BuildFromWorkspaceUsingBundles.py", line 108, in <module>
    project.remove_group_by_name(adapterName, True)
  File "/Users/damian.troncoso/Desktop/workspace/LIMA-docs/Tools/AutomatedBuilding/mod_pbxproj/mod_pbxproj/mod_pbxproj.py", line 1002, in remove_group_by_name
    self.remove_group(group.id, recursive)
  File "/Users/damian.troncoso/Desktop/workspace/LIMA-docs/Tools/AutomatedBuilding/mod_pbxproj/mod_pbxproj/mod_pbxproj.py", line 983, in remove_group
    name = self.objects.get(id).get('path')
AttributeError: 'NoneType' object has no attribute 'get'

This seems to happen when there is a group within the group I'm removing with the same name

from mod-pbxproj.

kronenthaler avatar kronenthaler commented on September 26, 2024

I will check it over the weekend

On Fri, May 29, 2015 at 9:36 PM, Damian [email protected] wrote:

With the recursive flag it fails with this error:

Traceback (most recent call last):
File "./BuildFromWorkspaceUsingBundles.py", line 108, in
project.remove_group_by_name(adapterName, True)
File "/Users/damian.troncoso/Desktop/workspace/LIMA-docs/Tools/AutomatedBuilding/mod_pbxproj/mod_pbxproj/mod_pbxproj.py", line 1002, in remove_group_by_name
self.remove_group(group.id, recursive)
File "/Users/damian.troncoso/Desktop/workspace/LIMA-docs/Tools/AutomatedBuilding/mod_pbxproj/mod_pbxproj/mod_pbxproj.py", line 983, in remove_group
name = self.objects.get(id).get('path')
AttributeError: 'NoneType' object has no attribute 'get'


Reply to this email directly or view it on GitHub
#53 (comment)
.

.: Kronenthaler :.

[email protected] | yahoo.com

from mod-pbxproj.

da-mian avatar da-mian commented on September 26, 2024

Thanks a lot!

from mod-pbxproj.

huazi2015 avatar huazi2015 commented on September 26, 2024

DELETED: unrelated input to the issue.

from mod-pbxproj.

kronenthaler avatar kronenthaler commented on September 26, 2024

I couldn't reproduce your error. Neither with the remove_group_by_name or remove_group. Here is the script i used to test.

#!/bin/python
from mod_pbxproj import XcodeProject

project = XcodeProject.Load('test/test.xcodeproj/project.pbxproj')
# create Hola/bye/source.m
group = project.get_or_create_group("Hola")
groupB = project.get_or_create_group(name="bye", parent=group)
project.add_file_if_doesnt_exist("source.m", parent=groupB)
# remove recursively using the string name
project.remove_group_by_name("Hola", True)

# create Hola/bye/source.m
group2 = project.get_or_create_group("Hola")
groupB2 = project.get_or_create_group(name="bye", parent=group2)
project.add_file_if_doesnt_exist("source.m", parent=groupB2)
# remove recursively using the group2 instance + id
project.remove_group(group2.id, True)

project.save()

from mod-pbxproj.

da-mian avatar da-mian commented on September 26, 2024

I meant when there's a group within a group, both with the same name.
So for example this:

group = project.get_or_create_group("Hola")
groupB = project.get_or_create_group(name="Hola", parent=group)
project.remove_group_by_name("Hola", True)
project.save()

It fails with this log:

Traceback (most recent call last):
  File "./BuildFromWorkspaceUsingBundles.py", line 112, in <module>
    project.remove_group_by_name("Hola", True)
  File "/Users/damian.troncoso/Desktop/workspace/LIMA-docs/Tools/AutomatedBuilding/mod_pbxproj/mod_pbxproj/mod_pbxproj.py", line 1002, in remove_group_by_name
    self.remove_group(group.id, recursive)
  File "/Users/damian.troncoso/Desktop/workspace/LIMA-docs/Tools/AutomatedBuilding/mod_pbxproj/mod_pbxproj/mod_pbxproj.py", line 991, in remove_group
    if childValue.get('isa') == 'PBXGroup':
AttributeError: 'NoneType' object has no attribute 'get'

from mod-pbxproj.

kronenthaler avatar kronenthaler commented on September 26, 2024

True, but that operation is ambiguous.
Both groups have the same name, there is no way to ensure which one was deleted first (the parent or the child).
In such cases use the id to resolve the ambiguity yourself.

from mod-pbxproj.

da-mian avatar da-mian commented on September 26, 2024

But if I use the id (project.remove_group(group.id)), the source files are not removed from the Compile Sources build phase.

from mod-pbxproj.

kronenthaler avatar kronenthaler commented on September 26, 2024

I fixed that issue on pull request #57 give it a try

from mod-pbxproj.

da-mian avatar da-mian commented on September 26, 2024

I just checked it. It's not fixed :/
project.remove_group(group.id) still leaves the source files in the Compile Sources build phase, which leads to compiler errors.

from mod-pbxproj.

kronenthaler avatar kronenthaler commented on September 26, 2024

This is the code i have been using to test the feature:

#!/bin/python
from mod_pbxproj import XcodeProject

project = XcodeProject.Load('test/test.xcodeproj/project.pbxproj')
# add a file to the sources
group = project.get_or_create_group("Hola")
groupB = project.get_or_create_group(name="Hola", parent=group)
project.add_file_if_doesnt_exist("source.m", parent=groupB)

# comment out to actually remove the file
# project.remove_group(group.id, True) # note the True to make it recursive.

project.save()

Create an empty project and run over that project. It will create: Hola/Hola/source.m
Check that the file is in the sources section of the target.
Un-comment the remove_group and run again.
Check again the sources section of the target. It should be gone.

If this works, the problem is in your script.

from mod-pbxproj.

da-mian avatar da-mian commented on September 26, 2024

Sorry, I didn't realize I could use remove_group with the recursive option :)
It's working now.
Thanks a lot!

from mod-pbxproj.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.