Skip to content
Snippets Groups Projects
Commit 0c63ba43 authored by Kristina Mazur's avatar Kristina Mazur
Browse files

Delete parsing of aircraft xml - not necessary anymore

parent 69c7d261
Branches feature/CI
No related tags found
No related merge requests found
Pipeline #1544207 failed
......@@ -63,9 +63,6 @@ pages:
- pip install pipenv
- pipenv install
script:cmks
- mkdir $CI_PROJECT_DIR/documentation/aircraft-xml
#- python $CI_PROJECT_DIR/scripts/document_aircraft_xml.py --title Design specification --level 4 $CI_PROJECT_DIR/scripts/csmr-2020_startCSD.xml > $CI_PROJECT_DIR/documentation/aircraft-xml/specification.md
- python $CI_PROJECT_DIR/scripts/document_aircraft_xml.py --title DesignSpecification --level 4 $CI_PROJECT_DIR/scripts/csmr-2020_startCSD.xml > $CI_PROJECT_DIR/documentation/aircraft-xml/specification.md
- pipenv run mkdocs build --site-dir $CI_PROJECT_DIR/public
needs:
- doxygen
......
......@@ -104,9 +104,6 @@ nav: # Customizes the main navigation struc
- Libraries: 'documentation/libraries.md' # Link to libraries overview.
- Utilities: 'documentation/additional-software.md' # Link to additional software page.
- Workflow: 'workflow.md' # Link to the workflow page.
- Aircraft Exchange File:
- 'DesignSpecification': 'aircraft-xml/specification.md'
#- Design specification: 'aircraft-xml/specification.md'
- Get involved:
- Developer Guide: developer/developer-installation.md # Top-level item for contributions and development.
- Build Instructions:
......
Source diff could not be displayed: it is too large. Options to address this: view the blob.
This diff is collapsed.
import argparse
import xml.etree.ElementTree as ET
from pathlib import Path
# === Configuration ===
FORMAT = {
"Header": "\n{}## {:s}\n> **Description**: {:s}\n",
"Unit": "> **Unit**: {:s}\n",
"TableHeader": "| Relative XML Path | Unit | Description |\n|:---|:---:|:---|",
"Table": "| <nobr>`{:s}` | *{:s}* | {:s} |",
}
KEYS = {
"Description": "description",
"Unit": "unit",
}
# Define specific levels for each child node of "requirements_and_specifications"
CUSTOM_LEVELS = {
"general": 2,
"mission_files": 2,
"design_specification": 4,
"requirements": 3,
}
class Page:
def __init__(self, title):
self.title = title
self.current_level = 0
self.table_started = False
self.current_path = Path(".")
self.sections = [[]]
def create(self, node: ET.Element, level=None):
# Set the level based on custom levels if provided
if node.tag in CUSTOM_LEVELS:
level = CUSTOM_LEVELS[node.tag]
elif level is None:
level = self.current_level + 1
# Update current level and path
if level <= 4:
self.current_level = level
self.current_path /= node.tag
# Add header if appropriate
self.make_header_entry(node)
# 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 not in ["value", "unit", "lower_boundary", "upper_boundary"]:
self.create(child, level + 1)
# Restore previous path after processing
self.current_path = self.current_path.parent
def make_header_entry(self, node: ET.Element):
# Reset the table when creating a new header
self.table_started = False
# Fetch description and adjust header level format
description = node.attrib.get(KEYS["Description"], "None")
header_level_prefix = "#" * min(self.current_level, 4)
# Create the header with description
print(
"\n"
+ header_level_prefix
+ FORMAT["Header"].format(self.current_level, node.tag, description)
)
# Try to add a unit description
unit = node.attrib.get(KEYS["Unit"])
if unit:
print(FORMAT["Unit"].format(unit))
def make_table_entry(self, node: ET.Element):
# Check if the table has already been started
if not self.table_started:
self.table_started = True
print(FORMAT["TableHeader"])
# Generate a relative XML path for the current node
path_name = str(self.current_path / node.tag).replace("\\", "/")
# Fetch the description and unit
description = node.attrib.get(KEYS["Description"], f"No description for {node.tag}")
unit = node.attrib.get(KEYS["Unit"], "No unit specified")
# Print the table row for the current node
print(FORMAT["Table"].format(path_name, unit, description))
def main():
parser = argparse.ArgumentParser(
description="Converts an aircraft XML file to a markdown file. The output is streamed to stdout and can be piped to a file."
)
# Add the filename argument
parser.add_argument(
"filename", metavar="filename", type=str, help="The XML file to convert."
)
# Add the layout arguments
parser.add_argument(
"--title",
metavar="title",
type=str,
help="The title of the output page. This also sets the root node which is used to create the document.",
)
# Parse the arguments
args = parser.parse_args()
# Read the XML file
tree = ET.parse(args.filename)
root = tree.getroot()
# Get the configuration parameters
page = Page(args.title)
node = root.find(page.title)
# Check whether the node exists
if node is None:
raise Warning("Could not find node with title '" + page.title + "'")
# Start creating the page
page.create(node)
if __name__ == "__main__":
main()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment