def _write_cpp_file(contents, cfg): """Helper function. """ root = cfg['xcpp']['root'] cppdir = cfg['python']['dir'] if cppdir[0] == '/': base = cppdir else: base = '%s/%s' % (root, cppdir) filename = cfg['xcpp']['filename'] in_fname = '%s/%s_pylib.cpp' % (base, filename) trace('+ inspecting %s_pylib.cpp ... ' % filename) write_file(in_fname, contents) return in_fname
def _write_py_file(contents, cfg): """Helper function for process_function. """ root = cfg['xcpp']['root'] dest_dir = cfg['python']['wrapper'] if dest_dir[0] == '/': base = dest_dir else: base = '%s/%s' % (root, dest_dir) filename = cfg['xcpp']['filename'] in_fname = '%s/%s.py' % (base, filename) trace('+ inspecting %s.py ... ' % filename) write_file(in_fname, contents) return in_fname
def write_cpp_code(content, cfg): """Helper function for process_function. """ root = cfg['xcpp']['root'] cppdir = cfg['mathematica']['dir'] if cppdir[0] == '/': base = cppdir else: base = '%s/%s' % (root, cppdir) filename = cfg['xcpp']['filename'] in_fname = '%s/%s_mathlink.cpp' % (base, filename) trace('+ inspecting %s_mathlink.cpp ... ' % filename) write_file(in_fname, content) return in_fname
def write_matlab_file(func, cfg, in_map): """Writes the m file. """ pkg = cfg['xcpp']['filename'] content = M_FILE.format(doc=_format_help(func, pkg), pkg=pkg, name=func.name, args=_args(func.param), load=cfg['matlab']['load'], dump=cfg['matlab']['dump'], inputs=_format_input(func.param, in_map)) base = cfg['matlab']['pkg'] pkg = cfg['xcpp']['filename'] in_fname = '%s/%s.m' % (base, func.name) trace(' + inspecting +%s/%s.m ... ' % (pkg, func.name)) write_file(in_fname, content)
def _write_file(contents, func, cfg): """Helper function for process_function. """ root = cfg['xcpp']['root'] cppdir = cfg['cpp']['dir'] if cppdir[0] == '/' or cppdir == '.': base = cppdir else: base = '%s/%s' % (root, cppdir) filename = cfg['xcpp']['filename'] in_fname = '%s/%s-%s.cpp' % (base, filename, func.name) msg = '[%d] inspecting %s-%s.cpp ... ' trace(msg % (func.num, filename, func.name)) write_file(in_fname, contents) return in_fname
def write_matlab_defs(cfg, defs): """Write a file containing the definition used in the package. """ contents = DEF_FILE % (cfg['xcpp']['filename'], date(), _format_defs(defs)) base = cfg['matlab']['pkg'] pkg = cfg['xcpp']['filename'] in_fname = '%s/xc_def.m' % base trace('* inspecting +%s/xc_def.m ... ' % pkg) write_file(in_fname, contents) if defs.keys(): inputs = 'The posible inputs are: \n%%\n%% %s' inputs = inputs % '\n%% '.join(defs.keys()) else: inputs = '' contents = XC_STRUCT_FILE.format(pkg=pkg, date=date(), inputs=inputs) in_fname = '%s/xc_struct.m' % base trace('* inspecting +%s/xc_struct.m ... ' % pkg) write_file(in_fname, contents)
def write_m_file(xcf, cfg): """Writes the m file. """ root = cfg['xcpp']['root'] app = cfg['mathematica']['app'] usage = '\n\n'.join([_format_help(func, cfg) for func in xcf.function]) pkgname = cfg['xcpp']['filename'] funcnames = ',\n '.join([m_name(func.name) for func in xcf.function]) errors = '\n'.join([_format_error(func, cfg) for func in xcf.function]) content = M_FILE.format(date=date(), app=app, pkgname=pkgname, error=errors, usage=usage, funcnames=funcnames) dest_dir = '%s/%s' % (cfg['mathematica']['mma'], app) if dest_dir[0] == '/': base = dest_dir else: base = '%s/%s' % (root, dest_dir) filename = cfg['xcpp']['filename'] in_fname = '%s/%s.m' % (base, filename) trace('+ inspecting %s/%s.m ... ' % (app, filename)) write_file(in_fname, content)