summaryrefslogtreecommitdiff
path: root/gr-utils/python/modtool/modtool_makexml.py
diff options
context:
space:
mode:
Diffstat (limited to 'gr-utils/python/modtool/modtool_makexml.py')
-rw-r--r--gr-utils/python/modtool/modtool_makexml.py34
1 files changed, 21 insertions, 13 deletions
diff --git a/gr-utils/python/modtool/modtool_makexml.py b/gr-utils/python/modtool/modtool_makexml.py
index 777cc09e1f..28eabe1b81 100644
--- a/gr-utils/python/modtool/modtool_makexml.py
+++ b/gr-utils/python/modtool/modtool_makexml.py
@@ -20,32 +20,32 @@
#
""" Automatically create XML bindings for GRC from block code """
-import sys
import os
import re
import glob
-from optparse import OptionGroup
-from modtool_base import ModTool
+from modtool_base import ModTool, ModToolException
from parser_cc_block import ParserCCBlock
from grc_xml_generator import GRCXMLGenerator
from cmakefile_editor import CMakeFileEditor
from util_functions import ask_yes_no
+
class ModToolMakeXML(ModTool):
""" Make XML file for GRC block bindings """
name = 'makexml'
aliases = ('mx',)
+
def __init__(self):
ModTool.__init__(self)
- def setup(self):
- ModTool.setup(self)
- options = self.options
+ def setup(self, options, args):
+ ModTool.setup(self, options, args)
+
if options.block_name is not None:
self._info['pattern'] = options.block_name
- elif len(self.args) >= 2:
- self._info['pattern'] = self.args[1]
+ elif len(args) >= 2:
+ self._info['pattern'] = args[1]
else:
self._info['pattern'] = raw_input('Which blocks do you want to parse? (Regex): ')
if len(self._info['pattern']) == 0:
@@ -66,7 +66,7 @@ class ModToolMakeXML(ModTool):
(params, iosig, blockname) = self._parse_cc_h(f)
self._make_grc_xml_from_block_data(params, iosig, blockname)
# 2) Go through python/
-
+ # TODO
def _search_files(self, path, path_glob):
""" Search for files matching pattern in the given path. """
@@ -85,6 +85,7 @@ class ModToolMakeXML(ModTool):
generator. Also, check the makefile if the .xml file is in there.
If necessary, add. """
fname_xml = '%s_%s.xml' % (self._info['modname'], blockname)
+ path_to_xml = os.path.join('grc', fname_xml)
# Some adaptions for the GRC
for inout in ('in', 'out'):
if iosig[inout]['max_ports'] == '-1':
@@ -94,11 +95,13 @@ class ModToolMakeXML(ModTool):
'name': 'Num %sputs' % inout,
'default': '2',
'in_constructor': False})
- if os.path.isfile(os.path.join('grc', fname_xml)):
+ file_exists = False
+ if os.path.isfile(path_to_xml):
if not self._info['yes']:
if not ask_yes_no('Overwrite existing GRC file?', False):
return
else:
+ file_exists = True
print "Warning: Overwriting existing GRC file."
grc_generator = GRCXMLGenerator(
modname=self._info['modname'],
@@ -106,13 +109,18 @@ class ModToolMakeXML(ModTool):
params=params,
iosig=iosig
)
- grc_generator.save(os.path.join('grc', fname_xml))
+ grc_generator.save(path_to_xml)
+ if file_exists:
+ self.scm.mark_files_updated((path_to_xml,))
+ else:
+ self.scm.add_files((path_to_xml,))
if not self._skip_subdirs['grc']:
ed = CMakeFileEditor(self._file['cmgrc'])
if re.search(fname_xml, ed.cfile) is None and not ed.check_for_glob('*.xml'):
print "Adding GRC bindings to grc/CMakeLists.txt..."
ed.append_value('install', fname_xml, to_ignore_end='DESTINATION[^()]+')
ed.write()
+ self.scm.mark_files_updated(self._file['cmgrc'])
def _parse_cc_h(self, fname_cc):
""" Go through a .cc and .h-file defining a block and return info """
@@ -152,7 +160,7 @@ class ModToolMakeXML(ModTool):
_type_translate
)
except IOError:
- print "Can't open some of the files necessary to parse %s." % fname_cc
- sys.exit(1)
+ raise ModToolException("Can't open some of the files necessary to parse {}.".format(fname_cc))
+
return (parser.read_params(), parser.read_io_signature(), blockname)