Skip to content

Instantly share code, notes, and snippets.

@PowerX-NOT
Created October 15, 2023 09:11
Show Gist options
  • Save PowerX-NOT/cd37177ee2d0ca12a47d9ebf7337154f to your computer and use it in GitHub Desktop.
Save PowerX-NOT/cd37177ee2d0ca12a47d9ebf7337154f to your computer and use it in GitHub Desktop.
import re
def convert_to_xml(input_string):
match = re.match(r'^(.+)@(.+)::(.+?)(?:/([^@]+))?$', input_string)
if match:
package, version, interface, instance = match.groups()
xml_string = f'''
<hal format="hidl">
<name>{package}</name>
<version>{version}</version>
<interface>
<name>{interface}</name>
{f'<instance>{instance}</instance>' if instance else ''}
</interface>
{f'<fqname>@{version}::{interface}/{instance}</fqname>' if instance else ''}
</hal>
'''
return xml_string.strip()
else:
return "Invalid input format"
# Example usage:
input_codes = """
android.hardware.audio.effect@6.0::IEffectsFactory/default
android.hardware.audio@6.0::IDevicesFactory/default
# ... (other codes)
vendor.xiaomi.hardware.misys@3.0::IMiSys/default
"""
# Split the input codes into a list and convert each one to XML
codes_list = input_codes.strip().split('\n')
xml_list = [convert_to_xml(code) for code in codes_list]
# Join the XML strings with proper spacing and indentation
result_xml = '\n'.join(xml_list)
# Write the result to a text file
output_file_path = 'output.txt'
with open(output_file_path, 'w') as output_file:
output_file.write(result_xml)
print(f"Result has been written to {output_file_path}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment