Example #1
0
def process_file(arg, filename):
    """Process the xcpp file. """
    cfg = get_cfg(arg, 'matlab', DEFAULTS)
    cfg['xcpp']['filename'] = extract_name(filename)
    xcfile = FileParser(filename).parse()
    cfg['matlab']['opt'] = cfg['matlab']['cxxopt']
    in_map, defs = check_inputs(xcfile, cfg, 'matlab')

    cfg['matlab']['cxx'] = 'mex'
    root = cfg['xcpp']['root']
    matlabdir = cfg['matlab']['wrapper']
    if matlabdir[0] == '/':
        base = matlabdir
    else:
        base = '%s/%s' % (root, matlabdir)
    cfg['matlab']['pkg'] = '%s/+%s' % (base, cfg['xcpp']['filename'])
    if not os.path.exists(cfg['matlab']['pkg']):
        os.mkdir(cfg['matlab']['pkg'])
    cfg['matlab']['opt'] = cfg['matlab']['mexopt']

    if defs:
        write_matlab_defs(cfg, defs)
    for func in xcfile.function:
        write_cpp_function(xcfile, func, cfg)
        write_matlab_file(func, cfg, in_map)
Example #2
0
def process_file(arg, filename):
    """Process the xcpp file. """
    cfg = get_cfg(arg, 'cpp', DEFAULTS)
    cfg['xcpp']['filename'] = extract_name(filename)
    xcfile = FileParser(filename).parse()
    check_inputs(xcfile, cfg, 'cpp')
    for func in xcfile.function:
        process_function(xcfile, cfg, func)
Example #3
0
def process_file(arg, filename):
    """Process the xcpp file. """
    cfg = get_cfg(arg, 'mathematica', DEFAULTS)
    cfg['xcpp']['filename'] = extract_name(filename)
    xcfile = FileParser(filename).parse()
    in_map, _ = check_inputs(xcfile, cfg, 'mathematica')
    write_cpp_file(xcfile, cfg, in_map)
    write_m_file(xcfile, cfg)
Example #4
0
def process_file(arg, filename):
    """Process the xcpp file. """
    cfg = get_cfg(arg, 'python', DEFAULTS)
    cfg['xcpp']['filename'] = extract_name(filename)
    xcfile = FileParser(filename).parse()
    in_map, defs = check_inputs(xcfile, cfg, 'python')
    write_cpp_file(xcfile, cfg)
    write_python_file(xcfile, cfg, in_map, defs)
Example #5
0
def valid_files(parsed_args, **_):
    """Return a list of valid files to edit."""
    cfg = get_cfg(parsed_args, 'xcpp')
    root = cfg['xcpp']['root']
    paths = cfg['xcpp']['path'].split(':')
    choices = []
    for path in paths:
        if path == '.' or path[0] in ['/']:
            abs_path = path
        else:
            abs_path = '%s/%s' % (root, path)
        try:
            choices.extend([fname for fname in listdir(abs_path)
                            if isfile(join(abs_path, fname))])
        except OSError:
            pass
    return choices
Example #6
0
def _get_filename(arg):
    """Helper function. """
    if arg.inputfile == '_':
        error("ERROR: Missing inputfile. Use -h to see usage.\n")
    cfg = get_cfg(arg, 'xcpp')
    root = cfg['xcpp']['root']
    paths = cfg['xcpp']['path'].split(':')

    is_file = False
    for path in paths:
        if path == '.' or path[0] in ['/']:
            abs_path = '%s/%s' % (path, arg.inputfile)
        else:
            abs_path = '%s/%s/%s' % (root, path, arg.inputfile)
        if os.path.exists(abs_path):
            is_file = True
            break
    if not is_file:
        fname = '`%s` in\n  %s' % (arg.inputfile, '\n  '.join(paths))
        error("ERROR: Unable to find %s\n" % fname)
    return abs_path