Exemple #1
0
def generate(install_dir):
    context = {
        'fields': create_fields(),
    }

    with template_utils.open_output(install_dir, 'wireshark/openflow.lua') as out:
        template_utils.render_template(out, "openflow.lua", [templates_dir], context)
Exemple #2
0
def generate(install_dir):
    context = {
        'fields': create_fields(),
    }

    with template_utils.open_output(install_dir, 'wireshark/openflow.lua') as out:
        template_utils.render_template(out, "openflow.lua", [templates_dir], context)
Exemple #3
0
    def render_class(self, clazz, template, src_dir=None, **context):
        if not src_dir:
            src_dir = "gen-src/main/java/"

        context['class_name'] = clazz.name
        context['package'] = clazz.package
        context['template_dir'] = self.templates_dir
        context['genopts'] = self.gen_opts

        filename = os.path.join(
            self.basedir, src_dir,
            "%s/%s.java" % (clazz.package.replace(".", "/"), clazz.name))
        dirname = os.path.dirname(filename)
        if not os.path.exists(dirname):
            os.makedirs(dirname)
        prefix = '//::(?=[ \t]|$)'
        logger.debug("rendering filename: %s" % filename)
        with open(filename, "w") as f:
            template_utils.render_template(f,
                                           template, [self.templates_dir],
                                           context,
                                           prefix=prefix)

        try:
            cleaner = ImportCleaner(filename)
            cleaner.find_used_imports()
            cleaner.rewrite_file(filename)
        except:
            logger.info('Cannot clean imports from file %s' % filename)
Exemple #4
0
    def render_class(self, clazz, template, src_dir=None, **context):
        if not src_dir:
            src_dir = "gen-src/main/java/"

        context['class_name'] = clazz.name
        context['package'] = clazz.package
        context['template_dir'] = self.templates_dir
        context['genopts']= self.gen_opts

        filename = os.path.join(self.basedir, src_dir, "%s/%s.java" % (clazz.package.replace(".", "/"), clazz.name))
        dirname = os.path.dirname(filename)
        if not os.path.exists(dirname):
            os.makedirs(dirname)
        prefix = '//::(?=[ \t]|$)'
        logger.debug("rendering filename: %s" % filename)
        with open(filename, "w") as f:
            template_utils.render_template(f, template, [self.templates_dir], context, prefix=prefix)

        try:
            cleaner = ImportCleaner(filename)
            cleaner.find_used_imports()
            cleaner.rewrite_file(filename)
        except:
            logger.info('Cannot clean imports from file %s' % filename)
Exemple #5
0
def generate(ir, output):
    os.mkdir(output)
    out = open(os.path.join(output, "__init__.py"), 'w')

    render_template(out, "header.py", {})

    for x in ir:
        out.write("\n")
        if isinstance(x, XDRConst):
            render_template(out, "const.py", dict(const=x))
        elif isinstance(x, XDREnum):
            render_template(out, "enum.py", dict(enum=x))
        elif isinstance(x, XDRStruct):
            render_template(out, "struct.py", dict(struct=x))
        elif isinstance(x, XDRUnion):
            render_template(out, "union.py", dict(union=x))
        elif isinstance(x, XDRTypedef):
            render_template(out, "typedef.py", dict(typedef=x))

    out.write("\n__all__ = " + repr([x.name for x in ir if not isinstance(x, XDRTypedef)]))
Exemple #6
0
def render_template(out, name, **context):
    template_utils.render_template(out, name, [templates_dir], context)
Exemple #7
0
def render_template(out, name, **context):
    template_utils.render_template(out, name, template_path, context)
Exemple #8
0
def generate(ir, output):
    os.mkdir(output)
    out = open(os.path.join(output, "__init__.py"), 'w')

    constants = collect_constants(ir)

    render_template(out, "header.py", {})

    for x in ir:
        out.write("\n")
        if isinstance(x, XDRConst):
            render_template(out, "const.py", dict(const=x))
        elif isinstance(x, XDREnum):
            render_template(out, "enum.py", dict(enum=x))
        elif isinstance(x, XDRStruct):
            render_template(out, "struct.py", dict(struct=x))
        elif isinstance(x, XDRUnion):
            render_template(out, "union.py", dict(union=x,
                                                  constants=constants))
        elif isinstance(x, XDRTypedef):
            render_template(out, "typedef.py", dict(typedef=x))

    out.write("\n__all__ = " +
              repr([x.name for x in ir if not isinstance(x, XDRTypedef)]))