[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Commit-gnuradio] [gnuradio] 02/04: modtool: Switched over to mako templ
From: |
git |
Subject: |
[Commit-gnuradio] [gnuradio] 02/04: modtool: Switched over to mako template engine |
Date: |
Tue, 29 Dec 2015 15:49:36 +0000 (UTC) |
This is an automated email from the git hooks/post-receive script.
jcorgan pushed a commit to branch next
in repository gnuradio.
commit 2dbbe486a51b8decc21566ceb0a5cb1c414eb499
Author: Martin Braun <address@hidden>
Date: Wed Oct 22 23:12:53 2014 +0200
modtool: Switched over to mako template engine
---
gr-utils/python/modtool/__init__.py | 3 +-
gr-utils/python/modtool/code_generator.py | 60 ++--
gr-utils/python/modtool/modtool_add.py | 32 +-
gr-utils/python/modtool/modtool_rename.py | 3 -
gr-utils/python/modtool/templates.py | 546 +++++++++++++++---------------
5 files changed, 304 insertions(+), 340 deletions(-)
diff --git a/gr-utils/python/modtool/__init__.py
b/gr-utils/python/modtool/__init__.py
index 0319b91..1bc841e 100644
--- a/gr-utils/python/modtool/__init__.py
+++ b/gr-utils/python/modtool/__init__.py
@@ -1,5 +1,5 @@
#
-# Copyright 2013 Free Software Foundation, Inc.
+# Copyright 2013-2014 Free Software Foundation, Inc.
#
# This file is part of GNU Radio
#
@@ -20,7 +20,6 @@
#
from cmakefile_editor import CMakeFileEditor
-from code_generator import GRMTemplate
from grc_xml_generator import GRCXMLGenerator
from modtool_base import ModTool, ModToolException, get_class_dict
from modtool_add import ModToolAdd
diff --git a/gr-utils/python/modtool/code_generator.py
b/gr-utils/python/modtool/code_generator.py
index 99f9176..326b2d5 100644
--- a/gr-utils/python/modtool/code_generator.py
+++ b/gr-utils/python/modtool/code_generator.py
@@ -1,5 +1,5 @@
#
-# Copyright 2013 Free Software Foundation, Inc.
+# Copyright 2013-2014 Free Software Foundation, Inc.
#
# This file is part of GNU Radio
#
@@ -20,39 +20,41 @@
#
""" A code generator (needed by ModToolAdd) """
+from mako.template import Template
from templates import Templates
-import Cheetah.Template
from util_functions import str_to_fancyc_comment
from util_functions import str_to_python_comment
from util_functions import strip_default_values
from util_functions import strip_arg_types
from util_functions import strip_arg_types_grc
-class GRMTemplate(Cheetah.Template.Template):
- """ An extended template class """
- def __init__(self, src, searchList):
- self.grtypelist = {
- 'sync': 'sync_block',
- 'sink': 'sync_block',
- 'source': 'sync_block',
- 'decimator': 'sync_decimator',
- 'interpolator': 'sync_interpolator',
- 'general': 'block',
- 'tagged_stream': 'tagged_stream_block',
- 'hier': 'hier_block2',
- 'noblock': ''}
- searchList['str_to_fancyc_comment'] = str_to_fancyc_comment
- searchList['str_to_python_comment'] = str_to_python_comment
- searchList['strip_default_values'] = strip_default_values
- searchList['strip_arg_types'] = strip_arg_types
- searchList['strip_arg_types_grc'] = strip_arg_types_grc
- Cheetah.Template.Template.__init__(self, src, searchList=searchList)
- self.grblocktype = self.grtypelist[searchList['blocktype']]
- if searchList['is_component']:
- self.include_dir_prefix = "gnuradio/" + searchList['modname']
- else:
- self.include_dir_prefix = searchList['modname']
+GRTYPELIST = {
+ 'sync': 'sync_block',
+ 'sink': 'sync_block',
+ 'source': 'sync_block',
+ 'decimator': 'sync_decimator',
+ 'interpolator': 'sync_interpolator',
+ 'general': 'block',
+ 'tagged_stream': 'tagged_stream_block',
+ 'hier': 'hier_block2',
+ 'noblock': ''
+}
+
+def render_template(tpl_id, **kwargs):
+ """ Return the parsed and rendered template given by tpl_id """
+ # Choose template
+ tpl = Template(Templates[tpl_id])
+ # Set up all variables
+ kwargs['str_to_fancyc_comment'] = str_to_fancyc_comment
+ kwargs['str_to_python_comment'] = str_to_python_comment
+ kwargs['strip_default_values'] = strip_default_values
+ kwargs['strip_arg_types'] = strip_arg_types
+ kwargs['strip_arg_types_grc'] = strip_arg_types_grc
+ kwargs['grblocktype'] = GRTYPELIST[kwargs['blocktype']]
+ if kwargs['is_component']:
+ kwargs['include_dir_prefix'] = "gnuradio/" + kwargs['modname']
+ else:
+ kwargs['include_dir_prefix'] = kwargs['modname']
+ # Render and return
+ return tpl.render(**kwargs)
-def get_template(tpl_id, **kwargs):
- """ Return the template given by tpl_id, parsed through Cheetah """
- return str(GRMTemplate(Templates[tpl_id], searchList=kwargs))
diff --git a/gr-utils/python/modtool/modtool_add.py
b/gr-utils/python/modtool/modtool_add.py
index a4812c8..75d4d6d 100644
--- a/gr-utils/python/modtool/modtool_add.py
+++ b/gr-utils/python/modtool/modtool_add.py
@@ -1,5 +1,5 @@
#
-# Copyright 2013 Free Software Foundation, Inc.
+# Copyright 2013-2014 Free Software Foundation, Inc.
#
# This file is part of GNU Radio
#
@@ -28,9 +28,7 @@ from util_functions import append_re_line_sequence, ask_yes_no
from cmakefile_editor import CMakeFileEditor
from modtool_base import ModTool, ModToolException
from templates import Templates
-from code_generator import get_template
-import Cheetah.Template
-
+from code_generator import render_template
class ModToolAdd(ModTool):
""" Add block to the out-of-tree module. """
@@ -146,7 +144,7 @@ class ModToolAdd(ModTool):
""" Shorthand for writing a substituted template to a file"""
path_to_file = os.path.join(path, fname)
print "Adding file '%s'..." % path_to_file
- open(path_to_file, 'w').write(get_template(tpl, **self._info))
+ open(path_to_file, 'w').write(render_template(tpl, **self._info))
self.scm.add_files((path_to_file,))
def run(self):
@@ -199,26 +197,6 @@ class ModToolAdd(ModTool):
self.scm.mark_files_updated((self._file['qalib'],))
except IOError:
print "Can't add C++ QA files."
- def _add_qa36():
- " Add C++ QA files for pre-3.7 API (not autotools) "
- fname_qa_cc = 'qa_%s.cc' % self._info['fullblockname']
- self._write_tpl('qa_cpp36', 'lib', fname_qa_cc)
- if not self._skip_cmakefiles:
- open(self._file['cmlib'], 'a').write(
- str(
- Cheetah.Template.Template(
- Templates['qa_cmakeentry36'],
- searchList={'basename':
os.path.splitext(fname_qa_cc)[0],
- 'upperbasename':
os.path.splitext(fname_qa_cc)[0].upper(),
- 'filename': fname_qa_cc,
- 'modname': self._info['modname']
- }
- )
- )
- )
- ed = CMakeFileEditor(self._file['cmlib'])
- ed.remove_double_newlines()
- ed.write()
fname_cc = None
fname_h = None
if self._info['version'] == '37':
@@ -239,7 +217,7 @@ class ModToolAdd(ModTool):
if self._info['version'] == '37':
_add_qa()
elif self._info['version'] == '36':
- _add_qa36()
+ print "Warning: C++ QA files not supported for 3.6-style OOTs."
elif self._info['version'] == 'autofoo':
print "Warning: C++ QA files not supported for autotools."
if not self._skip_cmakefiles:
@@ -264,7 +242,7 @@ class ModToolAdd(ModTool):
mod_block_sep = '/'
if self._info['version'] == '36':
mod_block_sep = '_'
- swig_block_magic_str = get_template('swig_block_magic', **self._info)
+ swig_block_magic_str = render_template('swig_block_magic',
**self._info)
open(self._file['swig'], 'a').write(swig_block_magic_str)
include_str = '#include "%s%s%s.h"' % (
{True: 'gnuradio/' + self._info['modname'], False:
self._info['modname']}[self._info['is_component']],
diff --git a/gr-utils/python/modtool/modtool_rename.py
b/gr-utils/python/modtool/modtool_rename.py
index 8f1b250..e815073 100644
--- a/gr-utils/python/modtool/modtool_rename.py
+++ b/gr-utils/python/modtool/modtool_rename.py
@@ -28,9 +28,6 @@ from util_functions import append_re_line_sequence, ask_yes_no
from cmakefile_editor import CMakeFileEditor
from modtool_base import ModTool, ModToolException
from templates import Templates
-from code_generator import get_template
-import Cheetah.Template
-
class ModToolRename(ModTool):
""" Add block to the out-of-tree module. """
diff --git a/gr-utils/python/modtool/templates.py
b/gr-utils/python/modtool/templates.py
index dc840df..2e222e2 100644
--- a/gr-utils/python/modtool/templates.py
+++ b/gr-utils/python/modtool/templates.py
@@ -1,5 +1,5 @@
#
-# Copyright 2013 Free Software Foundation, Inc.
+# Copyright 2013-2014 Free Software Foundation, Inc.
#
# This file is part of GNU Radio
#
@@ -26,7 +26,7 @@ Templates = {}
# Default licence
Templates['defaultlicense'] = '''
-Copyright %d <+YOU OR YOUR COMPANY+>.
+Copyright {0} <+YOU OR YOUR COMPANY+>.
This is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -42,10 +42,10 @@ You should have received a copy of the GNU General Public
License
along with this software; see the file COPYING. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street,
Boston, MA 02110-1301, USA.
-''' % datetime.now().year
+'''.format(datetime.now().year)
Templates['grlicense'] = '''
-Copyright %d Free Software Foundation, Inc.
+Copyright {0} Free Software Foundation, Inc.
This file is part of GNU Radio
@@ -63,15 +63,15 @@ You should have received a copy of the GNU General Public
License
along with GNU Radio; see the file COPYING. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street,
Boston, MA 02110-1301, USA.
-''' % datetime.now().year
+'''.format(datetime.now().year)
# Header file of a sync/decimator/interpolator block
Templates['block_impl_h'] = '''/* -*- c++ -*- */
-${str_to_fancyc_comment($license)}
-\#ifndef INCLUDED_${modname.upper()}_${blockname.upper()}_IMPL_H
-\#define INCLUDED_${modname.upper()}_${blockname.upper()}_IMPL_H
+${str_to_fancyc_comment(license)}
+#ifndef INCLUDED_${modname.upper()}_${blockname.upper()}_IMPL_H
+#define INCLUDED_${modname.upper()}_${blockname.upper()}_IMPL_H
-\#include <${include_dir_prefix}/${blockname}.h>
+#include <${include_dir_prefix}/${blockname}.h>
namespace gr {
namespace ${modname} {
@@ -81,112 +81,118 @@ namespace gr {
private:
// Nothing to declare in this block.
-#if $blocktype == 'tagged_stream'
+% if blocktype == 'tagged_stream':
protected:
int calculate_output_stream_length(const gr_vector_int &ninput_items);
-#end if
+% endif
public:
- ${blockname}_impl(${strip_default_values($arglist)});
+ ${blockname}_impl(${strip_default_values(arglist)});
~${blockname}_impl();
// Where all the action really happens
-#if $blocktype == 'general'
+% if blocktype == 'general':
void forecast (int noutput_items, gr_vector_int &ninput_items_required);
int general_work(int noutput_items,
gr_vector_int &ninput_items,
gr_vector_const_void_star &input_items,
gr_vector_void_star &output_items);
-#else if $blocktype == 'tagged_stream'
- int work(int noutput_items,
- gr_vector_int &ninput_items,
- gr_vector_const_void_star &input_items,
- gr_vector_void_star &output_items);
-#else if $blocktype == 'hier'
-#silent pass
-#else
- int work(int noutput_items,
- gr_vector_const_void_star &input_items,
- gr_vector_void_star &output_items);
-#end if
+
+% elif blocktype == 'tagged_stream':
+ int work(
+ int noutput_items,
+ gr_vector_int &ninput_items,
+ gr_vector_const_void_star &input_items,
+ gr_vector_void_star &output_items
+ );
+% elif blocktype == 'hier':
+% else:
+ int work(
+ int noutput_items,
+ gr_vector_const_void_star &input_items,
+ gr_vector_void_star &output_items
+ );
+% endif
};
} // namespace ${modname}
} // namespace gr
-\#endif /* INCLUDED_${modname.upper()}_${blockname.upper()}_IMPL_H */
+#endif /* INCLUDED_${modname.upper()}_${blockname.upper()}_IMPL_H */
'''
# C++ file of a GR block
Templates['block_impl_cpp'] = '''/* -*- c++ -*- */
-${str_to_fancyc_comment($license)}
-\#ifdef HAVE_CONFIG_H
-\#include "config.h"
-\#endif
-
-\#include <gnuradio/io_signature.h>
-#if $blocktype == 'noblock'
-\#include <${include_dir_prefix}/${blockname}.h>
-#else
-\#include "${blockname}_impl.h"
-#end if
+${str_to_fancyc_comment(license)}
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <gnuradio/io_signature.h>
+% if blocktype == 'noblock':
+#include <${include_dir_prefix}/${blockname}.h>
+% else:
+#include "${blockname}_impl.h"
+% endif
namespace gr {
namespace ${modname} {
-#if $blocktype == 'noblock'
- $blockname::${blockname}(${strip_default_values($arglist)})
+% if blocktype == 'noblock':
+ ${blockname}::${blockname}(${strip_default_values(arglist)})
{
}
- $blockname::~${blockname}()
+ ${blockname}::~${blockname}()
{
}
-#else
+% else:
${blockname}::sptr
- ${blockname}::make(${strip_default_values($arglist)})
+ ${blockname}::make(${strip_default_values(arglist)})
{
return gnuradio::get_initial_sptr
- (new ${blockname}_impl(${strip_arg_types($arglist)}));
+ (new ${blockname}_impl(${strip_arg_types(arglist)}));
}
-#if $blocktype == 'decimator'
-#set $decimation = ', <+decimation+>'
-#else if $blocktype == 'interpolator'
-#set $decimation = ', <+interpolation+>'
-#else if $blocktype == 'tagged_stream'
-#set $decimation = ', <+len_tag_key+>'
-#else
-#set $decimation = ''
-#end if
-#if $blocktype == 'source'
-#set $inputsig = '0, 0, 0'
-#else
-#set $inputsig = '<+MIN_IN+>, <+MAX_IN+>, sizeof(<+ITYPE+>)'
-#end if
-#if $blocktype == 'sink'
-#set $outputsig = '0, 0, 0'
-#else
-#set $outputsig = '<+MIN_OUT+>, <+MAX_OUT+>, sizeof(<+OTYPE+>)'
-#end if
+<%
+ if blocktype == 'decimator':
+ decimation = ', <+decimation+>'
+ elif blocktype == 'interpolator':
+ decimation = ', <+interpolation+>'
+ elif blocktype == 'tagged_stream':
+ decimation = ', <+len_tag_key+>'
+ else:
+ decimation = ''
+ endif
+ if blocktype == 'source':
+ inputsig = '0, 0, 0'
+ else:
+ inputsig = '<+MIN_IN+>, <+MAX_IN+>, sizeof(<+ITYPE+>)'
+ endif
+ if blocktype == 'sink':
+ outputsig = '0, 0, 0'
+ else:
+ outputsig = '<+MIN_OUT+>, <+MAX_OUT+>, sizeof(<+OTYPE+>)'
+ endif
+%>
/*
* The private constructor
*/
- ${blockname}_impl::${blockname}_impl(${strip_default_values($arglist)})
+ ${blockname}_impl::${blockname}_impl(${strip_default_values(arglist)})
: gr::${grblocktype}("${blockname}",
- gr::io_signature::make($inputsig),
- gr::io_signature::make($outputsig)$decimation)
-#if $blocktype == 'hier'
+ gr::io_signature::make(${inputsig}),
+ gr::io_signature::make(${outputsig})${decimation})
+ % if blocktype == 'hier':
{
connect(self(), 0, d_firstblock, 0);
// connect other blocks
connect(d_lastblock, 0, self(), 0);
}
-#else
+ % else:
{}
-#end if
+ % endif
/*
* Our virtual destructor.
@@ -195,7 +201,7 @@ namespace gr {
{
}
-#if $blocktype == 'general'
+ % if blocktype == 'general':
void
${blockname}_impl::forecast (int noutput_items, gr_vector_int
&ninput_items_required)
{
@@ -219,7 +225,7 @@ namespace gr {
// Tell runtime system how many output items we produced.
return noutput_items;
}
-#else if $blocktype == 'tagged_stream'
+ % elif blocktype == 'tagged_stream':
int
${blockname}_impl::calculate_output_stream_length(const gr_vector_int
&ninput_items)
{
@@ -241,32 +247,27 @@ namespace gr {
// Tell runtime system how many output items we produced.
return noutput_items;
}
-#else if $blocktype == 'hier'
-#silent pass
-#else
+ % elif blocktype == 'hier':
+ % else:
int
${blockname}_impl::work(int noutput_items,
gr_vector_const_void_star &input_items,
gr_vector_void_star &output_items)
{
-#if $blocktype == 'source'
-#silent pass
-#else
+ % if blocktype != 'source':
const <+ITYPE+> *in = (const <+ITYPE+> *) input_items[0];
-#end if
-#if $blocktype == 'sink'
-#silent pass
-#else
+ % endif
+ % if blocktype != 'sink':
<+OTYPE+> *out = (<+OTYPE+> *) output_items[0];
-#end if
+ % endif
// Do <+signal processing+>
// Tell runtime system how many output items we produced.
return noutput_items;
}
-#end if
-#end if
+ % endif
+% endif
} /* namespace ${modname} */
} /* namespace gr */
@@ -275,38 +276,38 @@ namespace gr {
# Block definition header file (for include/)
Templates['block_def_h'] = '''/* -*- c++ -*- */
-${str_to_fancyc_comment($license)}
+${str_to_fancyc_comment(license)}
-\#ifndef INCLUDED_${modname.upper()}_${blockname.upper()}_H
-\#define INCLUDED_${modname.upper()}_${blockname.upper()}_H
+#ifndef INCLUDED_${modname.upper()}_${blockname.upper()}_H
+#define INCLUDED_${modname.upper()}_${blockname.upper()}_H
-\#include <${include_dir_prefix}/api.h>
-#if $blocktype != 'noblock'
-\#include <gnuradio/${grblocktype}.h>
-#end if
+#include <${include_dir_prefix}/api.h>
+% if blocktype != 'noblock':
+#include <gnuradio/${grblocktype}.h>
+% endif
namespace gr {
namespace ${modname} {
-#if $blocktype == 'noblock'
+% if blocktype == 'noblock':
/*!
* \\brief <+description+>
*
*/
- class ${modname.upper()}_API $blockname
+ class ${modname.upper()}_API ${blockname}
{
public:
${blockname}(${arglist});
~${blockname}();
private:
};
-#else
+% else:
/*!
* \\brief <+description of block+>
* \ingroup ${modname}
*
*/
- class ${modname.upper()}_API ${blockname} : virtual public gr::$grblocktype
+ class ${modname.upper()}_API ${blockname} : virtual public
gr::${grblocktype}
{
public:
typedef boost::shared_ptr<${blockname}> sptr;
@@ -319,85 +320,94 @@ namespace gr {
* class. ${modname}::${blockname}::make is the public interface for
* creating new instances.
*/
- static sptr make($arglist);
+ static sptr make(${arglist});
};
-#end if
+% endif
} // namespace ${modname}
} // namespace gr
-\#endif /* INCLUDED_${modname.upper()}_${blockname.upper()}_H */
+#endif /* INCLUDED_${modname.upper()}_${blockname.upper()}_H */
'''
# Python block
-Templates['block_python'] = '''\#!/usr/bin/env python
+Templates['block_python'] = '''#!/usr/bin/env python
# -*- coding: utf-8 -*-
-${str_to_python_comment($license)}
-#
-#if $blocktype == 'noblock'
-#stop
-#end if
-
-#if $blocktype in ('sync', 'sink', 'source')
-#set $parenttype = 'gr.sync_block'
-#else
-#set $parenttype = {'hier': 'gr.hier_block2', 'interpolator':
'gr.interp_block', 'decimator': 'gr.decim_block', 'general':
'gr.basic_block'}[$blocktype]
-#end if
-#if $blocktype != 'hier'
-import numpy
-#if $blocktype == 'source'
-#set $inputsig = 'None'
-#else
-#set $inputsig = '[<+numpy.float+>]'
-#end if
-#if $blocktype == 'sink'
-#set $outputsig = 'None'
-#else
-#set $outputsig = '[<+numpy.float+>]'
-#end if
-#else
-#if $blocktype == 'source'
-#set $inputsig = '0, 0, 0'
-#else
-#set $inputsig = '<+MIN_IN+>, <+MAX_IN+>, gr.sizeof_<+ITYPE+>'
-#end if
-#if $blocktype == 'sink'
-#set $outputsig = '0, 0, 0'
-#else
-#set $outputsig = '<+MIN_OUT+>, <+MAX_OUT+>, gr.sizeof_<+OTYPE+>'
-#end if
-#end if
-#if $blocktype == 'interpolator'
-#set $deciminterp = ', <+interpolation+>'
-#else if $blocktype == 'decimator'
-#set $deciminterp = ', <+decimation+>'
-#else
-#set $deciminterp = ''
-#end if
-from gnuradio import gr
+${str_to_python_comment(license)}
+#\
+<%
+ if blocktype == 'noblock':
+ return
+ if blocktype in ('sync', 'sink', 'source'):
+ parenttype = 'gr.sync_block'
+ else:
+ parenttype = {
+ 'hier': 'gr.hier_block2',
+ 'interpolator': 'gr.interp_block',
+ 'decimator': 'gr.decim_block',
+ 'general': 'gr.basic_block'
+ }[blocktype]
+%>
+% if blocktype != 'hier':
+
+import numpy\
+<%
+ if blocktype == 'source':
+ inputsig = 'None'
+ else:
+ inputsig = '[<+numpy.float32+>]'
+ if blocktype == 'sink':
+ outputsig = 'None'
+ else:
+ outputsig = '[<+numpy.float32+>]'
+%>
+% else:
+<%
+ if blocktype == 'source':
+ inputsig = '0, 0, 0'
+ else:
+ inputsig = '<+MIN_IN+>, <+MAX_IN+>, gr.sizeof_<+ITYPE+>'
+ if blocktype == 'sink':
+ outputsig = '0, 0, 0'
+ else:
+ outputsig = '<+MIN_OUT+>, <+MAX_OUT+>, gr.sizeof_<+OTYPE+>'
+%>
+% endif
+<%
+ if blocktype == 'interpolator':
+ deciminterp = ', <+interpolation+>'
+ elif blocktype == 'decimator':
+ deciminterp = ', <+decimation+>'
+ else:
+ deciminterp = ''
+ if arglist == '':
+ arglistsep = ''
+ else:
+ arglistsep = ', '
+%>from gnuradio import gr
class ${blockname}(${parenttype}):
"""
docstring for block ${blockname}
"""
- def __init__(self#if $arglist == '' then '' else ', '#$arglist):
+ def __init__(self${arglistsep}${arglist}):
${parenttype}.__init__(self,
-#if $blocktype == 'hier'
- "$blockname",
+% if blocktype == 'hier':
+ "${blockname}",
gr.io_signature(${inputsig}), # Input signature
gr.io_signature(${outputsig})) # Output signature
# Define blocks and connect them
self.connect()
-#stop
-#else
+<% return %>
+% else:
name="${blockname}",
in_sig=${inputsig},
out_sig=${outputsig}${deciminterp})
-#end if
+% endif
-#if $blocktype == 'general'
+% if blocktype == 'general':
def forecast(self, noutput_items, ninput_items_required):
#setup size of input_items[i] for work call
for i in range(len(ninput_items_required)):
@@ -408,37 +418,37 @@ class ${blockname}(${parenttype}):
consume(0, len(input_items[0]))
\#self.consume_each(len(input_items[0]))
return len(output_items[0])
-#stop
-#end if
+<% return %>
+% endif
def work(self, input_items, output_items):
-#if $blocktype != 'source'
+% if blocktype != 'source':
in0 = input_items[0]
-#end if
-#if $blocktype != 'sink'
+% endif
+% if blocktype != 'sink':
out = output_items[0]
-#end if
+% endif
# <+signal processing here+>
-#if $blocktype in ('sync', 'decimator', 'interpolator')
+% if blocktype in ('sync', 'decimator', 'interpolator'):
out[:] = in0
return len(output_items[0])
-#else if $blocktype == 'sink'
+% elif blocktype == 'sink':
return len(input_items[0])
-#else if $blocktype == 'source'
+% elif blocktype == 'source':
out[:] = whatever
return len(output_items[0])
-#end if
+% endif
'''
# C++ file for QA
Templates['qa_cpp'] = '''/* -*- c++ -*- */
-${str_to_fancyc_comment($license)}
+${str_to_fancyc_comment(license)}
-\#include <gnuradio/attributes.h>
-\#include <cppunit/TestAssert.h>
-\#include "qa_${blockname}.h"
-\#include <${include_dir_prefix}/${blockname}.h>
+#include <gnuradio/attributes.h>
+#include <cppunit/TestAssert.h>
+#include "qa_${blockname}.h"
+#include <${include_dir_prefix}/${blockname}.h>
namespace gr {
namespace ${modname} {
@@ -456,13 +466,13 @@ namespace gr {
# Header file for QA
Templates['qa_h'] = '''/* -*- c++ -*- */
-${str_to_fancyc_comment($license)}
+${str_to_fancyc_comment(license)}
-\#ifndef _QA_${blockname.upper()}_H_
-\#define _QA_${blockname.upper()}_H_
+#ifndef _QA_${blockname.upper()}_H_
+#define _QA_${blockname.upper()}_H_
-\#include <cppunit/extensions/HelperMacros.h>
-\#include <cppunit/TestCase.h>
+#include <cppunit/extensions/HelperMacros.h>
+#include <cppunit/TestCase.h>
namespace gr {
namespace ${modname} {
@@ -481,25 +491,25 @@ namespace gr {
} /* namespace ${modname} */
} /* namespace gr */
-\#endif /* _QA_${blockname.upper()}_H_ */
+#endif /* _QA_${blockname.upper()}_H_ */
'''
# Python QA code
-Templates['qa_python'] = '''\#!/usr/bin/env python
+Templates['qa_python'] = '''#!/usr/bin/env python
# -*- coding: utf-8 -*-
-${str_to_python_comment($license)}
+${str_to_python_comment(license)}
#
from gnuradio import gr, gr_unittest
from gnuradio import blocks
-#if $lang == 'cpp'
+% if lang == 'cpp':
import ${modname}_swig as ${modname}
-#else
+% else:
from ${blockname} import ${blockname}
-#end if
+% endif
-class qa_$blockname (gr_unittest.TestCase):
+class qa_${blockname} (gr_unittest.TestCase):
def setUp (self):
self.tb = gr.top_block ()
@@ -519,11 +529,11 @@ if __name__ == '__main__':
Templates['grc_xml'] = '''<?xml version="1.0"?>
<block>
- <name>$blockname</name>
- <key>${modname}_$blockname</key>
- <category>$modname</category>
- <import>import $modname</import>
- <make>${modname}.${blockname}(${strip_arg_types_grc($arglist)})</make>
+ <name>${blockname}</name>
+ <key>${modname}_${blockname}</key>
+ <category>${modname}</category>
+ <import>import ${modname}</import>
+ <make>${modname}.${blockname}(${strip_arg_types_grc(arglist)})</make>
<!-- Make one 'param' node for every Parameter you want settable from the
GUI.
Sub-nodes:
* name
@@ -564,80 +574,85 @@ gr_modtool help -- Show a list of commands.
gr_modtool help <command> -- Shows the help for a given command. '''
# SWIG string
-Templates['swig_block_magic'] = """#if $version == '36'
-#if $blocktype != 'noblock'
-GR_SWIG_BLOCK_MAGIC($modname, $blockname);
-#end if
-%include "${modname}_${blockname}.h"
-#else
-%include "${include_dir_prefix}/${blockname}.h"
-#if $blocktype != 'noblock'
-GR_SWIG_BLOCK_MAGIC2($modname, $blockname);
-#end if
-#end if
+Templates['swig_block_magic'] = """% if version == '36':
+% if blocktype != 'noblock':
+GR_SWIG_BLOCK_MAGIC(${modname}, ${blockname});
+% endif
+%%include "${modname}_${blockname}.h"
+% else:
+%%include "${include_dir_prefix}/${blockname}.h"
+ % if blocktype != 'noblock':
+GR_SWIG_BLOCK_MAGIC2(${modname}, ${blockname});
+ % endif
+% endif
"""
## Old stuff
# C++ file of a GR block
Templates['block_cpp36'] = '''/* -*- c++ -*- */
-${str_to_fancyc_comment($license)}
-\#ifdef HAVE_CONFIG_H
-\#include "config.h"
-\#endif
-
-#if $blocktype != 'noblock'
-\#include <gr_io_signature.h>
-#end if
-\#include "${modname}_${blockname}.h"
-
-#if $blocktype == 'noblock'
-${modname}_${blockname}::${modname}_${blockname}(${strip_default_values($arglist)})
+${str_to_fancyc_comment(license)}
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+% if blocktype != 'noblock':
+#include <gr_io_signature.h>
+% endif
+#include "${modname}_${blockname}.h"
+
+% if blocktype == 'noblock':
+${modname}_${blockname}::${modname}_${blockname}(${strip_default_values(arglist)})
{
}
${modname}_${blockname}::~${modname}_${blockname}()
{
}
-#else
+% else:
${modname}_${blockname}_sptr
-${modname}_make_${blockname} (${strip_default_values($arglist)})
+${modname}_make_${blockname} (${strip_default_values(arglist)})
{
- return gnuradio::get_initial_sptr (new
${modname}_${blockname}(${strip_arg_types($arglist)}));
+ return gnuradio::get_initial_sptr (new
${modname}_${blockname}(${strip_arg_types(arglist)}));
}
-#if $blocktype == 'decimator'
-#set $decimation = ', <+decimation+>'
-#else if $blocktype == 'interpolator'
-#set $decimation = ', <+interpolation+>'
-#else
-#set $decimation = ''
-#end if
-#if $blocktype == 'sink'
-#set $inputsig = '0, 0, 0'
-#else
-#set $inputsig = '<+MIN_IN+>, <+MAX_IN+>, sizeof(<+ITYPE+>)'
-#end if
-#if $blocktype == 'source'
-#set $outputsig = '0, 0, 0'
-#else
-#set $outputsig = '<+MIN_OUT+>, <+MAX_OUT+>, sizeof(<+OTYPE+>)'
-#end if
+<%
+ if blocktype == 'interpolator':
+ deciminterp = ', <+interpolation+>'
+ elif blocktype == 'decimator':
+ deciminterp = ', <+decimation+>'
+ else:
+ deciminterp = ''
+ if arglist == '':
+ arglistsep = ''
+ else:
+ arglistsep = ', '
+ if blocktype == 'source':
+ inputsig = '0, 0, 0'
+ else:
+ inputsig = '<+MIN_IN+>, <+MAX_IN+>, sizeof(<+ITYPE+>)'
+ endif
+ if blocktype == 'sink':
+ outputsig = '0, 0, 0'
+ else:
+ outputsig = '<+MIN_OUT+>, <+MAX_OUT+>, sizeof(<+OTYPE+>)'
+ endif
+%>
/*
* The private constructor
*/
-${modname}_${blockname}::${modname}_${blockname}
(${strip_default_values($arglist)})
+${modname}_${blockname}::${modname}_${blockname}
(${strip_default_values(arglist)})
: gr_${grblocktype} ("${blockname}",
- gr_make_io_signature($inputsig),
- gr_make_io_signature($outputsig)$decimation)
+ gr_make_io_signature(${inputsig}),
+ gr_make_io_signature(${outputsig})${deciminterp})
{
-#if $blocktype == 'hier'
+% if blocktype == 'hier'
connect(self(), 0, d_firstblock, 0);
// <+connect other blocks+>
connect(d_lastblock, 0, self(), 0);
-#else
+% else:
// Put in <+constructor stuff+> here
-#end if
+% endif
}
@@ -648,10 +663,10 @@ ${modname}_${blockname}::~${modname}_${blockname}()
{
// Put in <+destructor stuff+> here
}
-#end if
+% endif
-#if $blocktype == 'general'
+% if blocktype == 'general'
void
${modname}_${blockname}::forecast (int noutput_items, gr_vector_int
&ninput_items_required)
{
@@ -675,9 +690,8 @@ ${modname}_${blockname}::general_work (int noutput_items,
// Tell runtime system how many output items we produced.
return noutput_items;
}
-#else if $blocktype == 'hier' or $blocktype == 'noblock'
-#pass
-#else
+% elif blocktype == 'hier' or $blocktype == 'noblock':
+% else:
int
${modname}_${blockname}::work(int noutput_items,
gr_vector_const_void_star &input_items,
@@ -691,51 +705,51 @@ ${modname}_${blockname}::work(int noutput_items,
// Tell runtime system how many output items we produced.
return noutput_items;
}
-#end if
+% endif
'''
# Block definition header file (for include/)
Templates['block_h36'] = '''/* -*- c++ -*- */
-${str_to_fancyc_comment($license)}
+${str_to_fancyc_comment(license)}
-\#ifndef INCLUDED_${modname.upper()}_${blockname.upper()}_H
-\#define INCLUDED_${modname.upper()}_${blockname.upper()}_H
+#ifndef INCLUDED_${modname.upper()}_${blockname.upper()}_H
+#define INCLUDED_${modname.upper()}_${blockname.upper()}_H
-\#include <${modname}_api.h>
-#if $blocktype == 'noblock'
-class ${modname.upper()}_API $blockname
+#include <${modname}_api.h>
+% if blocktype == 'noblock'
+class ${modname.upper()}_API ${blockname}
{
${blockname}(${arglist});
~${blockname}();
private:
};
-#else
-\#include <gr_${grblocktype}.h>
+% else:
+#include <gr_${grblocktype}.h>
class ${modname}_${blockname};
typedef boost::shared_ptr<${modname}_${blockname}>
${modname}_${blockname}_sptr;
-${modname.upper()}_API ${modname}_${blockname}_sptr
${modname}_make_${blockname} ($arglist);
+${modname.upper()}_API ${modname}_${blockname}_sptr
${modname}_make_${blockname} (${arglist});
/*!
* \\brief <+description+>
* \ingroup ${modname}
*
*/
-class ${modname.upper()}_API ${modname}_${blockname} : public gr_$grblocktype
+class ${modname.upper()}_API ${modname}_${blockname} : public gr_${grblocktype}
{
private:
- friend ${modname.upper()}_API ${modname}_${blockname}_sptr
${modname}_make_${blockname} (${strip_default_values($arglist)});
+ friend ${modname.upper()}_API ${modname}_${blockname}_sptr
${modname}_make_${blockname} (${strip_default_values(arglist)});
- ${modname}_${blockname}(${strip_default_values($arglist)});
+ ${modname}_${blockname}(${strip_default_values(arglist)});
public:
~${modname}_${blockname}();
-#if $blocktype == 'general'
+ % if blocktype == 'general':
void forecast (int noutput_items, gr_vector_int &ninput_items_required);
// Where all the action really happens
@@ -743,43 +757,17 @@ class ${modname.upper()}_API ${modname}_${blockname} :
public gr_$grblocktype
gr_vector_int &ninput_items,
gr_vector_const_void_star &input_items,
gr_vector_void_star &output_items);
-#else if $blocktype == 'hier'
-#pass
-#else
+ % elif blocktype == 'hier':
+ % else:
// Where all the action really happens
int work (int noutput_items,
gr_vector_const_void_star &input_items,
gr_vector_void_star &output_items);
-#end if
+ % endif
};
-#end if
+% endif
-\#endif /* INCLUDED_${modname.upper()}_${blockname.upper()}_H */
+#endif /* INCLUDED_${modname.upper()}_${blockname.upper()}_H */
'''
-# C++ file for QA
-Templates['qa_cpp36'] = '''/* -*- c++ -*- */
-${str_to_fancyc_comment($license)}
-
-\#include <boost/test/unit_test.hpp>
-
-BOOST_AUTO_TEST_CASE(qa_${modname}_${blockname}_t1){
- BOOST_CHECK_EQUAL(2 + 2, 4);
- // TODO BOOST_* test macros here
-}
-
-BOOST_AUTO_TEST_CASE(qa_${modname}_${blockname}_t2){
- BOOST_CHECK_EQUAL(2 + 2, 4);
- // TODO BOOST_* test macros here
-}
-
-'''
-
-# Header file for QA
-Templates['qa_cmakeentry36'] = """
-add_executable($basename $filename)
-target_link_libraries($basename gnuradio-$modname \${Boost_LIBRARIES})
-GR_ADD_TEST($basename $basename)
-"""
-