summaryrefslogtreecommitdiff
path: root/gr-utils/python/modtool/cli/makeyaml.py
diff options
context:
space:
mode:
Diffstat (limited to 'gr-utils/python/modtool/cli/makeyaml.py')
-rw-r--r--gr-utils/python/modtool/cli/makeyaml.py37
1 files changed, 32 insertions, 5 deletions
diff --git a/gr-utils/python/modtool/cli/makeyaml.py b/gr-utils/python/modtool/cli/makeyaml.py
index 621d444958..8e38f9a3a0 100644
--- a/gr-utils/python/modtool/cli/makeyaml.py
+++ b/gr-utils/python/modtool/cli/makeyaml.py
@@ -24,14 +24,27 @@ from __future__ import print_function
from __future__ import absolute_import
from __future__ import unicode_literals
+import os
import click
-from ..core import get_block_candidates, ModToolMakeYAML
+try:
+ from gnuradio.blocktool import BlockHeaderParser
+ from gnuradio.blocktool.core.base import BlockToolException
+except ImportError:
+ have_blocktool = False
+else:
+ have_blocktool = True
+
+from ..core import get_block_candidates, ModToolMakeYAML, yaml_generator
from ..tools import SequenceCompleter
from .base import common_params, block_name, run, cli_input
@click.command('makeyaml', short_help=ModToolMakeYAML.description)
+@click.option('-b', '--blocktool', is_flag=True,
+ help='Use blocktool support to print yaml output. FILE PATH mandatory if used.')
+@click.option('-o', '--output', is_flag=True,
+ help='If given, a file with desired output format will be generated')
@common_params
@block_name
def cli(**kwargs):
@@ -42,10 +55,24 @@ def cli(**kwargs):
Note: This does not work on python blocks
"""
kwargs['cli'] = True
- self = ModToolMakeYAML(**kwargs)
- click.secho("GNU Radio module name identified: " + self.info['modname'], fg='green')
- get_pattern(self)
- run(self)
+ if kwargs['blocktool']:
+ kwargs['modtool'] = True
+ if kwargs['blockname'] is None:
+ raise BlockToolException('Missing argument FILE PATH with blocktool flag')
+ kwargs['file_path'] = os.path.abspath(kwargs['blockname'])
+ if os.path.isfile(kwargs['file_path']):
+ parse_yml = BlockHeaderParser(**kwargs)
+ parse_yml.run_blocktool()
+ parse_yml.cli = True
+ parse_yml.yaml = True
+ yaml_generator(parse_yml, **kwargs)
+ else:
+ raise BlockToolException('Invalid file path.')
+ else:
+ self = ModToolMakeYAML(**kwargs)
+ click.secho("GNU Radio module name identified: " + self.info['modname'], fg='green')
+ get_pattern(self)
+ run(self)
def get_pattern(self):
""" Get the regex pattern for block(s) to be parsed """