Skip to content

Instantly share code, notes, and snippets.

@gabcoh
Forked from haakov/cmdline_converter.py
Last active December 17, 2019 20:57
Show Gist options
  • Save gabcoh/ffd8fb70b0fc6ec2c7b6d566c30f17ed to your computer and use it in GitHub Desktop.
Save gabcoh/ffd8fb70b0fc6ec2c7b6d566c30f17ed to your computer and use it in GitHub Desktop.
Standalone GNU Radio XML -> YAML block converter script
#
# Short script for converting GNU Radio XML blocks to YAML blocks
# without having to start GRC
#
# Please note that this program _WILL_ overwrite files.
#
# How to use:
# 1. Save this file to grc/converter/cmdline_converter.py
# 2. Navigate back to the GNU Radio project root
# 3. Run: python3 -m grc.converter.cmdline_converter [name.xml]
# 4. Your YAML file has been created, called [name.block.yml]
#
# You can also specify the output filename:
# python3 -m grc.converter.cmdline_converter [input.xml] [output.block.yml]
#
import sys
from gnuradio.grc.converter import block
if not (1 < len(sys.argv) < 4):
print("Navigate to the project root and run the following:")
print(" python3 -m grc.converter.cmdline_converter [input.xml]")
print("")
exit()
if len(sys.argv) == 3:
output = open(sys.argv[-1], "w")
input = block.from_xml(sys.argv[-2])
else:
output_filename = sys.argv[-1].split(".")[0] + ".block.yml"
output = open(output_filename, "w")
input = block.from_xml(sys.argv[-1])
block.dump(input, output)
print("Dumped to " + output_filename)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment