As a first step to create a "mission generator" for a flight simulator I would like to be able to extract pieces of a mission template so I can alter or delete some stuff, put it altogether again and so generate a new "mission" file. I have minimal Python skills. I don't need a working solution, but would like a direction to investigate further. Here is the challenge:
This is a (simplified) sample of the input file:
test_str = ("Group\n"
"{\n"
" Name = \"Group 1\";\n"
" Index = 2;\n"
" Desc = \"Description\";\n"
" Block\n"
" {\n"
" Name = \"Block 1\";\n"
" Index = 497;\n"
" XPos = 171568.472;\n"
" YPos = 0.000;\n"
" ZPos = 204878.718;\n"
" }\n"
"\n"
" Block\n"
" {\n"
" Name = \"Block 2\";\n"
" Index = 321;\n"
" XPos = 162268.472;\n"
" YPos = 0.000;\n"
" ZPos = 203478.718;\n"
" }\n"
"\n"
"}\n"
"\n"
"Group\n"
"{\n"
" Name = \"Group 2\";\n"
" Index = 5;\n"
" Desc = \"Description\";\n"
" Block\n"
" {\n"
" Name = \"Block 3\";\n"
" Index = 112;\n"
" XPos = 122268.472;\n"
" YPos = 0.000;\n"
" ZPos = 208878.718;\n"
" }\n"
"\n"
" Block\n"
" {\n"
" Name = \"Block 4\";\n"
" Index = 214;\n"
" XPos = 159868.472;\n"
" YPos = 0.000;\n"
" ZPos = 202678.718;\n"
" }\n"
"\n"
"}\n")
As you can see the file consist of numerous objects ("blocks") that can be grouped. This is a nested structure as groups may also be grouped (not shown here). How can I isolate one particular group based on it's name?
So let's say I only want to use "Group 2" in my output file, I would want to get as a result:
Group
{
Name = "Group 2";
Index = 5;
Desc = "Description";
Block
{
Name = "Block 3";
Index = 112;
XPos = 122268.472;
YPos = 0.000;
ZPos = 208878.718;
}
Block
{
Name = "Block 4";
Index = 214;
XPos = 159868.472;
YPos = 0.000;
ZPos = 202678.718;
}
}
And a similar question for a given block inside a group.