Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ModTool: Add features and update functionalities #1873

Closed
wants to merge 82 commits into from
Closed
Show file tree
Hide file tree
Changes from 77 commits
Commits
Show all changes
82 commits
Select commit Hold shift + click to select a range
27c87e2
CLI parsing: Change from Argparse to Click
swap-nil7 May 18, 2018
84f70ab
modtool: Remove redundant imports and functions
swap-nil7 May 18, 2018
19bfb95
gr_modtool: replace immutable namedtuples by class objects
swap-nil7 May 19, 2018
ac55488
modtool: Update SequenceCompleter for py3k compatibility
swap-nil7 May 20, 2018
4e0cab8
CLI: move commands to respective modules
swap-nil7 May 21, 2018
2da6d9c
CLI: add missing imports, fix the issue with click commands of submod…
swap-nil7 May 21, 2018
9d21470
modtool: Add a Click Plugin Architecture
swap-nil7 May 22, 2018
06baf14
CLI: Add short_help for gr_modtool --help
swap-nil7 May 23, 2018
18efc42
Plugin Architecture: Multicommand to Group
swap-nil7 May 24, 2018
a01a146
Plugin Architecture: Update for external plugins
swap-nil7 May 25, 2018
8d06d19
External Plugins: Complete
swap-nil7 May 28, 2018
da7c843
CLI: visual changes
swap-nil7 May 28, 2018
405447a
gr_modtool: Remove wildcard import statement
swap-nil7 May 28, 2018
db7f28d
modtool_base: newline at the end of file
swap-nil7 May 28, 2018
c60f507
Modtool: Remove unused imports and fix Pylint issues
swap-nil7 May 29, 2018
f64f6ed
CLI: use SimpleNamespace
swap-nil7 May 30, 2018
385db2e
API: move the code to modtool.core
swap-nil7 May 31, 2018
cb0d0cc
API: shift click code to the cli folder
swap-nil7 May 31, 2018
9f7b1e6
API: Add CMakeLists
swap-nil7 Jun 1, 2018
2bfcca2
API: Remove click code from the core maintaining the functionality
swap-nil7 Jun 2, 2018
c7f0723
CLI: move redundant code to the base
swap-nil7 Jun 4, 2018
ff2a45d
ModToolAdd: Shift portion from core to cli
swap-nil7 Jun 4, 2018
34cd898
ModToolAdd: Separate CLI and Core
swap-nil7 Jun 5, 2018
2b39810
ModToolAdd: Separated Core and CLI
swap-nil7 Jun 6, 2018
6224825
ModToolDisable: Core/CLI split
swap-nil7 Jun 6, 2018
fb6da18
ModToolRename: Core/CLI split
swap-nil7 Jun 6, 2018
01ae6e5
ModToolRemove: Core/CLI split
swap-nil7 Jun 6, 2018
21da87a
ModToolMakeXML: Core/CLI split
swap-nil7 Jun 6, 2018
3ec3556
grc_xml_generator: Outfile must be in binary mode
swap-nil7 Jun 6, 2018
02db700
ModtoolNewModule: Core/CLI split
swap-nil7 Jun 7, 2018
536f6c5
Core/CLI split: Clean up
swap-nil7 Jun 7, 2018
1f82ef3
Core/Cli split: Remove unused imports
swap-nil7 Jun 7, 2018
3fe0a63
ModToolNewModule: Update help page
swap-nil7 Jun 8, 2018
cfbb53e
API: Improve checks for Core modules
swap-nil7 Jun 12, 2018
f192744
ModToolAdd: add missing condition
swap-nil7 Jun 13, 2018
428e8d5
ModTool: Move some modules setup to __init__
swap-nil7 Jun 13, 2018
3e2e591
Modtool: Complete Base Module and Add module
swap-nil7 Jun 13, 2018
3391edd
Core/CLI split: Update CLI and Core modules
swap-nil7 Jun 13, 2018
e939c4a
ModToolMakeXML: Shift the setup code to __init__
swap-nil7 Jun 14, 2018
a3428bc
ModToolNewModule: moved the setup code to __init__
swap-nil7 Jun 14, 2018
7123996
ModToolRename: shift the setup code into __init__
swap-nil7 Jun 14, 2018
ea67a4f
ModToolRemove: Shift the setup code into __init__
swap-nil7 Jun 14, 2018
b6791f2
ModTool: Remove unused imports
swap-nil7 Jun 14, 2018
7424145
ModTool CLI: Change absolute imports to relative
swap-nil7 Jun 14, 2018
189dfd4
Core and CLI: Rename modules
swap-nil7 Jun 14, 2018
f4ba70c
ModTool Core: Avoid breaking of code for no arguments
swap-nil7 Jun 14, 2018
65fa252
CLI: rename modules
swap-nil7 Jun 15, 2018
91df381
Split core, template, and utility modules
swap-nil7 Jun 15, 2018
ec973c2
Core Modules: Replace *args with actual arguments
swap-nil7 Jun 15, 2018
ed262de
ModTool: Change some of the protected class members to public
swap-nil7 Jun 15, 2018
cc77775
ModTool Core: Specify module name
swap-nil7 Jun 15, 2018
c9b3c3c
replace raw 'open' with 'with open(file) as f
swap-nil7 Jun 18, 2018
1d28005
Modtool Core: Replace print with logging.logger
swap-nil7 Jun 19, 2018
a507236
API: modify classes so that the values can be assigned later
swap-nil7 Jun 20, 2018
36dfeb7
ModTool base: shift code from init to other functions to enable the c…
swap-nil7 Jun 20, 2018
08b5d2c
CLI: validation must occur at instantiation
swap-nil7 Jun 20, 2018
506ad89
ModTool: make the logger global
swap-nil7 Jun 20, 2018
3ce04e6
ModTool: Add test for modtool API
swap-nil7 Jun 21, 2018
44e6abe
ModTool: Add logger to the tools
swap-nil7 Jun 21, 2018
94bec4f
ModTool: Remove call to a protected method from CLI newmod
swap-nil7 Jun 22, 2018
99d8df9
ModToolMakeXML: decode bytes generated by xml.etree.Element.tostring
swap-nil7 Jun 23, 2018
9c6a59f
ModTool CLI: Add functional behaviour
swap-nil7 Jun 22, 2018
fc5c59d
ModTool: Add SequenceComplter, Fix bug for rename
swap-nil7 Jun 26, 2018
9df8d9e
ModTool: Add colors to the logger
swap-nil7 Jun 26, 2018
0138433
ModTool: Add colors if colorama is installed
swap-nil7 Jun 27, 2018
17df7e5
ModTool: Color Enhancement
swap-nil7 Jun 27, 2018
8b39d51
ModTool: Remove redundant styling of input
swap-nil7 Jun 27, 2018
1966185
ModTool: Interchange color of input and logger info
swap-nil7 Jun 27, 2018
6b20e21
ModTool Add: Split _run_lib to separate qa code
swap-nil7 Jun 28, 2018
8da4abd
ModTool: Basic Pylint fixes
swap-nil7 Jun 28, 2018
0d8d06f
ModTool Python Templates: Relative imports
swap-nil7 Jun 28, 2018
3ca51e3
ModTool Tests: Add Pylint Tests (commented)
swap-nil7 Jun 28, 2018
685340c
ModTool: Replace XML Generator by YAML Generator
swap-nil7 Jul 3, 2018
4f07af1
YAML Generator: Lint fixes and append .block to file name
swap-nil7 Jul 4, 2018
08d06a5
ModTool Templates: Replace XML template with YAML template
swap-nil7 Jul 4, 2018
758aa2f
ModTool: Remove future imports and update copyright templates
swap-nil7 Jul 4, 2018
71f9c68
ModTool: Update README and restructure CMakeLists
swap-nil7 Jul 5, 2018
c174d46
Uncomment pylint tests, use str.format, restructure imports
swap-nil7 Jul 6, 2018
c1757a9
ModTool: Add XML to YAML Converter (option: update)
swap-nil7 Jul 10, 2018
5b6a877
ModTool Update: Add feature for conversion of all XML bindings
swap-nil7 Jul 11, 2018
31608d2
ModTool: Minor enhancements
swap-nil7 Jul 18, 2018
a9b88a4
Modtool: Import modules from future for Py2k compatibility
swap-nil7 Oct 15, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion gr-utils/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,4 @@ if(ENABLE_GR_UTILS)
add_subdirectory(python/utils)
add_subdirectory(python/modtool)


endif(ENABLE_GR_UTILS)
30 changes: 10 additions & 20 deletions gr-utils/python/modtool/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2011 Free Software Foundation, Inc.
# Copyright 2018 Free Software Foundation, Inc.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When modifying a file, don't replace the year but add it to keep track of its changes

# Copyright 2011, 2018 Free Software Foundation, Inc.

This goes for all mods on the Copyright year that you made

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The files that are newly created will have only 2018. All the core scripts and the tools scripts have a previous copyright intact.

#
# This file is part of GNU Radio
#
Expand All @@ -21,28 +21,10 @@ include(GrPython)

GR_PYTHON_INSTALL(FILES
__init__.py
cmakefile_editor.py
code_generator.py
grc_xml_generator.py
modtool_add.py
modtool_base.py
modtool_disable.py
modtool_info.py
modtool_makexml.py
modtool_newmod.py
modtool_rm.py
modtool_rename.py
parser_cc_block.py
scm.py
templates.py
util_functions.py
DESTINATION ${GR_PYTHON_DIR}/gnuradio/modtool
)

set(GR_PKG_MODTOOL_DATA_DIR ${GR_PKG_DATA_DIR}/modtool)
install(DIRECTORY gr-newmod
DESTINATION ${GR_PKG_MODTOOL_DATA_DIR}
)
set(GR_PKG_MODTOOL_DATA_DIR ${GR_PKG_DATA_DIR}/modtool/templates)


########################################################################
Expand All @@ -60,3 +42,11 @@ install(
DESTINATION ${GR_PREFSDIR}
)

########################################################################
# Add subdirectories
########################################################################
add_subdirectory(core)
add_subdirectory(cli)
add_subdirectory(tools)
add_subdirectory(templates)
add_subdirectory(tests)
24 changes: 17 additions & 7 deletions gr-utils/python/modtool/README.modtool
Original file line number Diff line number Diff line change
@@ -1,19 +1,29 @@
gr_modtool: Swiss Army Knife for editing GNU Radio modules and -components.

Adding a new subcommand
=======================
Adding a new subcommand for Command Line Interface
==================================================

* Add a new file called modtool_SUBCOMMAND
* Add a new file called SUBCOMMAND in the cli directory
* Create a function cli with the decorator @click.command or @click.group
* Add the necessary options for the command or command group
* Add that file to __init__.py and CMakeLists.txt in the cli directory


Adding a new subcommand for Exposing as an API
==============================================

* Add a new file called SUBCOMMAND in the core directory
* Have a look at the other subcommands, it must inherit from ModTool
* Add that file to __init__.py and CMakeLists.txt
* Add that file to __init__.py and CMakeLists.txt in the core directory


The gr-newmod directory inside the templates directory
======================================================

The gr-newmod directory
=======================
This dir basically contains a copy of gr-howto-write-a-block from the gnuradio
sources, with some differences:
- All example blocks, apps, grc files (...) and references thereto in the
CMake files are removed
- In the top-level CMake file, the project is called 'gr-howto'.
- Any time anything relevant is changed in gr-howto-write-a-block, it should
be changed here, too.

37 changes: 0 additions & 37 deletions gr-utils/python/modtool/__init__.py
Original file line number Diff line number Diff line change
@@ -1,37 +0,0 @@
from __future__ import absolute_import
from __future__ import unicode_literals
#
# Copyright 2013-2014 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.
#

from .cmakefile_editor import CMakeFileEditor
from .grc_xml_generator import GRCXMLGenerator
from .modtool_base import ModTool, ModToolException, get_modtool_modules
from .modtool_add import ModToolAdd
from .modtool_disable import ModToolDisable
from .modtool_info import ModToolInfo
from .modtool_makexml import ModToolMakeXML
from .modtool_newmod import ModToolNewModule
from .modtool_rm import ModToolRemove
from .modtool_rename import ModToolRename
from .templates import Templates
# Leave this at the end
from .parser_cc_block import ParserCCBlock
from .util_functions import *
33 changes: 33 additions & 0 deletions gr-utils/python/modtool/cli/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Copyright 2018 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.

include(GrPython)

GR_PYTHON_INSTALL(FILES
__init__.py
add.py
base.py
disable.py
info.py
makeyaml.py
newmod.py
rm.py
rename.py
DESTINATION ${GR_PYTHON_DIR}/gnuradio/modtool/cli
)
23 changes: 23 additions & 0 deletions gr-utils/python/modtool/cli/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#
# Copyright 2018 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.
#

from .base import cli, common_params, block_name, ModToolException
from .base import setup_cli_logger, cli_input
130 changes: 130 additions & 0 deletions gr-utils/python/modtool/cli/add.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
#
# Copyright 2018 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 re

import click

from ..core import ModToolAdd
from ..tools import SequenceCompleter, ask_yes_no
from .base import ModToolException
from .base import common_params, block_name, run, cli_input


@click.command('add')
@click.option('-t', '--block-type', type=click.Choice(ModToolAdd.block_types),
help="One of {}.".format(', '.join(ModToolAdd.block_types)))
@click.option('--license-file',
help="File containing the license header for every source code file.")
@click.option('--copyright',
help="Name of the copyright holder (you or your company) MUST be a quoted string.")
@click.option('--argument-list', default="",
help="The argument list for the constructor and make functions.")
@click.option('--add-python-qa', is_flag=True, default=None,
help="If given, Python QA code is automatically added if possible.")
@click.option('--add-cpp-qa', is_flag=True, default=None,
help="If given, C++ QA code is automatically added if possible.")
@click.option('--skip-cmakefiles', is_flag=True,
help="If given, only source files are written, but CMakeLists.txt files are left unchanged.")
@click.option('-l', '--lang', type=click.Choice(ModToolAdd.language_candidates),
help="Programming Language")
@common_params
@block_name
def cli(**kwargs):
"""Adds a block to the out-of-tree module."""
kwargs['cli'] = True
self = ModToolAdd(**kwargs)
click.secho("GNU Radio module name identified: " + self.info['modname'], fg='green')
get_blocktype(self)
get_lang(self)
click.secho("Language: {}".format({'cpp': 'C++', 'python': 'Python'}[self.info['lang']]), fg='green')
if ((self.skip_subdirs['lib'] and self.info['lang'] == 'cpp')
or (self.skip_subdirs['python'] and self.info['lang'] == 'python')):
raise ModToolException('Missing or skipping relevant subdir.')
get_blockname(self)
click.secho("Block/code identifier: " + self.info['blockname'], fg='green')
self.info['fullblockname'] = self.info['modname'] + '_' + self.info['blockname']
if not self.license_file:
get_copyrightholder(self)
self.info['license'] = self.setup_choose_license()
get_arglist(self)
get_py_qa(self)
get_cpp_qa(self)
if self.info['version'] == 'autofoo' and not self.skip_cmakefiles:
click.secho("Warning: Autotools modules are not supported. "+
"Files will be created, but Makefiles will not be edited.",
fg='yellow')
self.skip_cmakefiles = True
run(self)

def get_blocktype(self):
""" Get the blocktype of the block to be added """
if self.info['blocktype'] is None:
click.secho(str(self.block_types), fg='yellow')
with SequenceCompleter(self.block_types):
while self.info['blocktype'] not in self.block_types:
self.info['blocktype'] = cli_input("Enter block type: ")
if self.info['blocktype'] not in self.block_types:
click.secho('Must be one of ' + str(self.block_types), fg='yellow')

def get_lang(self):
""" Get the Programming Language of the block to be added """
if self.info['lang'] is None:
with SequenceCompleter(self.language_candidates):
while self.info['lang'] not in self.language_candidates:
self.info['lang'] = cli_input("Language (python/cpp): ")
if self.info['lang'] == 'c++':
self.info['lang'] = 'cpp'

def get_blockname(self):
""" Get the blockname"""
if self.info['blockname'] is None:
while not self.info['blockname'] or self.info['blockname'].isspace():
self.info['blockname'] = cli_input("Enter name of block/code (without module name prefix): ")
if not re.match('[a-zA-Z0-9_]+', self.info['blockname']):
raise ModToolException('Invalid block name.')

def get_copyrightholder(self):
""" Get the copyrightholder of the block to be added """
if self.info['copyrightholder'] is None:
self.info['copyrightholder'] = '<+YOU OR YOUR COMPANY+>'
elif self.info['is_component']:
click.secho("For GNU Radio components the FSF is added as copyright holder",
fg='cyan')

def get_arglist(self):
""" Get the argument list of the block to be added """
if self.info['arglist'] is not None:
self.info['arglist'] = cli_input('Enter valid argument list, including default arguments: ')

def get_py_qa(self):
""" Get a boolean value for addition of py_qa """
if not (self.info['blocktype'] in ('noblock') or self.skip_subdirs['python']):
if self.add_py_qa is None:
self.add_py_qa = ask_yes_no(click.style('Add Python QA code?', fg='cyan'), True)

def get_cpp_qa(self):
""" Get a boolean value for addition of cpp_qa """
if self.info['lang'] == 'cpp':
if self.add_cc_qa is None:
self.add_cc_qa = ask_yes_no(click.style('Add C++ QA code?', fg='cyan'),
not self.add_py_qa)
Loading