summaryrefslogtreecommitdiff
path: root/gr-utils/modtool/core/bind.py
diff options
context:
space:
mode:
authorJosh Morman <mormjb@gmail.com>2020-04-23 15:03:55 -0400
committerJosh Morman <mormjb@gmail.com>2020-06-04 10:05:48 -0400
commit999c0e723240ee783bca17942f77a9d05bbfc168 (patch)
tree3661aeb0ef10bad228df014a20e5b0a63627c833 /gr-utils/modtool/core/bind.py
parenta4e6d4d55b35ac36dd5915dec5145073d8ec3b9a (diff)
utils: add functionality to generate bindings
This currently exists in two places 1) Bindtool (longevity TBD) which calls blocktool to parse the public header file in the include directory 2) Modtool - binding of headers added to add and bind. rm, update, info, etc still TODO
Diffstat (limited to 'gr-utils/modtool/core/bind.py')
-rw-r--r--gr-utils/modtool/core/bind.py65
1 files changed, 65 insertions, 0 deletions
diff --git a/gr-utils/modtool/core/bind.py b/gr-utils/modtool/core/bind.py
new file mode 100644
index 0000000000..b95178759c
--- /dev/null
+++ b/gr-utils/modtool/core/bind.py
@@ -0,0 +1,65 @@
+#
+# Copyright 2013, 2018, 2019 Free Software Foundation, Inc.
+#
+# This file is part of GNU Radio
+#
+# SPDX-License-Identifier: GPL-3.0-or-later
+#
+#
+""" Module to call bindtool and create Python bindings """
+
+
+from __future__ import print_function
+from __future__ import absolute_import
+from __future__ import unicode_literals
+
+import os
+import logging
+import warnings
+import subprocess
+
+try:
+ from gnuradio.bindtool import BindingGenerator
+except ImportError:
+ have_bindtool = False
+else:
+ have_bindtool = True
+
+from ..tools import ParserCCBlock, CMakeFileEditor, ask_yes_no
+from .base import ModTool, ModToolException
+
+from gnuradio import gr
+
+logger = logging.getLogger(__name__)
+
+class ModToolGenBindings(ModTool):
+ """ Make YAML file for GRC block bindings """
+ name = 'bind'
+ description = 'Generate Python bindings for GR block'
+
+ def __init__(self, blockname=None, **kwargs):
+ ModTool.__init__(self, blockname, **kwargs)
+ self.info['pattern'] = blockname
+
+ def validate(self):
+ """ Validates the arguments """
+ ModTool._validate(self)
+ if not self.info['pattern'] or self.info['pattern'].isspace():
+ raise ModToolException("Incorrect blockname (Regex)!")
+
+ def run(self):
+ """ Go, go, go! """
+ # This portion will be covered by the CLI
+ if not self.cli:
+ self.validate()
+ if not have_bindtool:
+ logger.error(
+ "Bindtool required to generate bindings ... Aborting")
+ return
+
+ with warnings.catch_warnings():
+ warnings.filterwarnings("ignore", category=DeprecationWarning)
+ file_to_process = os.path.join(self.dir, self.info['includedir'], self.info['blockname'] + '.h')
+ bg = BindingGenerator(prefix=gr.prefix(), namespace=[
+ 'gr', self.info['modname']], prefix_include_root=self.info['modname'], output_dir=os.path.join(self.dir, 'python'))
+ bg.gen_file_binding(file_to_process)