def setup(self, options, args):
     # Don't call ModTool.setup(), that assumes an existing module.
     self._info['modname'] = options.module_name
     if self._info['modname'] is None:
         if len(args) >= 2:
             self._info['modname'] = args[1]
         else:
             self._info['modname'] = raw_input('Name of the new module: ')
     if not re.match('[a-zA-Z0-9_]+$', self._info['modname']):
         raise ModToolException('Invalid module name.')
     self._dir = options.directory
     if self._dir == '.':
         self._dir = './gr-%s' % self._info['modname']
     try:
         os.stat(self._dir)
     except OSError:
         pass  # This is what should happen
     else:
         raise ModToolException('The given directory exists.')
     if options.srcdir is None:
         options.srcdir = '/usr/local/share/gnuradio/modtool/gr-newmod'
     self._srcdir = gr.prefs().get_string('modtool', 'newmod_path',
                                          options.srcdir)
     if not os.path.isdir(self._srcdir):
         raise ModToolException('Could not find gr-newmod source dir.')
     self.options = options
     self._setup_scm(mode='new')
Beispiel #2
0
    def setup(self, options, args):
        ModTool.setup(self, options, args)

        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.')

        # first make sure the old block name is provided
        self._info['oldname'] = options.old_name
        if self._info['oldname'] is None:
            if len(args) >= 2:
                self._info['oldname'] = args[1]
            else:
                self._info['oldname'] = raw_input(
                    "Enter name of block/code to rename (without module name prefix): "
                )
        if not re.match('[a-zA-Z0-9_]+', self._info['oldname']):
            raise ModToolException('Invalid block name.')
        print "Block/code to rename identifier: " + self._info['oldname']
        self._info['fulloldname'] = self._info['modname'] + '_' + self._info[
            'oldname']

        # now get the new block name
        self._info['newname'] = options.new_name
        if self._info['newname'] is None:
            if len(args) >= 2:
                self._info['newname'] = args[2]
            else:
                self._info['newname'] = raw_input(
                    "Enter name of block/code (without module name prefix): ")
        if not re.match('[a-zA-Z0-9_]+', self._info['newname']):
            raise ModToolException('Invalid block name.')
        print "Block/code identifier: " + self._info['newname']
        self._info['fullnewname'] = self._info['modname'] + '_' + self._info[
            'newname']
 def run(self):
     """ Go, go, go! """
     mod_info = dict()
     mod_info['base_dir'] = self._get_base_dir(self._directory)
     if mod_info['base_dir'] is None:
         raise ModToolException(
             '{}' if self._python_readable else "No module found.")
     os.chdir(mod_info['base_dir'])
     mod_info['modname'] = get_modname()
     if mod_info['modname'] is None:
         raise ModToolException(
             '{}' if self._python_readable else "No module found.")
     if self._info['version'] == '36' and (os.path.isdir(
             os.path.join('include', mod_info['modname'])) or os.path.isdir(
                 os.path.join('include', 'gnuradio', mod_info['modname']))):
         self._info['version'] = '37'
     mod_info['version'] = self._info['version']
     if 'is_component' in self._info.keys() and self._info['is_component']:
         mod_info['is_component'] = True
     mod_info['incdirs'] = []
     mod_incl_dir = os.path.join(mod_info['base_dir'], 'include')
     if os.path.isdir(os.path.join(mod_incl_dir, mod_info['modname'])):
         mod_info['incdirs'].append(
             os.path.join(mod_incl_dir, mod_info['modname']))
     else:
         mod_info['incdirs'].append(mod_incl_dir)
     build_dir = self._get_build_dir(mod_info)
     if build_dir is not None:
         mod_info['build_dir'] = build_dir
         mod_info['incdirs'] += self._get_include_dirs(mod_info)
     if self._python_readable:
         print str(mod_info)
     else:
         self._pretty_print(mod_info)
    def setup(self, options, args):
        ModTool.setup(self, options, args)

        self._info['blocktype'] = options.block_type
        if self._info['blocktype'] is None:
            while self._info['blocktype'] not in self._block_types:
                self._info['blocktype'] = raw_input("Enter code type: ")
                if self._info['blocktype'] not in self._block_types:
                    print 'Must be one of ' + str(self._block_types)
        self._info['lang'] = options.lang
        if self._info['lang'] == 'c++':
            self._info['lang'] = 'cpp'
        print "Language: %s" % {
            'cpp': 'C++',
            'python': 'Python'
        }[self._info['lang']]

        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.')

        if self._info['blockname'] is None:
            if len(args) >= 2:
                self._info['blockname'] = args[1]
            else:
                self._info['blockname'] = raw_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.')
        print "Block/code identifier: " + self._info['blockname']
        self._info['fullblockname'] = self._info['modname'] + '_' + self._info[
            'blockname']
        self._info['license'] = self.setup_choose_license()

        if options.argument_list is not None:
            self._info['arglist'] = options.argument_list
        else:
            self._info['arglist'] = raw_input(
                'Enter valid argument list, including default arguments: ')

        if not (self._info['blocktype'] in ('noblock')
                or self._skip_subdirs['python']):
            self._add_py_qa = options.add_python_qa
            if self._add_py_qa is None:
                self._add_py_qa = ask_yes_no('Add Python QA code?', True)
        if self._info['lang'] == 'cpp':
            self._add_cc_qa = options.add_cpp_qa
            if self._add_cc_qa is None:
                self._add_cc_qa = ask_yes_no('Add C++ QA code?',
                                             not self._add_py_qa)
        self._skip_cmakefiles = options.skip_cmakefiles
        if self._info['version'] == 'autofoo' and not self._skip_cmakefiles:
            print "Warning: Autotools modules are not supported. ",
            print "Files will be created, but Makefiles will not be edited."
            self._skip_cmakefiles = True
        self._license_file = options.license_file
Beispiel #5
0
    def setup(self, options, args):
        ModTool.setup(self, options, args)
        self._info['blocktype'] = 'rfnoc'
        self._info['lang'] = 'cpp'
        if (self._skip_subdirs['lib']) or (self._skip_subdirs['python']):
            raise ModToolException('Missing or skipping relevant subdir.')
        if self._info['blockname'] is None:
            if len(args) >= 2:
                self._info['blockname'] = args[1]
            else:
                self._info['blockname'] = raw_input("Enter name of block/code (without module name prefix): ")
        if not re.match('^([a-zA-Z]+[0-9a-zA-Z]*)$', self._info['blockname']):
            raise ModToolException('Invalid block name.')
        print("Block/code identifier: " + self._info['blockname'])
        self._info['fullblockname'] = self._info['modname'] + '_' + self._info['blockname']
        if not options.license_file:
            self._info['copyrightholder'] = options.copyright
            if self._info['copyrightholder'] is None:
                self._info['copyrightholder'] = '<+YOU OR YOUR COMPANY+>'
            elif self._info['is_component']:
                print("For GNU Radio components the FSF is added as copyright holder")
        self._license_file = options.license_file
        self._info['license'] = self.setup_choose_license()
        if options.argument_list is not None:
            self._info['arglist'] = options.argument_list
        else:
            self._info['arglist'] = raw_input('Enter valid argument list, including default arguments: ')

        if not (self._info['blocktype'] in ('noblock') or self._skip_subdirs['python']):
            self._add_py_qa = options.add_python_qa
            if self._add_py_qa is None:
                self._add_py_qa = ask_yes_no('Add Python QA code?', True)
        self._add_cc_qa = options.add_cpp_qa
        if self._add_cc_qa is None:
            self._add_cc_qa = ask_yes_no('Add C++ QA code?', not self._add_py_qa)
        self._skip_cmakefiles = options.skip_cmakefiles
        if self._info['version'] == 'autofoo' and not self._skip_cmakefiles:
            print("Warning: Autotools modules are not supported. ",)
            print("Files will be created, but Makefiles will not be edited.")
            self._skip_cmakefiles = True
        #NOC ID parse
        self._info['noc_id'] = options.noc_id
        if self._info['noc_id'] is None:
            self._info['noc_id'] = id_process(raw_input("Block NoC ID (Hexadecimal): "))
        if not re.match(r'\A[0-9A-F]+\Z', self._info['noc_id']):
            raise ModToolException('Invalid NoC ID - Only Hexadecimal Values accepted.')
        self._skip_block_ctrl = options.skip_block_ctrl
        if self._skip_block_ctrl is None:
            self._skip_block_ctrl = ask_yes_no('Skip Block Controllers Generation? [UHD block ctrl files]', False)
        self._skip_block_interface = options.skip_block_interface
        if self._skip_block_interface is None:
            self._skip_block_interface = ask_yes_no('Skip Block interface files Generation? [GRC block ctrl files]', False)
 def run(self):
     """
     * Copy the example dir recursively
     * 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,
     try:
         shutil.copytree(self._srcdir, self._dir)
         os.chdir(self._dir)
     except OSError:
         raise ModToolException('Could not create directory %s.' %
                                self._dir)
     for root, dirs, files in os.walk('.'):
         for filename in files:
             f = os.path.join(root, filename)
             s = open(f, 'r').read()
             s = s.replace('howto', self._info['modname'])
             s = s.replace('HOWTO', self._info['modname'].upper())
             open(f, 'w').write(s)
             if filename.find('howto') != -1:
                 os.rename(
                     f,
                     os.path.join(
                         root,
                         filename.replace('howto', self._info['modname'])))
         if os.path.basename(root) == 'howto':
             os.rename(
                 root,
                 os.path.join(os.path.dirname(root), self._info['modname']))
     print "Done."
     if self.scm.init_repo(path_to_repo="."):
         print "Created repository... you might want to commit before continuing."
     print "Use 'gr_modtool add' to add a new block to this currently empty module."
Beispiel #7
0
    def _parse_cc_h(self, fname_cc):
        """ Go through a .cc and .h-file defining a block and return info """
        def _type_translate(p_type, default_v=None):
            """ Translates a type from C++ to GRC """
            translate_dict = {
                'float': 'float',
                'double': 'real',
                'int': 'int',
                'gr_complex': 'complex',
                'char': 'byte',
                'unsigned char': 'byte',
                'std::string': 'string',
                'std::vector<int>': 'int_vector',
                'std::vector<float>': 'real_vector',
                'std::vector<gr_complex>': 'complex_vector',
            }
            if p_type in ('int', ) and default_v is not None and len(
                    default_v) > 1 and default_v[:2].lower() == '0x':
                return 'hex'
            try:
                return translate_dict[p_type]
            except KeyError:
                return 'raw'

        def _get_blockdata(fname_cc):
            """ Return the block name and the header file name from the .cc file name """
            blockname = os.path.splitext(
                os.path.basename(fname_cc.replace('_impl.', '.')))[0]
            fname_h = (blockname + '.h').replace('_impl.', '.')
            blockname = blockname.replace(self._info['modname'] + '_', '', 1)
            return (blockname, fname_h)

        # Go, go, go
        print "Making GRC bindings for %s..." % fname_cc
        (blockname, fname_h) = _get_blockdata(fname_cc)
        try:
            parser = ParserCCBlock(
                fname_cc, os.path.join(self._info['includedir'], fname_h),
                blockname, self._info['version'], _type_translate)
        except IOError:
            raise ModToolException(
                "Can't open some of the files necessary to parse {}.".format(
                    fname_cc))

        return (parser.read_params(), parser.read_io_signature(), blockname)
Beispiel #8
0
    def setup(self, options, args):
        ModTool.setup(self, options, args)

        if self._info['blockname'] is None:
            if len(args) >= 2:
                self._info['blockname'] = args[1]
            else:
                self._info['blockname'] = raw_input(
                    "Enter name of block/code (without module name prefix): ")
        if os.path.isfile("./lib/" + self._info['blockname'] +
                          "_impl.cc") or os.path.isfile(
                              "./python/" + self._info['blockname'] + ".py"):
            raise ModToolException('The given blockname already exists!')
        if not re.match('[a-zA-Z0-9_]+', self._info['blockname']):
            raise ModToolException('Invalid block name.')
        print "Block/code identifier: " + self._info['blockname']
        self._info['fullblockname'] = self._info['modname'] + '_' + self._info[
            'blockname']

        self._info['blocktype'] = options.block_type
        if self._info['blocktype'] is None:
            # Print list out of blocktypes to user for reference
            print str(self._block_types)
            with SequenceCompleter(sorted(self._block_types)):
                while self._info['blocktype'] not in self._block_types:
                    self._info['blocktype'] = raw_input("Enter block type: ")
                    if self._info['blocktype'] not in self._block_types:
                        print 'Must be one of ' + str(self._block_types)

        # Allow user to specify language interactively if not set
        self._info['lang'] = options.lang
        if self._info['lang'] is None:
            language_candidates = ('cpp', 'python')
            with SequenceCompleter(language_candidates):
                while self._info['lang'] not in language_candidates:
                    self._info['lang'] = raw_input("Language (python/cpp): ")
        if self._info['lang'] == 'c++':
            self._info['lang'] = 'cpp'

        print "Language: %s" % {
            'cpp': 'C++',
            'python': 'Python'
        }[self._info['lang']]

        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.')

        if not options.license_file:
            self._info['copyrightholder'] = options.copyright
            if self._info['copyrightholder'] is None:
                user = getpass.getuser()
                git_user = self.scm.get_gituser()
                if git_user:
                    copyright_candidates = (user, git_user, 'GNU Radio')
                else:
                    copyright_candidates = (user, 'GNU Radio')
                with SequenceCompleter(copyright_candidates):
                    self._info['copyrightholder'] = raw_input(
                        "Please specify the copyright holder: ")
                    if not self._info['copyrightholder'] or self._info[
                            'copyrightholder'].isspace():
                        self._info['copyrightholder'] = "gr-" + self._info[
                            'modname'] + " author"
            elif self._info['is_component']:
                print "For GNU Radio components the FSF is added as copyright holder"
        self._license_file = options.license_file
        self._info['license'] = self.setup_choose_license()
        if options.argument_list is not None:
            self._info['arglist'] = options.argument_list
        else:
            self._info['arglist'] = raw_input(
                'Enter valid argument list, including default arguments: ')

        if not (self._info['blocktype'] in ('noblock')
                or self._skip_subdirs['python']):
            self._add_py_qa = options.add_python_qa
            if self._add_py_qa is None:
                self._add_py_qa = ask_yes_no('Add Python QA code?', True)
        if self._info['lang'] == 'cpp':
            self._add_cc_qa = options.add_cpp_qa
            if self._add_cc_qa is None:
                self._add_cc_qa = ask_yes_no('Add C++ QA code?',
                                             not self._add_py_qa)
        self._skip_cmakefiles = options.skip_cmakefiles
        if self._info['version'] == 'autofoo' and not self._skip_cmakefiles:
            print "Warning: Autotools modules are not supported. ",
            print "Files will be created, but Makefiles will not be edited."
            self._skip_cmakefiles = True