當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。