当前位置: 首页>>代码示例>>Python>>正文


Python jinja2.PackageLoader方法代码示例

本文整理汇总了Python中jinja2.PackageLoader方法的典型用法代码示例。如果您正苦于以下问题:Python jinja2.PackageLoader方法的具体用法?Python jinja2.PackageLoader怎么用?Python jinja2.PackageLoader使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在jinja2的用法示例。


在下文中一共展示了jinja2.PackageLoader方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

# 需要导入模块: import jinja2 [as 别名]
# 或者: from jinja2 import PackageLoader [as 别名]
def __init__(self, template_file=None, flag_dep=False):
        """Constructor

        The `Diagram` class constructor simply initializes object lists.  It
        does not create objects or relationships.
        """
        self._flag_dep = flag_dep
        self.clear()
        loader_list = []
        if template_file is not None:
            loader_list.append(jinja2.FileSystemLoader(
                os.path.abspath(os.path.dirname(template_file))))
            self._template_file = os.path.basename(template_file)
        else:
            self._template_file = 'default.puml'
        loader_list.append(jinja2.PackageLoader('hpp2plantuml', 'templates'))
        self._env = jinja2.Environment(loader=jinja2.ChoiceLoader(
            loader_list), keep_trailing_newline=True) 
开发者ID:thibaultmarin,项目名称:hpp2plantuml,代码行数:20,代码来源:hpp2plantuml.py

示例2: _init

# 需要导入模块: import jinja2 [as 别名]
# 或者: from jinja2 import PackageLoader [as 别名]
def _init(cls):

        if cls.package_name is None:
            raise NotImplementedError("Package name not given")

        if cls.spec_template_file is None:
            raise NotImplementedError("Spec file not given")

        loader = PackageLoader(cls.package_name, "")
        env = Environment(loader=loader)
        template = env.get_template(cls.spec_template_file)
        tdict = yaml.safe_load(StringIO(template.render()))
        tdict = jsonref.loads(json.dumps(tdict))

        # TODO - Check if keys are present
        cls.provider_spec = tdict["components"]["schemas"]["provider_spec"]
        cls.Validator = StrictDraft7Validator(cls.provider_spec) 
开发者ID:nutanix,项目名称:calm-dsl,代码行数:19,代码来源:base.py

示例3: _render_config_template

# 需要导入模块: import jinja2 [as 别名]
# 或者: from jinja2 import PackageLoader [as 别名]
def _render_config_template(
    ip,
    port,
    username,
    password,
    project_name,
    log_level,
    schema_file="config.ini.jinja2",
):
    """renders the config template"""

    loader = PackageLoader(__name__, "")
    env = Environment(loader=loader)
    template = env.get_template(schema_file)
    text = template.render(
        ip=ip,
        port=port,
        username=username,
        password=password,
        project_name=project_name,
        log_level=log_level,
    )
    return text.strip() + os.linesep 
开发者ID:nutanix,项目名称:calm-dsl,代码行数:25,代码来源:config.py

示例4: __init__

# 需要导入模块: import jinja2 [as 别名]
# 或者: from jinja2 import PackageLoader [as 别名]
def __init__(self, redmine_server, redmine_api_key, project_name_or_identifier, issues_dirname, redmine2github_id_map_filename):
        """
        Constructor
        
        :param redmine_server: str giving the url of the redmine server.  e.g. https://redmine.myorg.edu/
        :param redmine_api_key: str with a redmine api key
        :param project_name_or_identifier: str or int with either the redmine project id or project identifier
        :param issues_base_directory: str, directory to download the redmine issues in JSON format.  Directory will be crated
        """
        self.redmine_server = redmine_server
        self.redmine_api_key = redmine_api_key
        self.project_name_or_identifier = project_name_or_identifier
        self.issue_dirname = issues_dirname
        msg('redmine2github_id_map_filename: %s' % redmine2github_id_map_filename)
        self.redmine2github_id_map = json.loads(open(redmine2github_id_map_filename, 'rU').read())
        
        self.redmine_conn = None
        self.redmine_project = None
        
        self.jinja_env = Environment(loader=PackageLoader('redmine_ticket', 'templates'))
        
        self.setup() 
开发者ID:IQSS,项目名称:redmine2github,代码行数:24,代码来源:redmine_issue_updater.py

示例5: create

# 需要导入模块: import jinja2 [as 别名]
# 或者: from jinja2 import PackageLoader [as 别名]
def create(self, variables, md_output, pdf_output):
        env = Environment(loader=PackageLoader('qanta', 'reporting/templates'))
        template = env.get_template(self.template)
        markdown = template.render(variables)
        if md_output is not None:
            with open(md_output, 'w') as f:
                f.write(markdown)
        try:
            import pypandoc
            pypandoc.convert_text(
                markdown,
                'pdf',
                format='md',
                outputfile=pdf_output,
                extra_args=['-V', 'geometry:margin=.75in']
            )
        except Exception as e:
            log.warn('Pandoc was not installed or there was an error calling it, omitting PDF report')
            log.warn(str(e)) 
开发者ID:Pinafore,项目名称:qb,代码行数:21,代码来源:report_generator.py

示例6: slurm

# 需要导入模块: import jinja2 [as 别名]
# 或者: from jinja2 import PackageLoader [as 别名]
def slurm(partition, qos, mem_per_cpu, max_time, nodelist, cpus_per_task, luigi_module, luigi_task):
    env = Environment(loader=PackageLoader('qanta', 'slurm/templates'))
    template = env.get_template('luigi-template.sh.jinja2')
    sbatch_script = template.render({
        'luigi_module': luigi_module,
        'luigi_task': luigi_task,
        'partition': partition,
        'qos': qos,
        'mem_per_cpu': mem_per_cpu,
        'max_time': max_time,
        'nodelist': nodelist,
        'cpus_per_task': cpus_per_task
    })
    tmp_file = get_tmp_filename()
    with open(tmp_file, 'w') as f:
        f.write(sbatch_script)
    shell(f'sbatch {tmp_file}')
    shell(f'rm -f {tmp_file}') 
开发者ID:Pinafore,项目名称:qb,代码行数:20,代码来源:cli.py

示例7: prepare_template

# 需要导入模块: import jinja2 [as 别名]
# 或者: from jinja2 import PackageLoader [as 别名]
def prepare_template(flags, module):
    jinja_env = Environment(lstrip_blocks=True, trim_blocks=True)

    for name, function in inspect.getmembers(module, inspect.isfunction):
        jinja_env.filters[name] = function

    if flags.template:
        jinja_env.loader = FileSystemLoader(os.path.dirname(flags.template))
        template = jinja_env.get_template(os.path.basename(flags.template))
    else:
        jinja_env.loader = PackageLoader('swg2rst')
        try:
            template = jinja_env.get_template('main.{}'.format(flags.format))
        except TemplateError as err:
            sys.exit(u'Template Error: {}'.format(err.message))

    return template 
开发者ID:Arello-Mobile,项目名称:swagger2rst,代码行数:19,代码来源:swagger2rst.py

示例8: prepare_env

# 需要导入模块: import jinja2 [as 别名]
# 或者: from jinja2 import PackageLoader [as 别名]
def prepare_env(cnt, file_name=True, inline=False):
        this = {}
        if file_name:
            this['file_name_json'] = os.path.join(SAMPLES_PATH, '{}.json'.format(cnt))
            this['file_name_rst'] = os.path.join(SAMPLES_PATH,
                                                 '{}{inline}.rst'.format(cnt, inline='_inline' if inline else '')
                                                 )
            with codecs.open(this['file_name_json'], 'r', encoding='utf-8') as _file:
                doc = json.load(_file)
        else:
            this['file_name_json'] = False
            this['file_name_rst'] = False
            doc = json.load(cnt)
        this['swagger_doc'] = rst.SwaggerObject(doc)
        doc_module = importlib.import_module('swg2rst.utils.rst')
        jinja_env = Environment(lstrip_blocks=True, trim_blocks=True)
        jinja_env.loader = PackageLoader('swg2rst')
        for name, function in inspect.getmembers(doc_module, inspect.isfunction):
            jinja_env.filters[name] = function
        jinja_env.filters['sorted'] = sorted
        template = jinja_env.get_template('main.rst')
        this['raw_rst'] = template.render(doc=this['swagger_doc'], inline=inline)
        this['pattern'] = re.compile(r'[idm]_\w{32}')
        this['normalize'] = lambda x: x[:-1] if x[-1] == '\n' else x
        return this 
开发者ID:Arello-Mobile,项目名称:swagger2rst,代码行数:27,代码来源:test.py

示例9: __init__

# 需要导入模块: import jinja2 [as 别名]
# 或者: from jinja2 import PackageLoader [as 别名]
def __init__(self):
        self.jinja_env = Environment(
            loader=PackageLoader('snipsmanager', 'templates'))

        self.wizard = Wizard()
        self.wizard.add_question(
            description="Give your skill a name. For instance: lightskill, gardeningskill, etc ...",
            text="Project name? ",
            input_function=ask_for_input,
            input_validation=lambda x: len(x) > 0)
        self.wizard.add_question(description="A short sentence to describe what your skill does.",
                                 text="Description? ",
                                 input_function=ask_for_input,
                                 input_validation=lambda x: len(x) > 0)
        self.wizard.add_question(description="",
                                 text="Author? ",
                                 input_function=ask_for_input,
                                 input_validation=lambda x: True)
        self.wizard.add_question(description="",
                                 text="Email address? ",
                                 input_function=ask_for_input,
                                 input_validation=email_is_valid,
                                 default_value=get_user_email_git()) 
开发者ID:snipsco,项目名称:snipsmanager,代码行数:25,代码来源:scaffold.py

示例10: render_xml_payload

# 需要导入模块: import jinja2 [as 别名]
# 或者: from jinja2 import PackageLoader [as 别名]
def render_xml_payload(virl_xml, roster=None,
                       interfaces=None, protocol="telnet"):
    """
    we need to merge information from multiple sources to generate all
    the required parameters for the inventory

    """
    env = Environment(loader=PackageLoader('virl'),
                      trim_blocks=False)

    inventory = sim_info(virl_xml,
                         roster=roster,
                         interfaces=interfaces,
                         protocol=protocol)
    # pass all available data to template for rendering, this can probably be
    # pruned back at some point
    xml = env.get_template('nso/xml_payload.j2').render(inventory=inventory)
    return xml 
开发者ID:CiscoDevNet,项目名称:virlutils,代码行数:20,代码来源:nso_payload.py

示例11: render_ini_inventory

# 需要导入模块: import jinja2 [as 别名]
# 或者: from jinja2 import PackageLoader [as 别名]
def render_ini_inventory(virl_xml, roster=None, interfaces=None):
    """
    we need to merge information from multiple sources to generate all
    the required parameters for the inventory

    """

    j2_env = Environment(loader=PackageLoader('virl'),
                         trim_blocks=False)

    inventory = generate_inventory_dict(virl_xml,
                                        roster=roster,
                                        interfaces=interfaces)
    # pass all available data to template for rendering, this can probably
    # be pruned back at some point
    template = j2_env.get_template('ansible/inventory_ini_template.j2')
    return template.render(inventory=inventory) 
开发者ID:CiscoDevNet,项目名称:virlutils,代码行数:19,代码来源:ansible_inventory.py

示例12: __init__

# 需要导入模块: import jinja2 [as 别名]
# 或者: from jinja2 import PackageLoader [as 别名]
def __init__(self, path, width, height, depth=3, database='Unknown', segmented=0):
        environment = Environment(loader=PackageLoader('pascal_voc_writer', 'templates'), keep_trailing_newline=True)
        self.annotation_template = environment.get_template('annotation.xml')

        abspath = os.path.abspath(path)

        self.template_parameters = {
            'path': abspath,
            'filename': os.path.basename(abspath),
            'folder': os.path.basename(os.path.dirname(abspath)),
            'width': width,
            'height': height,
            'depth': depth,
            'database': database,
            'segmented': segmented,
            'objects': []
        } 
开发者ID:AndrewCarterUK,项目名称:pascal-voc-writer,代码行数:19,代码来源:__init__.py

示例13: register_loaders

# 需要导入模块: import jinja2 [as 别名]
# 或者: from jinja2 import PackageLoader [as 别名]
def register_loaders(self, application=None):
        user_path_loaders = [jinja2.FileSystemLoader(path)
                             for path in self.config.get('paths')]
        user_package_loaders = [jinja2.PackageLoader(*package)
                                for package in self.config.get('packages')]
        user_loaders = user_package_loaders + user_path_loaders
        system_loaders = [jinja2.PackageLoader(*package)
                          for package in self.config.get('framework_packages')]
        if self._debug_mode:
            loaders = system_loaders + user_loaders
        else:
            loaders = user_loaders + system_loaders
        kwargs = self.config.get('environment', {})
        loader = jinja2.ChoiceLoader(loaders)
        kwargs['loader'] = loader
        self._choice_loader = loader
        self._env = jinja2.Environment(**kwargs)
        self._env.application = application 
开发者ID:watsonpy,项目名称:watson-framework,代码行数:20,代码来源:jinja2.py

示例14: start

# 需要导入模块: import jinja2 [as 别名]
# 或者: from jinja2 import PackageLoader [as 别名]
def start(self, ioloop=None):
        """Serves a backtrader result as a Bokeh application running on a web server"""
        def make_document(doc: Document):
            if self._on_session_destroyed is not None:
                doc.on_session_destroyed(self._on_session_destroyed)

            # set document title
            doc.title = self._title

            # set document template
            env = Environment(loader=PackageLoader('backtrader_plotting.bokeh', 'templates'))
            doc.template = env.get_template(self._html_template)
            doc.template_variables['stylesheet'] = utils.generate_stylesheet(self._scheme)

            # get root model
            model = self._model_factory_fnc(doc)
            doc.add_root(model)

        self._run_server(make_document, ioloop=ioloop, port=self._port) 
开发者ID:verybadsoldier,项目名称:backtrader_plotting,代码行数:21,代码来源:bokeh_webapp.py

示例15: generate_stylesheet

# 需要导入模块: import jinja2 [as 别名]
# 或者: from jinja2 import PackageLoader [as 别名]
def generate_stylesheet(scheme, template="basic.css.j2") -> str:
    env = Environment(loader=PackageLoader('backtrader_plotting.bokeh', 'templates'))
    templ = env.get_template(template)

    css = templ.render(dict(
                             datatable_row_color_even=scheme.table_color_even,
                             datatable_row_color_odd=scheme.table_color_odd,
                             datatable_header_color=scheme.table_header_color,
                             tab_active_background_color=scheme.tab_active_background_color,
                             tab_active_color=scheme.tab_active_color,

                             tooltip_background_color=scheme.tooltip_background_color,
                             tooltip_text_color_label=scheme.tooltip_text_label_color,
                             tooltip_text_color_value=scheme.tooltip_text_value_color,
                             body_background_color=scheme.body_background_color,
                             tag_pre_background_color=scheme.tag_pre_background_color,
                             headline_color=scheme.plot_title_text_color,
                             text_color=scheme.text_color,
                           )
                       )
    return css 
开发者ID:verybadsoldier,项目名称:backtrader_plotting,代码行数:23,代码来源:utils.py


注:本文中的jinja2.PackageLoader方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。