From fc696a9ff3ef7bbeb2f7420cead255d950a7ba3b Mon Sep 17 00:00:00 2001 From: Hilton Bristow Date: Thu, 27 Mar 2014 14:52:23 +1000 Subject: [PATCH] Improved standalone importing behaviour and creation of nested directories --- modules/matlab/generator/gen_matlab.py | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/modules/matlab/generator/gen_matlab.py b/modules/matlab/generator/gen_matlab.py index 9f0975d..36d588c 100644 --- a/modules/matlab/generator/gen_matlab.py +++ b/modules/matlab/generator/gen_matlab.py @@ -1,4 +1,8 @@ #!/usr/bin/env python +import sys, re, os, time +from string import Template +from parse_tree import ParseTree, todict, constants +from filters import * class MatlabWrapperGenerator(object): """ @@ -22,9 +26,14 @@ class MatlabWrapperGenerator(object): The output_dir specifies the directory to write the generated sources to. """ + # dynamically import the parsers + from jinja2 import Environment, FileSystemLoader + import hdr_parser + import rst_parser + # parse each of the files and store in a dictionary # as a separate "namespace" - parser = CppHeaderParser() + parser = hdr_parser.CppHeaderParser() rst = rst_parser.RstParser(parser) rst_parser.verbose = False rst_parser.show_warnings = False @@ -91,13 +100,13 @@ class MatlabWrapperGenerator(object): output_class_dir = output_dir+'/+cv' output_map_dir = output_dir+'/map' if not os.path.isdir(output_source_dir): - os.mkdir(output_source_dir) + os.makedirs(output_source_dir) if not os.path.isdir(output_private_dir): - os.mkdir(output_private_dir) + os.makedirs(output_private_dir) if not os.path.isdir(output_class_dir): - os.mkdir(output_class_dir) + os.makedirs(output_class_dir) if not os.path.isdir(output_map_dir): - os.mkdir(output_map_dir) + os.makedirs(output_map_dir) # populate templates for namespace in parse_tree.namespaces: @@ -168,7 +177,6 @@ if __name__ == "__main__": """ # parse the input options - import sys, re, os, time from argparse import ArgumentParser parser = ArgumentParser() parser.add_argument('--jinja2') @@ -185,13 +193,6 @@ if __name__ == "__main__": sys.path.append(args.hdrparser) sys.path.append(args.rstparser) - from string import Template - from hdr_parser import CppHeaderParser - import rst_parser - from parse_tree import ParseTree, todict, constants - from filters import * - from jinja2 import Environment, FileSystemLoader - # create the generator mwg = MatlabWrapperGenerator() mwg.gen(args.moduleroot, args.modules, args.extra, args.outdir) -- 2.7.4