sarvekshayr commented on code in PR #6916: URL: https://github.com/apache/ozone/pull/6916#discussion_r2753006801
########## dev-support/ci/xml_to_md.py: ########## @@ -0,0 +1,127 @@ +#!/usr/bin/python +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# Python file to convert XML properties into Markdown +import os +import re +import zipfile +import xml.etree.ElementTree as ET +from collections import namedtuple +from pathlib import Path +import sys + +Property = namedtuple('Property', ['name', 'value', 'tag', 'description']) + +def extract_xml_from_jar(jar_path, xml_filename): + xml_files = [] + with zipfile.ZipFile(jar_path, 'r') as jar: + for file_info in jar.infolist(): + if file_info.filename.endswith(xml_filename): + with jar.open(file_info.filename) as xml_file: + xml_files.append(xml_file.read()) + return xml_files + +def wrap_config_keys_in_description(description, properties): + for key in properties.keys(): + description = re.sub(r'\b' + re.escape(key) + r'\b', f'`{key}`', description) + return description + +def parse_xml_file(xml_content, properties): + root = ET.fromstring(xml_content) + for prop in root.findall('property'): + name = prop.findtext('name') + if not name: + raise ValueError("Property 'name' is required but missing in XML.") + description = prop.findtext('description', '') + if not description: + raise ValueError(f"Property '{name}' is missing a description.") + tag = prop.findtext('tag', '') + if tag: + formatted_tag = '<br/>'.join(f'`{t.strip()}`' for t in tag.split(',')) + else: + formatted_tag = '' + + properties[name] = Property( + name=name, + value=prop.findtext('value', ''), + tag=formatted_tag, + description=wrap_config_keys_in_description( + ' '.join(description.split()).strip(), + properties + ) + ) + return properties + +def generate_markdown(properties): + markdown = f""" +## Ozone Configuration Keys +This page provides da comprehensive overview of the configuration keys available in Ozone. +### Configuration Keys +""" + + for prop in sorted(properties.values(), key=lambda p: p.name): + markdown += f""" +| **Name** | `{prop.name}` | +|:----------------|:----------------------------| +| **Value** | {prop.value} | +| **Tag** | {prop.tag} | +| **Description** | {prop.description} | +-------------------------------------------------------------------------------- Review Comment: Modified it to a single unified table with all configs. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
