From a62f90d8cc96b9dea9289ad6e420d1c0b16f6c36 Mon Sep 17 00:00:00 2001 From: Martin Braun <martin.braun@kit.edu> Date: Thu, 24 Jan 2013 19:33:03 +0100 Subject: utils: added modtool --- gr-utils/src/python/modtool/templates.py | 698 +++++++++++++++++++++++++++++++ 1 file changed, 698 insertions(+) create mode 100644 gr-utils/src/python/modtool/templates.py (limited to 'gr-utils/src/python/modtool/templates.py') diff --git a/gr-utils/src/python/modtool/templates.py b/gr-utils/src/python/modtool/templates.py new file mode 100644 index 0000000000..e3019bb701 --- /dev/null +++ b/gr-utils/src/python/modtool/templates.py @@ -0,0 +1,698 @@ +''' All the templates for skeleton files (needed by ModToolAdd) ''' + +from datetime import datetime + +### Templates ################################################################ +Templates = {} +Templates36 = {} + +# Default licence +Templates['defaultlicense'] = ''' +Copyright %d <+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 +the Free Software Foundation; either version 3, or (at your option) +any later version. + +This software is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +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 + +# 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 + +\#include <${modname}/${blockname}.h> + +namespace gr { + namespace ${modname} { + + class ${blockname}_impl : public ${blockname} + { + private: + // Nothing to declare in this block. + + public: + ${blockname}_impl(${strip_default_values($arglist)}); + ~${blockname}_impl(); + +#if $blocktype == 'general' + void forecast (int noutput_items, gr_vector_int &ninput_items_required); + + // Where all the action really happens + 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 == 'hier' +#silent pass +#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 + }; + + } // namespace ${modname} +} // namespace gr + +\#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 <gr_io_signature.h> +#if $blocktype == 'noblock' +\#include <${modname}/${blockname}.h> +#else +\#include "${blockname}_impl.h" +#end if + +namespace gr { + namespace ${modname} { + +#if $blocktype == 'noblock' + $blockname::${blockname}(${strip_default_values($arglist)}) + { + } + + $blockname::~${blockname}() + { + } +#else + ${blockname}::sptr + ${blockname}::make(${strip_default_values($arglist)}) + { + return gnuradio::get_initial_sptr (new ${blockname}_impl(${strip_arg_types($arglist)})); + } + +#if $blocktype == 'decimator' +#set $decimation = ', <+decimation+>' +#else if $blocktype == 'interpolator' +#set $decimation = ', <+interpolation+>' +#else +#set $decimation = '' +#end if +#if $blocktype == 'source' +#set $inputsig = '0, 0, 0' +#else +#set $inputsig = '<+MIN_IN+>, <+MAX_IN+>, sizeof (<+float+>)' +#end if +#if $blocktype == 'sink' +#set $outputsig = '0, 0, 0' +#else +#set $outputsig = '<+MIN_IN+>, <+MAX_IN+>, sizeof (<+float+>)' +#end if + /* + * The private constructor + */ + ${blockname}_impl::${blockname}_impl(${strip_default_values($arglist)}) + : ${grblocktype}("${blockname}", + gr_make_io_signature($inputsig), + gr_make_io_signature($outputsig)$decimation) +#if $blocktype == 'hier' + { + connect(self(), 0, d_firstblock, 0); + // connect other blocks + connect(d_lastblock, 0, self(), 0); + } +#else + {} +#end if + + /* + * Our virtual destructor. + */ + ${blockname}_impl::~${blockname}_impl() + { + } + +#if $blocktype == 'general' + void + ${blockname}_impl::forecast (int noutput_items, gr_vector_int &ninput_items_required) + { + /* <+forecast+> e.g. ninput_items_required[0] = noutput_items */ + } + + int + ${blockname}_impl::general_work (int noutput_items, + gr_vector_int &ninput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items) + { + const float *in = (const float *) input_items[0]; + float *out = (float *) output_items[0]; + + // Do <+signal processing+> + // Tell runtime system how many input items we consumed on + // each input stream. + consume_each (noutput_items); + + // Tell runtime system how many output items we produced. + return noutput_items; + } +#else if $blocktype == 'hier' +#silent pass +#else + int + ${blockname}_impl::work(int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items) + { + const float *in = (const float *) input_items[0]; + float *out = (float *) output_items[0]; + + // Do <+signal processing+> + + // Tell runtime system how many output items we produced. + return noutput_items; + } +#end if +#end if + + } /* namespace ${modname} */ +} /* namespace gr */ + +''' + +# Block definition header file (for include/) +Templates['block_def_h'] = '''/* -*- c++ -*- */ +${str_to_fancyc_comment($license)} + +\#ifndef INCLUDED_${modname.upper()}_${blockname.upper()}_H +\#define INCLUDED_${modname.upper()}_${blockname.upper()}_H + +\#include <${modname}/api.h> +\#include <${grblocktype}.h> + +namespace gr { + namespace ${modname} { + +#if $blocktype == 'noblock' + /*! + * \\brief <+description+> + * + */ + class ${modname.upper()}_API $blockname + { + ${blockname}(${arglist}); + ~${blockname}(); + private: + }; +#else + /*! + * \\brief <+description of block+> + * \ingroup ${modname} + * + */ + class ${modname.upper()}_API ${blockname} : virtual public $grblocktype + { + public: + typedef boost::shared_ptr<${blockname}> sptr; + + /*! + * \\brief Return a shared_ptr to a new instance of ${modname}::${blockname}. + * + * To avoid accidental use of raw pointers, ${modname}::${blockname}'s + * constructor is in a private implementation + * class. ${modname}::${blockname}::make is the public interface for + * creating new instances. + */ + static sptr make($arglist); + }; +#end if + + } // namespace ${modname} +} // namespace gr + +\#endif /* INCLUDED_${modname.upper()}_${blockname.upper()}_H */ + +''' + +# Python block (from grextras!) +Templates['block_python'] = '''\#!/usr/bin/env python +${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.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_<+float+>' +#end if +#if $blocktype == 'sink' +#set $outputsig = '0, 0, 0' +#else +#set $outputsig = '<+MIN_OUT+>, <+MAX_OUT+>, gr.sizeof_<+float+>' +#end if +#end if +#if $blocktype == 'interpolator' +#set $deciminterp = ', <+interpolation+>' +#else if $blocktype == 'decimator' +#set $deciminterp = ', <+decimation+>' +#set $deciminterp = '' +#else +#end if +from gnuradio import gr + +class ${blockname}(${parenttype}): + """ + docstring for block ${blockname} + """ + def __init__(self#if $arglist == '' then '' else ', '#$arglist): + gr.${parenttype}.__init__(self, +#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 + name="${blockname}", + in_sig=${inputsig}, + out_sig=${outputsig}${deciminterp}) +#end if + +#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)): + ninput_items_required[i] = noutput_items + + def general_work(self, input_items, output_items): + output_items[0][:] = input_items[0] + consume(0, len(input_items[0]) + \#self.consume_each(len(input_items[0])) + return len(output_items[0]) +#stop +#else + def work(self, input_items, output_items): +#end if + + def work(self, input_items, output_items): +#if $blocktype != 'source' + in0 = input_items[0] +#end if +#if $blocktype != 'sink' + out = output_items[0] +#end if + # <+signal processing here+> +#if $blocktype in ('sync', 'decimator', 'interpolator') + out[:] = in0 + return len(output_items[0]) +#else if $blocktype == 'sink' + return len(input_items[0]) +#else if $blocktype == 'source' + out[:] = whatever + return len(output_items[0]) +#end if + +''' + +# C++ file for QA +Templates['qa_cpp'] = '''/* -*- c++ -*- */ +${str_to_fancyc_comment($license)} + +\#include "qa_${blockname}.h" +\#include <cppunit/TestAssert.h> + +\#include <$modname/${blockname}.h> + +namespace gr { + namespace ${modname} { + + void + qa_${blockname}::t1() + { + // Put test here + } + + } /* namespace ${modname} */ +} /* namespace gr */ + +''' + +# Header file for QA +Templates['qa_h'] = '''/* -*- c++ -*- */ +${str_to_fancyc_comment($license)} + +\#ifndef _QA_${blockname.upper()}_H_ +\#define _QA_${blockname.upper()}_H_ + +\#include <cppunit/extensions/HelperMacros.h> +\#include <cppunit/TestCase.h> + +namespace gr { + namespace ${modname} { + + class qa_${blockname} : public CppUnit::TestCase + { + public: + CPPUNIT_TEST_SUITE(qa_${blockname}); + CPPUNIT_TEST(t1); + CPPUNIT_TEST_SUITE_END(); + + private: + void t1(); + }; + + } /* namespace ${modname} */ +} /* namespace gr */ + +\#endif /* _QA_${blockname.upper()}_H_ */ + +''' + +# Python QA code +Templates['qa_python'] = '''\#!/usr/bin/env python +${str_to_python_comment($license)} +# + +from gnuradio import gr, gr_unittest +#if $lang == 'cpp' +import ${modname}_swig as ${modname} +#else +from ${blockname} import ${blockname} +#end if + +class qa_$blockname (gr_unittest.TestCase): + + def setUp (self): + self.tb = gr.top_block () + + def tearDown (self): + self.tb = None + + def test_001_t (self): + # set up fg + self.tb.run () + # check data + + +if __name__ == '__main__': + gr_unittest.run(qa_${blockname}, "qa_${blockname}.xml") +''' + +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($arglist)})</make> + <!-- Make one 'param' node for every Parameter you want settable from the GUI. + Sub-nodes: + * name + * key (makes the value accessible as \$keyname, e.g. in the make node) + * type --> + <param> + <name>...</name> + <key>...</key> + <type>...</type> + </param> + + <!-- Make one 'sink' node per input. Sub-nodes: + * name (an identifier for the GUI) + * type + * vlen + * optional (set to 1 for optional inputs) --> + <sink> + <name>in</name> + <type><!-- e.g. int, real, complex, byte, short, xxx_vector, ...--></type> + </sink> + + <!-- Make one 'source' node per output. Sub-nodes: + * name (an identifier for the GUI) + * type + * vlen + * optional (set to 1 for optional inputs) --> + <source> + <name>out</name> + <type><!-- e.g. int, real, complex, byte, short, xxx_vector, ...--></type> + </source> +</block> +''' + +# Usage +Templates['usage'] = ''' +gr_modtool.py <command> [options] -- Run <command> with the given options. +gr_modtool.py help -- Show a list of commands. +gr_modtool.py help <command> -- Shows the help for a given command. ''' + +# SWIG string +Templates['swig_block_magic'] = """#if $version == '37' +#set $mod_block_sep = '/' +#set $block_magic_version = '2' +#else +#set $mod_block_sep = '_' +#set $block_magic_version = '' +#end if +%include "${modname}${mod_block_sep}${blockname}.h" +GR_SWIG_BLOCK_MAGIC${block_magic_version}($modname, $blockname); +""" + +## 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)}) +{ +} + +${modname}_${blockname}::~${modname}_${blockname}() +{ +} +#else +${modname}_${blockname}_sptr +${modname}_make_${blockname} (${strip_default_values($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 (<+float+>)' +#end if +#if $blocktype == 'source' +#set $outputsig = '0, 0, 0' +#else +#set $outputsig = '<+MIN_OUT+>, <+MAX_OUT+>, sizeof (<+float+>)' +#end if + +/* + * The private constructor + */ +${modname}_${blockname}::${modname}_${blockname} (${strip_default_values($arglist)}) + : ${grblocktype} ("${blockname}", + gr_make_io_signature($inputsig), + gr_make_io_signature($outputsig)$decimation) +{ +#if $blocktype == 'hier' + connect(self(), 0, d_firstblock, 0); + // <+connect other blocks+> + connect(d_lastblock, 0, self(), 0); +#else + // Put in <+constructor stuff+> here +#end if +} + + +/* + * Our virtual destructor. + */ +${modname}_${blockname}::~${modname}_${blockname}() +{ + // Put in <+destructor stuff+> here +} +#end if + + +#if $blocktype == 'general' +void +${modname}_${blockname}::forecast (int noutput_items, gr_vector_int &ninput_items_required) +{ + /* <+forecast+> e.g. ninput_items_required[0] = noutput_items */ +} + +int +${modname}_${blockname}::general_work (int noutput_items, + gr_vector_int &ninput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items) +{ + const float *in = (const float *) input_items[0]; + float *out = (float *) output_items[0]; + + // Do <+signal processing+> + // Tell runtime system how many input items we consumed on + // each input stream. + consume_each (noutput_items); + + // Tell runtime system how many output items we produced. + return noutput_items; +} +#else if $blocktype == 'hier' or $blocktype == 'noblock' +#pass +#else +int +${modname}_${blockname}::work(int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items) +{ + const float *in = (const float *) input_items[0]; + float *out = (float *) output_items[0]; + + // Do <+signal processing+> + + // Tell runtime system how many output items we produced. + return noutput_items; +} +#end if + +''' + +# Block definition header file (for include/) +Templates['block_h36'] = '''/* -*- c++ -*- */ +${str_to_fancyc_comment($license)} + +\#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 +{ + ${blockname}(${arglist}); + ~${blockname}(); + private: +}; + +#else +\#include <${grblocktype}.h> + +class ${modname}_${blockname}; + +typedef boost::shared_ptr<${modname}_${blockname}> ${modname}_${blockname}_sptr; + +${modname.upper()}_API ${modname}_${blockname}_sptr ${modname}_make_${blockname} ($arglist); + +/*! + * \\brief <+description+> + * \ingroup ${modname} + * + */ +class ${modname.upper()}_API ${modname}_${blockname} : public $grblocktype +{ + private: + friend ${modname.upper()}_API ${modname}_${blockname}_sptr ${modname}_make_${blockname} (${strip_default_values($arglist)}); + + ${modname}_${blockname}(${strip_default_values($arglist)}); + + public: + ~${modname}_${blockname}(); + +#if $blocktype == 'general' + void forecast (int noutput_items, gr_vector_int &ninput_items_required); + + // Where all the action really happens + 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 == 'hier' +#pass +#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 +}; +#end if + +\#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) +""" + -- cgit v1.2.3 From c4971ab2cb4bdbb9abc5d5320bd16b45cf263cf8 Mon Sep 17 00:00:00 2001 From: Martin Braun <martin.braun@kit.edu> Date: Fri, 25 Jan 2013 17:52:46 +0100 Subject: utils: modtool minor updates --- gr-utils/src/python/modtool/cmakefile_editor.py | 2 +- gr-utils/src/python/modtool/modtool_add.py | 2 +- gr-utils/src/python/modtool/modtool_newmod.py | 2 +- gr-utils/src/python/modtool/templates.py | 6 ++---- 4 files changed, 5 insertions(+), 7 deletions(-) (limited to 'gr-utils/src/python/modtool/templates.py') diff --git a/gr-utils/src/python/modtool/cmakefile_editor.py b/gr-utils/src/python/modtool/cmakefile_editor.py index fe50373bb8..b182757076 100644 --- a/gr-utils/src/python/modtool/cmakefile_editor.py +++ b/gr-utils/src/python/modtool/cmakefile_editor.py @@ -5,7 +5,7 @@ import re ### CMakeFile.txt editor class ############################################### class CMakeFileEditor(object): """A tool for editing CMakeLists.txt files. """ - def __init__(self, filename, separator=' ', indent=' '): + def __init__(self, filename, separator='\n ', indent=' '): self.filename = filename self.cfile = open(filename, 'r').read() self.separator = separator diff --git a/gr-utils/src/python/modtool/modtool_add.py b/gr-utils/src/python/modtool/modtool_add.py index c664d7c1a2..581f3b0aaf 100644 --- a/gr-utils/src/python/modtool/modtool_add.py +++ b/gr-utils/src/python/modtool/modtool_add.py @@ -272,7 +272,7 @@ class ModToolAdd(ModTool): self._write_tpl('block_python', 'python', fname_py) append_re_line_sequence(self._file['pyinit'], '(^from.*import.*\n|# import any pure.*\n)', - 'from %s import *' % self._info['blockname']) + 'from %s import %s' % (self._info['blockname'], self._info['blockname'])) if self.options.skip_cmakefiles: return ed = CMakeFileEditor(self._file['cmpython']) diff --git a/gr-utils/src/python/modtool/modtool_newmod.py b/gr-utils/src/python/modtool/modtool_newmod.py index 9b2dc6e30d..0c69cb69e8 100644 --- a/gr-utils/src/python/modtool/modtool_newmod.py +++ b/gr-utils/src/python/modtool/modtool_newmod.py @@ -51,7 +51,7 @@ class ModToolNewModule(ModTool): * Open all files, rename howto and HOWTO to the module name * Rename files and directories that contain the word howto """ - print "Creating out-of-tree module in %s..." % self._dir + print "Creating out-of-tree module in %s..." % self._dir, try: shutil.copytree('/home/braun/.usrlocal/share/gnuradio/modtool/gr-newmod', self._dir) os.chdir(self._dir) diff --git a/gr-utils/src/python/modtool/templates.py b/gr-utils/src/python/modtool/templates.py index e3019bb701..f41049c5ae 100644 --- a/gr-utils/src/python/modtool/templates.py +++ b/gr-utils/src/python/modtool/templates.py @@ -287,8 +287,8 @@ import numpy #set $deciminterp = ', <+interpolation+>' #else if $blocktype == 'decimator' #set $deciminterp = ', <+decimation+>' -#set $deciminterp = '' #else +#set $deciminterp = '' #end if from gnuradio import gr @@ -297,7 +297,7 @@ class ${blockname}(${parenttype}): docstring for block ${blockname} """ def __init__(self#if $arglist == '' then '' else ', '#$arglist): - gr.${parenttype}.__init__(self, + ${parenttype}.__init__(self, #if $blocktype == 'hier' "$blockname", gr.io_signature(${inputsig}), # Input signature @@ -324,8 +324,6 @@ class ${blockname}(${parenttype}): \#self.consume_each(len(input_items[0])) return len(output_items[0]) #stop -#else - def work(self, input_items, output_items): #end if def work(self, input_items, output_items): -- cgit v1.2.3 From 9ef0f125355a4541c691f18d05ad7ca7b6f7125e Mon Sep 17 00:00:00 2001 From: Martin Braun <martin.braun@kit.edu> Date: Sun, 27 Jan 2013 16:57:04 +0100 Subject: modtool: added copyleft headers --- gr-utils/src/python/modtool/__init__.py | 2 +- gr-utils/src/python/modtool/cmakefile_editor.py | 21 ++++++++++- gr-utils/src/python/modtool/code_generator.py | 21 ++++++++++- gr-utils/src/python/modtool/grc_xml_generator.py | 21 ++++++++++- gr-utils/src/python/modtool/modtool_add.py | 21 ++++++++++- gr-utils/src/python/modtool/modtool_base.py | 21 ++++++++++- gr-utils/src/python/modtool/modtool_disable.py | 21 ++++++++++- gr-utils/src/python/modtool/modtool_help.py | 44 ++++++++++++------------ gr-utils/src/python/modtool/modtool_info.py | 21 ++++++++++- gr-utils/src/python/modtool/modtool_makexml.py | 21 ++++++++++- gr-utils/src/python/modtool/modtool_newmod.py | 23 +++++++++++-- gr-utils/src/python/modtool/modtool_rm.py | 21 ++++++++++- gr-utils/src/python/modtool/parser_cc_block.py | 21 ++++++++++- gr-utils/src/python/modtool/templates.py | 22 ++++++++++-- gr-utils/src/python/modtool/util_functions.py | 21 ++++++++++- 15 files changed, 284 insertions(+), 38 deletions(-) (limited to 'gr-utils/src/python/modtool/templates.py') diff --git a/gr-utils/src/python/modtool/__init__.py b/gr-utils/src/python/modtool/__init__.py index a107472540..7935e4b482 100644 --- a/gr-utils/src/python/modtool/__init__.py +++ b/gr-utils/src/python/modtool/__init__.py @@ -1,5 +1,5 @@ # -# Copyright 2012 Free Software Foundation, Inc. +# Copyright 2013 Free Software Foundation, Inc. # # This file is part of GNU Radio # diff --git a/gr-utils/src/python/modtool/cmakefile_editor.py b/gr-utils/src/python/modtool/cmakefile_editor.py index b182757076..ed5b714253 100644 --- a/gr-utils/src/python/modtool/cmakefile_editor.py +++ b/gr-utils/src/python/modtool/cmakefile_editor.py @@ -1,8 +1,27 @@ +# +# Copyright 2013 Free Software Foundation, Inc. +# +# This file is part of GNU Radio +# +# GNU Radio is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3, or (at your option) +# any later version. +# +# GNU Radio is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# 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. +# """ Edit CMakeLists.txt files """ import re -### CMakeFile.txt editor class ############################################### class CMakeFileEditor(object): """A tool for editing CMakeLists.txt files. """ def __init__(self, filename, separator='\n ', indent=' '): diff --git a/gr-utils/src/python/modtool/code_generator.py b/gr-utils/src/python/modtool/code_generator.py index b727f611e5..525b3d1e9a 100644 --- a/gr-utils/src/python/modtool/code_generator.py +++ b/gr-utils/src/python/modtool/code_generator.py @@ -1,3 +1,23 @@ +# +# Copyright 2013 Free Software Foundation, Inc. +# +# This file is part of GNU Radio +# +# GNU Radio is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3, or (at your option) +# any later version. +# +# GNU Radio is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# 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. +# """ A code generator (needed by ModToolAdd) """ from templates import Templates @@ -7,7 +27,6 @@ from util_functions import str_to_python_comment from util_functions import strip_default_values from util_functions import strip_arg_types -### Code generator class ##################################################### class GRMTemplate(Cheetah.Template.Template): """ An extended template class """ def __init__(self, src, searchList): diff --git a/gr-utils/src/python/modtool/grc_xml_generator.py b/gr-utils/src/python/modtool/grc_xml_generator.py index 2fa61863f2..7ccd443196 100644 --- a/gr-utils/src/python/modtool/grc_xml_generator.py +++ b/gr-utils/src/python/modtool/grc_xml_generator.py @@ -1,7 +1,26 @@ +# +# Copyright 2013 Free Software Foundation, Inc. +# +# This file is part of GNU Radio +# +# GNU Radio is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3, or (at your option) +# any later version. +# +# GNU Radio is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# 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. +# import xml.etree.ElementTree as ET from util_functions import is_number, xml_indent -### GRC XML Generator ######################################################## try: import lxml.etree LXML_IMPORTED = True diff --git a/gr-utils/src/python/modtool/modtool_add.py b/gr-utils/src/python/modtool/modtool_add.py index 581f3b0aaf..a6c84bea85 100644 --- a/gr-utils/src/python/modtool/modtool_add.py +++ b/gr-utils/src/python/modtool/modtool_add.py @@ -1,3 +1,23 @@ +# +# Copyright 2013 Free Software Foundation, Inc. +# +# This file is part of GNU Radio +# +# GNU Radio is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3, or (at your option) +# any later version. +# +# GNU Radio is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# 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. +# """ Module to add new blocks """ import os @@ -12,7 +32,6 @@ from templates import Templates from code_generator import get_template import Cheetah.Template -### Add new block module ##################################################### class ModToolAdd(ModTool): """ Add block to the out-of-tree module. """ name = 'add' diff --git a/gr-utils/src/python/modtool/modtool_base.py b/gr-utils/src/python/modtool/modtool_base.py index edb0f14eed..d824910e95 100644 --- a/gr-utils/src/python/modtool/modtool_base.py +++ b/gr-utils/src/python/modtool/modtool_base.py @@ -1,3 +1,23 @@ +# +# Copyright 2013 Free Software Foundation, Inc. +# +# This file is part of GNU Radio +# +# GNU Radio is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3, or (at your option) +# any later version. +# +# GNU Radio is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# 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. +# """ Base class for the modules """ import os @@ -8,7 +28,6 @@ from optparse import OptionParser, OptionGroup from util_functions import get_modname from templates import Templates -### ModTool base class ####################################################### class ModTool(object): """ Base class for all modtool command classes. """ def __init__(self): diff --git a/gr-utils/src/python/modtool/modtool_disable.py b/gr-utils/src/python/modtool/modtool_disable.py index 67f15ad537..b0fb132451 100644 --- a/gr-utils/src/python/modtool/modtool_disable.py +++ b/gr-utils/src/python/modtool/modtool_disable.py @@ -1,3 +1,23 @@ +# +# Copyright 2013 Free Software Foundation, Inc. +# +# This file is part of GNU Radio +# +# GNU Radio is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3, or (at your option) +# any later version. +# +# GNU Radio is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# 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. +# """ Disable blocks module """ import os @@ -8,7 +28,6 @@ from optparse import OptionGroup from modtool_base import ModTool from cmakefile_editor import CMakeFileEditor -### Disable module ########################################################### class ModToolDisable(ModTool): """ Disable block (comments out CMake entries for files) """ name = 'disable' diff --git a/gr-utils/src/python/modtool/modtool_help.py b/gr-utils/src/python/modtool/modtool_help.py index a1dd3c4660..79474a9631 100644 --- a/gr-utils/src/python/modtool/modtool_help.py +++ b/gr-utils/src/python/modtool/modtool_help.py @@ -1,30 +1,30 @@ +# +# Copyright 2013 Free Software Foundation, Inc. +# +# This file is part of GNU Radio +# +# GNU Radio is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3, or (at your option) +# any later version. +# +# GNU Radio is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# 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. +# """ The help module """ -from modtool_base import ModTool -from modtool_info import ModToolInfo -from modtool_add import ModToolAdd -from modtool_rm import ModToolRemove -from modtool_newmod import ModToolNewModule -from modtool_disable import ModToolDisable -from modtool_makexml import ModToolMakeXML -from util_functions import get_command_from_argv +from gnuradio.modtool import * +from util_functions import get_command_from_argv, get_class_dict from templates import Templates -def get_class_dict(): - " Return a dictionary of the available commands in the form command->class " - classdict = {} - for g in globals().values(): - try: - if issubclass(g, ModTool): - classdict[g.name] = g - for a in g.aliases: - classdict[a] = g - except (TypeError, AttributeError): - pass - return classdict - -### Help module ############################################################## def print_class_descriptions(): ''' Go through all ModTool* classes and print their name, alias and description. ''' diff --git a/gr-utils/src/python/modtool/modtool_info.py b/gr-utils/src/python/modtool/modtool_info.py index 80fa278321..e774db9114 100644 --- a/gr-utils/src/python/modtool/modtool_info.py +++ b/gr-utils/src/python/modtool/modtool_info.py @@ -1,3 +1,23 @@ +# +# Copyright 2013 Free Software Foundation, Inc. +# +# This file is part of GNU Radio +# +# GNU Radio is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3, or (at your option) +# any later version. +# +# GNU Radio is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# 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. +# """ Returns information about a module """ import os @@ -6,7 +26,6 @@ from optparse import OptionGroup from modtool_base import ModTool from util_functions import get_modname -### Info module ############################################################## class ModToolInfo(ModTool): """ Return information about a given module """ name = 'info' diff --git a/gr-utils/src/python/modtool/modtool_makexml.py b/gr-utils/src/python/modtool/modtool_makexml.py index 5a1a24f1bb..acf3e459c0 100644 --- a/gr-utils/src/python/modtool/modtool_makexml.py +++ b/gr-utils/src/python/modtool/modtool_makexml.py @@ -1,3 +1,23 @@ +# +# Copyright 2013 Free Software Foundation, Inc. +# +# This file is part of GNU Radio +# +# GNU Radio is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3, or (at your option) +# any later version. +# +# GNU Radio is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# 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. +# """ Automatically create XML bindings for GRC from block code """ import sys @@ -11,7 +31,6 @@ from parser_cc_block import ParserCCBlock from grc_xml_generator import GRCXMLGenerator from cmakefile_editor import CMakeFileEditor -### Remove module ########################################################### class ModToolMakeXML(ModTool): """ Make XML file for GRC block bindings """ name = 'makexml' diff --git a/gr-utils/src/python/modtool/modtool_newmod.py b/gr-utils/src/python/modtool/modtool_newmod.py index 0c69cb69e8..7a5f635dde 100644 --- a/gr-utils/src/python/modtool/modtool_newmod.py +++ b/gr-utils/src/python/modtool/modtool_newmod.py @@ -1,3 +1,23 @@ +# +# Copyright 2013 Free Software Foundation, Inc. +# +# This file is part of GNU Radio +# +# GNU Radio is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3, or (at your option) +# any later version. +# +# GNU Radio is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# 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. +# """ Create a whole new out-of-tree module """ import shutil @@ -6,7 +26,6 @@ import re from optparse import OptionGroup from modtool_base import ModTool -### New out-of-tree-mod module ############################################### class ModToolNewModule(ModTool): """ Create a new out-of-tree module """ name = 'newmod' @@ -36,7 +55,6 @@ class ModToolNewModule(ModTool): self._dir = options.directory if self._dir == '.': self._dir = './gr-%s' % self._info['modname'] - print 'Module directory is "%s".' % self._dir try: os.stat(self._dir) except OSError: @@ -56,6 +74,7 @@ class ModToolNewModule(ModTool): shutil.copytree('/home/braun/.usrlocal/share/gnuradio/modtool/gr-newmod', self._dir) os.chdir(self._dir) except OSError: + print 'FAILED' print 'Could not create directory %s. Quitting.' % self._dir exit(2) for root, dirs, files in os.walk('.'): diff --git a/gr-utils/src/python/modtool/modtool_rm.py b/gr-utils/src/python/modtool/modtool_rm.py index 16bfeb34ce..bdbd802f33 100644 --- a/gr-utils/src/python/modtool/modtool_rm.py +++ b/gr-utils/src/python/modtool/modtool_rm.py @@ -1,3 +1,23 @@ +# +# Copyright 2013 Free Software Foundation, Inc. +# +# This file is part of GNU Radio +# +# GNU Radio is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3, or (at your option) +# any later version. +# +# GNU Radio is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# 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. +# """ Remove blocks module """ import os @@ -10,7 +30,6 @@ from util_functions import remove_pattern_from_file from modtool_base import ModTool from cmakefile_editor import CMakeFileEditor -### Remove module ########################################################### class ModToolRemove(ModTool): """ Remove block (delete files and remove Makefile entries) """ name = 'remove' diff --git a/gr-utils/src/python/modtool/parser_cc_block.py b/gr-utils/src/python/modtool/parser_cc_block.py index 447fe113dd..d11353cc7a 100644 --- a/gr-utils/src/python/modtool/parser_cc_block.py +++ b/gr-utils/src/python/modtool/parser_cc_block.py @@ -1,8 +1,27 @@ +# +# Copyright 2013 Free Software Foundation, Inc. +# +# This file is part of GNU Radio +# +# GNU Radio is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3, or (at your option) +# any later version. +# +# GNU Radio is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# 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. +# ''' A parser for blocks written in C++ ''' import re import sys -### Parser for CC blocks #################################################### def dummy_translator(the_type, default_v=None): """ Doesn't really translate. """ return the_type diff --git a/gr-utils/src/python/modtool/templates.py b/gr-utils/src/python/modtool/templates.py index f41049c5ae..91d8370b98 100644 --- a/gr-utils/src/python/modtool/templates.py +++ b/gr-utils/src/python/modtool/templates.py @@ -1,10 +1,28 @@ +# +# Copyright 2013 Free Software Foundation, Inc. +# +# This file is part of GNU Radio +# +# GNU Radio is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3, or (at your option) +# any later version. +# +# GNU Radio is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# 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. +# ''' All the templates for skeleton files (needed by ModToolAdd) ''' from datetime import datetime -### Templates ################################################################ Templates = {} -Templates36 = {} # Default licence Templates['defaultlicense'] = ''' diff --git a/gr-utils/src/python/modtool/util_functions.py b/gr-utils/src/python/modtool/util_functions.py index 029ae04bfa..33d8ad3339 100644 --- a/gr-utils/src/python/modtool/util_functions.py +++ b/gr-utils/src/python/modtool/util_functions.py @@ -1,9 +1,28 @@ +# +# Copyright 2013 Free Software Foundation, Inc. +# +# This file is part of GNU Radio +# +# GNU Radio is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3, or (at your option) +# any later version. +# +# GNU Radio is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# 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. +# """ Utility functions for gr_modtool.py """ import re import sys -### Utility functions ######################################################## def get_command_from_argv(possible_cmds): """ Read the requested command from argv. This can't be done with optparse, since the option parser isn't defined before the command is known, and -- cgit v1.2.3 From 2d695b3c4c86b5c206f95dcc1d71f97d808d98b8 Mon Sep 17 00:00:00 2001 From: Martin Braun <martin.braun@kit.edu> Date: Mon, 28 Jan 2013 15:26:05 +0100 Subject: modtool: cleanup, bugfixes --- gr-utils/src/python/gr_modtool | 20 +----------------- gr-utils/src/python/modtool/__init__.py | 5 +++-- gr-utils/src/python/modtool/cmakefile_editor.py | 2 +- gr-utils/src/python/modtool/modtool_add.py | 1 - gr-utils/src/python/modtool/modtool_base.py | 28 ++++++++++++++++++++----- gr-utils/src/python/modtool/modtool_disable.py | 19 ++--------------- gr-utils/src/python/modtool/modtool_help.py | 4 ++-- gr-utils/src/python/modtool/modtool_info.py | 2 +- gr-utils/src/python/modtool/modtool_makexml.py | 26 +++++++---------------- gr-utils/src/python/modtool/modtool_newmod.py | 2 +- gr-utils/src/python/modtool/modtool_rm.py | 19 ++--------------- gr-utils/src/python/modtool/parser_cc_block.py | 5 +++-- gr-utils/src/python/modtool/templates.py | 6 +++--- gr-utils/src/python/modtool/util_functions.py | 19 ++++------------- 14 files changed, 53 insertions(+), 105 deletions(-) (limited to 'gr-utils/src/python/modtool/templates.py') diff --git a/gr-utils/src/python/gr_modtool b/gr-utils/src/python/gr_modtool index bc41d56f55..8c5c710aff 100755 --- a/gr-utils/src/python/gr_modtool +++ b/gr-utils/src/python/gr_modtool @@ -24,24 +24,9 @@ import sys from gnuradio.modtool import * -def get_class_dict(): - " Return a dictionary of the available commands in the form command->class " - classdict = {} - for g in globals().values(): - try: - if issubclass(g, ModTool): - classdict[g.name] = g - for a in g.aliases: - classdict[a] = g - except (TypeError, AttributeError): - pass - return classdict - - -### Main code ################################################################ def main(): """ Here we go. Parse command, choose class and run. """ - cmd_dict = get_class_dict() + cmd_dict = get_class_dict(globals().values()) command = get_command_from_argv(cmd_dict.keys()) if command is None: print 'Usage:' + templates.Templates['usage'] @@ -51,9 +36,6 @@ def main(): modtool.run() if __name__ == '__main__': - if not ((sys.version_info[0] > 2) or - (sys.version_info[0] == 2 and sys.version_info[1] >= 7)): - print "Using Python < 2.7 is not recommended for gr_modtool." try: main() except KeyboardInterrupt: diff --git a/gr-utils/src/python/modtool/__init__.py b/gr-utils/src/python/modtool/__init__.py index 7935e4b482..a242722ab4 100644 --- a/gr-utils/src/python/modtool/__init__.py +++ b/gr-utils/src/python/modtool/__init__.py @@ -22,13 +22,14 @@ from cmakefile_editor import CMakeFileEditor from code_generator import GRMTemplate from grc_xml_generator import GRCXMLGenerator +from modtool_base import ModTool, get_class_dict from modtool_add import ModToolAdd -from modtool_base import ModTool from modtool_disable import ModToolDisable -from modtool_help import ModToolHelp from modtool_info import ModToolInfo from modtool_makexml import ModToolMakeXML from modtool_newmod import ModToolNewModule from modtool_rm import ModToolRemove +# Leave this at the end +from modtool_help import ModToolHelp from parser_cc_block import ParserCCBlock from util_functions import * diff --git a/gr-utils/src/python/modtool/cmakefile_editor.py b/gr-utils/src/python/modtool/cmakefile_editor.py index 92121dda3b..3d90b8d163 100644 --- a/gr-utils/src/python/modtool/cmakefile_editor.py +++ b/gr-utils/src/python/modtool/cmakefile_editor.py @@ -49,7 +49,7 @@ class CMakeFileEditor(object): """Remove an entry from the current buffer.""" regexp = '%s\s*\([^()]*%s[^()]*\)[^\n]*\n' % (entry, value_pattern) regexp = re.compile(regexp, re.MULTILINE) - (self.cfile, nsubs) = re.sub(regexp, '', self.cfile, count=1) + (self.cfile, nsubs) = re.subn(regexp, '', self.cfile, count=1) return nsubs def write(self): diff --git a/gr-utils/src/python/modtool/modtool_add.py b/gr-utils/src/python/modtool/modtool_add.py index 32cfe04408..7ca375b6f9 100644 --- a/gr-utils/src/python/modtool/modtool_add.py +++ b/gr-utils/src/python/modtool/modtool_add.py @@ -45,7 +45,6 @@ class ModToolAdd(ModTool): def setup_parser(self): parser = ModTool.setup_parser(self) - parser.usage = '%prog add [options]. \n Call %prog without any options to run it interactively.' ogroup = OptionGroup(parser, "Add module options") ogroup.add_option("-t", "--block-type", type="choice", choices=self._block_types, default=None, help="One of %s." % ', '.join(self._block_types)) diff --git a/gr-utils/src/python/modtool/modtool_base.py b/gr-utils/src/python/modtool/modtool_base.py index d824910e95..3f8f2bc3c7 100644 --- a/gr-utils/src/python/modtool/modtool_base.py +++ b/gr-utils/src/python/modtool/modtool_base.py @@ -28,6 +28,7 @@ from optparse import OptionParser, OptionGroup from util_functions import get_modname from templates import Templates + class ModTool(object): """ Base class for all modtool command classes. """ def __init__(self): @@ -47,15 +48,17 @@ class ModTool(object): def setup_parser(self): """ Init the option parser. If derived classes need to add options, override this and call the parent function. """ - parser = OptionParser(usage=Templates['usage'], add_help_option=False) + parser = OptionParser(add_help_option=False) + parser.usage = '%prog ' + self.name + ' [options] <PATTERN> \n' + \ + ' Call "%prog ' + self.name + '" without any options to run it interactively.' ogroup = OptionGroup(parser, "General options") ogroup.add_option("-h", "--help", action="help", help="Displays this help message.") ogroup.add_option("-d", "--directory", type="string", default=".", - help="Base directory of the module.") + help="Base directory of the module. Defaults to the cwd.") ogroup.add_option("-n", "--module-name", type="string", default=None, - help="Name of the GNU Radio module. If possible, this gets detected from CMakeLists.txt.") + help="Use this to override the current module's name (is normally autodetected).") ogroup.add_option("-N", "--block-name", type="string", default=None, - help="Name of the block, minus the module name prefix.") + help="Name of the block, where applicable.") ogroup.add_option("--skip-lib", action="store_true", default=False, help="Don't do anything in the lib/ subdirectory.") ogroup.add_option("--skip-swig", action="store_true", default=False, @@ -64,6 +67,8 @@ class ModTool(object): help="Don't do anything in the python/ subdirectory.") ogroup.add_option("--skip-grc", action="store_true", default=False, help="Don't do anything in the grc/ subdirectory.") + ogroup.add_option("-y", "--yes", action="store_true", default=False, + help="Answer all questions with 'yes'. This can overwrite and delete your files, so be careful.") parser.add_option_group(ogroup) return parser @@ -74,7 +79,6 @@ class ModTool(object): if not self._check_directory(self._dir): print "No GNU Radio module found in the given directory. Quitting." sys.exit(1) - print "Operating in directory " + self._dir if options.module_name is not None: self._info['modname'] = options.module_name else: @@ -96,6 +100,7 @@ class ModTool(object): self._info['blockname'] = options.block_name self.options = options self._setup_files() + self._info['yes'] = options.yes def _setup_files(self): """ Initialise the self._file[] dictionary """ @@ -156,3 +161,16 @@ class ModTool(object): """ Override this. """ pass +def get_class_dict(the_globals): + " Return a dictionary of the available commands in the form command->class " + classdict = {} + for g in the_globals: + try: + if issubclass(g, ModTool): + classdict[g.name] = g + for a in g.aliases: + classdict[a] = g + except (TypeError, AttributeError): + pass + return classdict + diff --git a/gr-utils/src/python/modtool/modtool_disable.py b/gr-utils/src/python/modtool/modtool_disable.py index b0fb132451..36725e5578 100644 --- a/gr-utils/src/python/modtool/modtool_disable.py +++ b/gr-utils/src/python/modtool/modtool_disable.py @@ -35,24 +35,10 @@ class ModToolDisable(ModTool): def __init__(self): ModTool.__init__(self) - def setup_parser(self): - " Initialise the option parser for 'gr_modtool.py rm' " - parser = ModTool.setup_parser(self) - parser.usage = '%prog disable [options]. \n Call %prog without any options to run it interactively.' - ogroup = OptionGroup(parser, "Disable module options") - ogroup.add_option("-p", "--pattern", type="string", default=None, - help="Filter possible choices for blocks to be disabled.") - ogroup.add_option("-y", "--yes", action="store_true", default=False, - help="Answer all questions with 'yes'.") - parser.add_option_group(ogroup) - return parser - def setup(self): ModTool.setup(self) options = self.options - if options.pattern is not None: - self._info['pattern'] = options.pattern - elif options.block_name is not None: + if options.block_name is not None: self._info['pattern'] = options.block_name elif len(self.args) >= 2: self._info['pattern'] = self.args[1] @@ -60,7 +46,6 @@ class ModToolDisable(ModTool): self._info['pattern'] = raw_input('Which blocks do you want to disable? (Regex): ') if len(self._info['pattern']) == 0: self._info['pattern'] = '.' - self._info['yes'] = options.yes def run(self): """ Go, go, go! """ @@ -123,7 +108,7 @@ class ModToolDisable(ModTool): swigfile = re.sub('(GR_SWIG_BLOCK_MAGIC2?.+'+blockname+'.+;)', r'//\1', swigfile) open(self._file['swig'], 'w').write(swigfile) return False - # List of special rules: 0: subdir, 1: filename re match, 2: function + # List of special rules: 0: subdir, 1: filename re match, 2: callback special_treatments = ( ('python', 'qa.+py$', _handle_py_qa), ('python', '^(?!qa).+py$', _handle_py_mod), diff --git a/gr-utils/src/python/modtool/modtool_help.py b/gr-utils/src/python/modtool/modtool_help.py index 79474a9631..76d9fd28bd 100644 --- a/gr-utils/src/python/modtool/modtool_help.py +++ b/gr-utils/src/python/modtool/modtool_help.py @@ -21,7 +21,7 @@ """ The help module """ from gnuradio.modtool import * -from util_functions import get_command_from_argv, get_class_dict +from util_functions import get_command_from_argv from templates import Templates @@ -51,7 +51,7 @@ class ModToolHelp(ModTool): pass def run(self): - cmd_dict = get_class_dict() + cmd_dict = get_class_dict(globals().values()) cmds = cmd_dict.keys() cmds.remove(self.name) for a in self.aliases: diff --git a/gr-utils/src/python/modtool/modtool_info.py b/gr-utils/src/python/modtool/modtool_info.py index e774db9114..680bd41b99 100644 --- a/gr-utils/src/python/modtool/modtool_info.py +++ b/gr-utils/src/python/modtool/modtool_info.py @@ -34,7 +34,7 @@ class ModToolInfo(ModTool): ModTool.__init__(self) def setup_parser(self): - " Initialise the option parser for 'gr_modtool.py info' " + " Initialise the option parser for 'gr_modtool info' " parser = ModTool.setup_parser(self) parser.usage = '%prog info [options]. \n Call %prog without any options to run it interactively.' ogroup = OptionGroup(parser, "Info options") diff --git a/gr-utils/src/python/modtool/modtool_makexml.py b/gr-utils/src/python/modtool/modtool_makexml.py index 104a0fdbde..777cc09e1f 100644 --- a/gr-utils/src/python/modtool/modtool_makexml.py +++ b/gr-utils/src/python/modtool/modtool_makexml.py @@ -30,6 +30,7 @@ from modtool_base import ModTool 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 """ @@ -38,24 +39,10 @@ class ModToolMakeXML(ModTool): def __init__(self): ModTool.__init__(self) - def setup_parser(self): - " Initialise the option parser for 'gr_modtool.py makexml' " - parser = ModTool.setup_parser(self) - parser.usage = '%prog makexml [options]. \n Call %prog without any options to run it interactively.' - ogroup = OptionGroup(parser, "Make XML module options") - ogroup.add_option("-p", "--pattern", type="string", default=None, - help="Filter possible choices for blocks to be parsed.") - ogroup.add_option("-y", "--yes", action="store_true", default=False, - help="Answer all questions with 'yes'. This can overwrite existing files!") - parser.add_option_group(ogroup) - return parser - def setup(self): ModTool.setup(self) options = self.options - if options.pattern is not None: - self._info['pattern'] = options.pattern - elif options.block_name is not None: + if options.block_name is not None: self._info['pattern'] = options.block_name elif len(self.args) >= 2: self._info['pattern'] = self.args[1] @@ -63,7 +50,6 @@ class ModToolMakeXML(ModTool): self._info['pattern'] = raw_input('Which blocks do you want to parse? (Regex): ') if len(self._info['pattern']) == 0: self._info['pattern'] = '.' - self._info['yes'] = options.yes def run(self): """ Go, go, go! """ @@ -109,8 +95,11 @@ class ModToolMakeXML(ModTool): 'default': '2', 'in_constructor': False}) if os.path.isfile(os.path.join('grc', fname_xml)): - # TODO add an option to keep - print "Warning: Overwriting existing GRC file." + if not self._info['yes']: + if not ask_yes_no('Overwrite existing GRC file?', False): + return + else: + print "Warning: Overwriting existing GRC file." grc_generator = GRCXMLGenerator( modname=self._info['modname'], blockname=blockname, @@ -167,4 +156,3 @@ class ModToolMakeXML(ModTool): sys.exit(1) return (parser.read_params(), parser.read_io_signature(), blockname) - diff --git a/gr-utils/src/python/modtool/modtool_newmod.py b/gr-utils/src/python/modtool/modtool_newmod.py index 5e14493c3c..102d83d8df 100644 --- a/gr-utils/src/python/modtool/modtool_newmod.py +++ b/gr-utils/src/python/modtool/modtool_newmod.py @@ -35,7 +35,7 @@ class ModToolNewModule(ModTool): ModTool.__init__(self) def setup_parser(self): - " Initialise the option parser for 'gr_modtool.py newmod' " + " Initialise the option parser for 'gr_modtool newmod' " parser = ModTool.setup_parser(self) parser.usage = '%prog rm [options]. \n Call %prog without any options to run it interactively.' ogroup = OptionGroup(parser, "New out-of-tree module options") diff --git a/gr-utils/src/python/modtool/modtool_rm.py b/gr-utils/src/python/modtool/modtool_rm.py index 02ce8ef3f2..32dfee4806 100644 --- a/gr-utils/src/python/modtool/modtool_rm.py +++ b/gr-utils/src/python/modtool/modtool_rm.py @@ -37,24 +37,10 @@ class ModToolRemove(ModTool): def __init__(self): ModTool.__init__(self) - def setup_parser(self): - " Initialise the option parser for 'gr_modtool.py rm' " - parser = ModTool.setup_parser(self) - parser.usage = '%prog rm [options]. \n Call %prog without any options to run it interactively.' - ogroup = OptionGroup(parser, "Remove module options") - ogroup.add_option("-p", "--pattern", type="string", default=None, - help="Filter possible choices for blocks to be deleted.") - ogroup.add_option("-y", "--yes", action="store_true", default=False, - help="Answer all questions with 'yes'.") - parser.add_option_group(ogroup) - return parser - def setup(self): ModTool.setup(self) options = self.options - if options.pattern is not None: - self._info['pattern'] = options.pattern - elif options.block_name is not None: + if options.block_name is not None: self._info['pattern'] = options.block_name elif len(self.args) >= 2: self._info['pattern'] = self.args[1] @@ -62,7 +48,6 @@ class ModToolRemove(ModTool): self._info['pattern'] = raw_input('Which blocks do you want to delete? (Regex): ') if len(self._info['pattern']) == 0: self._info['pattern'] = '.' - self._info['yes'] = options.yes def run(self): """ Go, go, go! """ @@ -108,7 +93,7 @@ class ModToolRemove(ModTool): return regexp # Go, go, go! if not self._skip_subdirs['lib']: - self._run_subdir('lib', ('*.cc', '*.h'), ('add_library',), + self._run_subdir('lib', ('*.cc', '*.h'), ('add_library', 'list'), cmakeedit_func=_remove_cc_test_case) if not self._skip_subdirs['include']: incl_files_deleted = self._run_subdir(self._info['includedir'], ('*.h',), ('install',)) diff --git a/gr-utils/src/python/modtool/parser_cc_block.py b/gr-utils/src/python/modtool/parser_cc_block.py index d11353cc7a..0d1d75f29a 100644 --- a/gr-utils/src/python/modtool/parser_cc_block.py +++ b/gr-utils/src/python/modtool/parser_cc_block.py @@ -121,12 +121,13 @@ class ParserCCBlock(object): if not in_string: if c[i] == ')': if parens_count == 0: - if read_state == 'type': + if read_state == 'type' and len(this_type): raise ValueError( 'Found closing parentheses before finishing last argument (this is how far I got: %s)' % str(param_list) ) - param_list.append((this_type, this_name, this_defv)) + if len(this_type): + param_list.append((this_type, this_name, this_defv)) end_of_list = True break else: diff --git a/gr-utils/src/python/modtool/templates.py b/gr-utils/src/python/modtool/templates.py index 91d8370b98..8777357112 100644 --- a/gr-utils/src/python/modtool/templates.py +++ b/gr-utils/src/python/modtool/templates.py @@ -490,9 +490,9 @@ Templates['grc_xml'] = '''<?xml version="1.0"?> # Usage Templates['usage'] = ''' -gr_modtool.py <command> [options] -- Run <command> with the given options. -gr_modtool.py help -- Show a list of commands. -gr_modtool.py help <command> -- Shows the help for a given command. ''' +gr_modtool <command> [options] -- Run <command> with the given options. +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 == '37' diff --git a/gr-utils/src/python/modtool/util_functions.py b/gr-utils/src/python/modtool/util_functions.py index 33d8ad3339..4ca294ac31 100644 --- a/gr-utils/src/python/modtool/util_functions.py +++ b/gr-utils/src/python/modtool/util_functions.py @@ -18,11 +18,13 @@ # the Free Software Foundation, Inc., 51 Franklin Street, # Boston, MA 02110-1301, USA. # -""" Utility functions for gr_modtool.py """ +""" Utility functions for gr_modtool """ import re import sys +# None of these must depend on other modtool stuff! + def get_command_from_argv(possible_cmds): """ Read the requested command from argv. This can't be done with optparse, since the option parser isn't defined before the command is known, and @@ -38,7 +40,7 @@ def get_command_from_argv(possible_cmds): return None def append_re_line_sequence(filename, linepattern, newline): - """Detects the re 'linepattern' in the file. After its last occurrence, + """ Detects the re 'linepattern' in the file. After its last occurrence, paste 'newline'. If the pattern does not exist, append the new line to the file. Then, write. """ oldfile = open(filename, 'r').read() @@ -99,19 +101,6 @@ def get_modname(): except AttributeError: return None -def get_class_dict(): - " Return a dictionary of the available commands in the form command->class " - classdict = {} - for g in globals().values(): - try: - if issubclass(g, ModTool): - classdict[g.name] = g - for a in g.aliases: - classdict[a] = g - except (TypeError, AttributeError): - pass - return classdict - def is_number(s): " Return True if the string s contains a number. " try: -- cgit v1.2.3 From 2ba9f1a544be17f40d60ba365bb084a342d41e0a Mon Sep 17 00:00:00 2001 From: Martin Braun <martin.braun@kit.edu> Date: Mon, 4 Feb 2013 15:34:41 +0100 Subject: modtool: bugfix, BLOCK_MAGIC should appear before %include --- gr-utils/src/python/modtool/modtool_add.py | 2 +- gr-utils/src/python/modtool/templates.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'gr-utils/src/python/modtool/templates.py') diff --git a/gr-utils/src/python/modtool/modtool_add.py b/gr-utils/src/python/modtool/modtool_add.py index 7ca375b6f9..e1d61cf0fb 100644 --- a/gr-utils/src/python/modtool/modtool_add.py +++ b/gr-utils/src/python/modtool/modtool_add.py @@ -246,6 +246,7 @@ class ModToolAdd(ModTool): if self._info['version'] == '36': mod_block_sep = '_' swig_block_magic_str = get_template('swig_block_magic', **self._info) + open(self._file['swig'], 'a').write(swig_block_magic_str) include_str = '#include "%s%s%s.h"' % ( self._info['modname'], mod_block_sep, @@ -257,7 +258,6 @@ class ModToolAdd(ModTool): regexp = re.compile('^%\{\n', re.MULTILINE) oldfile = regexp.sub('%%{\n%s\n' % include_str, oldfile, count=1) open(self._file['swig'], 'w').write(oldfile) - open(self._file['swig'], 'a').write(swig_block_magic_str) def _run_python_qa(self): """ Do everything that needs doing in the subdir 'python' to add diff --git a/gr-utils/src/python/modtool/templates.py b/gr-utils/src/python/modtool/templates.py index 8777357112..f405bcabbe 100644 --- a/gr-utils/src/python/modtool/templates.py +++ b/gr-utils/src/python/modtool/templates.py @@ -502,8 +502,8 @@ Templates['swig_block_magic'] = """#if $version == '37' #set $mod_block_sep = '_' #set $block_magic_version = '' #end if -%include "${modname}${mod_block_sep}${blockname}.h" GR_SWIG_BLOCK_MAGIC${block_magic_version}($modname, $blockname); +%include "${modname}${mod_block_sep}${blockname}.h" """ ## Old stuff -- cgit v1.2.3 From d83d461c68a53e6ac6652ef53384698d13cdb8ed Mon Sep 17 00:00:00 2001 From: Martin Braun <martin.braun@kit.edu> Date: Wed, 6 Feb 2013 09:50:49 +0100 Subject: modtool: fixed block_magic and %include order --- gr-utils/src/python/modtool/templates.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'gr-utils/src/python/modtool/templates.py') diff --git a/gr-utils/src/python/modtool/templates.py b/gr-utils/src/python/modtool/templates.py index f405bcabbe..8777357112 100644 --- a/gr-utils/src/python/modtool/templates.py +++ b/gr-utils/src/python/modtool/templates.py @@ -502,8 +502,8 @@ Templates['swig_block_magic'] = """#if $version == '37' #set $mod_block_sep = '_' #set $block_magic_version = '' #end if -GR_SWIG_BLOCK_MAGIC${block_magic_version}($modname, $blockname); %include "${modname}${mod_block_sep}${blockname}.h" +GR_SWIG_BLOCK_MAGIC${block_magic_version}($modname, $blockname); """ ## Old stuff -- cgit v1.2.3