Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
unicado.gitlab.io
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
UNICADO
unicado.gitlab.io
Commits
762694f6
Commit
762694f6
authored
4 months ago
by
Kristina Mazur
Browse files
Options
Downloads
Patches
Plain Diff
Improves the output
parent
2dee08bc
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
scripts/document_aircraft_xml.py
+28
-35
28 additions, 35 deletions
scripts/document_aircraft_xml.py
with
28 additions
and
35 deletions
scripts/document_aircraft_xml.py
+
28
−
35
View file @
762694f6
...
...
@@ -51,7 +51,7 @@ from pathlib import Path
# === Configuration ===
# Define the format of the output
FORMAT
=
{
"
Header
"
:
"
# {:s}
\n
> **Description**: {:s}
\n
"
,
"
Header
"
:
"
\n
#
# {:s}
\n
> **Description**: {:s}
\n
"
,
"
Unit
"
:
"
> **Unit**: {:s}
\n
"
,
"
TableHeader
"
:
"
| Relative XML Path | Unit | Description |
\n
|:---|:---:|:---|
"
,
"
Table
"
:
"
| <nobr>`{:s}` | *{:s}* | {:s} |
"
,
...
...
@@ -92,43 +92,28 @@ class Page:
self
.
sections
=
[[]]
def
create
(
self
,
node
:
ET
.
Element
):
"""
Creates the page from the given node.
"""
Creates the page from the given node
, summarizing nested elements properly
.
Args:
node (ET.Element): Node to start from.
"""
# Only add the header if it was not already added at this level
if
node
.
tag
in
self
.
sections
[
self
.
current_level
]:
return
# Check whether the current entry can be a header
# Add header if appropriate
if
not
self
.
max_level_reached
:
self
.
sections
[
self
.
current_level
].
append
(
node
.
tag
)
self
.
make_header_entry
(
node
)
self
.
current_path
=
Path
(
node
.
tag
)
else
:
self
.
current_path
/=
node
.
tag
# Loop through the children and group single entries in a table
for
child
in
node
:
if
len
(
child
)
==
0
:
# No further nesting
self
.
make_table_entry
(
child
)
else
:
self
.
create
(
child
)
# Recursively process child nodes
# Add a new level of sections
self
.
current_level
+=
1
self
.
sections
.
append
([])
# Loop again and add the subnodes
for
child
in
node
:
if
len
(
child
)
>
0
:
# Treat node attributes and values as part of the parent row
if
len
(
node
)
==
0
:
# Leaf node
self
.
make_table_entry
(
node
)
else
:
# Parent node
# Add a summary row for the parent node
self
.
make_table_entry
(
node
)
# Process child elements recursively, skipping common attributes like 'value', 'unit', etc.
for
child
in
node
:
if
child
.
tag
in
[
"
value
"
,
"
unit
"
,
"
lower_boundary
"
,
"
upper_boundary
"
]:
continue
self
.
create
(
child
)
# Decrease the level again when finished
self
.
current_level
-=
1
self
.
sections
.
pop
()
self
.
current_path
=
self
.
current_path
.
parent
def
make_header_entry
(
self
,
node
:
ET
.
Element
):
"""
Creates a header entry.
...
...
@@ -155,7 +140,7 @@ class Page:
print
(
FORMAT
[
"
Unit
"
].
format
(
unit
))
def
make_table_entry
(
self
,
node
:
ET
.
Element
):
"""
Creates a table entry.
"""
Creates a table entry
for the current node, embedding child attributes into the parent node
'
s row
.
Args:
node (ET.Element): The current node element.
...
...
@@ -165,17 +150,25 @@ class Page:
self
.
table_started
=
True
print
(
FORMAT
[
"
TableHeader
"
])
# Since we use pathlib for convenience, we need to convert it to a string
# and replace the backslashes with forward slashes
# Generate a relative XML path for the current node
path_name
=
str
(
self
.
current_path
/
node
.
tag
).
replace
(
"
\\
"
,
"
/
"
)
# Fetch description and unit
# Fetch
parent
description and unit
description
=
node
.
attrib
.
get
(
KEYS
[
"
Description
"
],
f
"
No description for
{
node
.
tag
}
"
)
unit
=
node
.
attrib
.
get
(
KEYS
[
"
Unit
"
],
"
No unit specified
"
)
# Collect all child attributes
child_details
=
[]
for
child
in
node
:
child_desc
=
child
.
attrib
.
get
(
KEYS
[
"
Description
"
],
f
"
No description for
{
child
.
tag
}
"
)
child_unit
=
child
.
attrib
.
get
(
KEYS
[
"
Unit
"
],
"
No unit specified
"
)
child_details
.
append
(
f
"
{
child
.
tag
}
:
{
child_desc
}
(unit:
{
child_unit
}
)
"
)
# Combine parent description with child attributes
combined_description
=
description
+
"
|
"
+
"
|
"
.
join
(
child_details
)
#
Create
the table row
print
(
FORMAT
[
"
Table
"
].
format
(
path_name
,
unit
,
description
))
#
Print
the table row
for the parent node
print
(
FORMAT
[
"
Table
"
].
format
(
path_name
,
unit
,
combined_
description
))
# === Main ===
def
main
():
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment