Skip to content

Instantly share code, notes, and snippets.

@haakov
Last active August 2, 2023 13:07
Show Gist options
  • Save haakov/4228ff6a14486641add538483093e86b to your computer and use it in GitHub Desktop.
Save haakov/4228ff6a14486641add538483093e86b 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 . 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)
@samhanie
Copy link

Hi,

I am trying your cmdline_converter.py and I am getting:

from . import block

ImportError: cannot import name 'block' from 'grc.converter' (unknown location)

Any advice appreciated.

Thanks,
Sam

@eddsalkield
Copy link

Try replacing

from . import block

with

from gnuradio.grc.converter import block

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment