How to export a hierarchy of logical components with P4C

I desperately try to export a hierarchy of logical components deriving sample_scripts.
it is completely unsuccessfull :frowning:

Could you give me some advices?
at the end, it could be a good new sample_script for the community if there is a way to give you the final file.



I would suggest you to provide us with some details/errors/stack traces/console content/script content.
It is very difficult for us to help you without this kind of information.

And of course any contribution will be taken into account and eventually integrated.


Sorry, you’ve right! I will be careful next time…
I just found a ugly way to export the hierarchy of Logical Component

Perhaps you have a smarter way to iterate the sub elements of the PBS?


You can use a recursive function:

def export(worksheet, column, line, logical_component):
    worksheet[column + str(line++)] = logical_component.get_name()
    child_column = next_alpha(column)
    for child in logical_component.get_owned_logical_components():
        export(worksheet, child_column, line++, child)

def next_alpha(s):
    return chr((ord(s.upper())+1 - 65) % 26 + 65)

You can then call it like this:

export(worksheet, "A", 2, some_logical_component)

Note: the next_alpha() doesn’t create “AA” and will restart at “A” if you have more than 26 levels of components.