當前位置: 首頁>>代碼示例>>Python>>正文


Python environment.Environment方法代碼示例

本文整理匯總了Python中jinja2.environment.Environment方法的典型用法代碼示例。如果您正苦於以下問題:Python environment.Environment方法的具體用法?Python environment.Environment怎麽用?Python environment.Environment使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在jinja2.environment的用法示例。


在下文中一共展示了environment.Environment方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: renderTemplate

# 需要導入模塊: from jinja2 import environment [as 別名]
# 或者: from jinja2.environment import Environment [as 別名]
def renderTemplate(script_path, time_file_path, dimensions=(24, 80), templatename=DEFAULT_TEMPLATE):
    with copen(script_path, encoding='utf-8', errors='replace', newline='\r\n') as scriptf:
    # with open(script_path) as scriptf:
        with open(time_file_path) as timef:
            timing = getTiming(timef)
            json = scriptToJSON(scriptf, timing)

    fsl = FileSystemLoader(dirname(templatename), 'utf-8')
    e = Environment()
    e.loader = fsl

    templatename = basename(templatename)
    rendered = e.get_template(templatename).render(json=json,
                                                   dimensions=dimensions)

    return rendered 
開發者ID:zsjtoby,項目名稱:DevOpsCloud,代碼行數:18,代碼來源:log_api.py

示例2: generate_config

# 需要導入模塊: from jinja2 import environment [as 別名]
# 或者: from jinja2.environment import Environment [as 別名]
def generate_config(loader_dir):
    """Generate the device configuration from a template."""
    jinja_env = Environment(undefined=StrictUndefined)
    template_vars = {
        'dns1': '1.1.1.1',
        'dns2': '8.8.8.8',
    }
    template_file = 'dns.j2'

    jinja_env.loader = FileSystemLoader(loader_dir)
    template = jinja_env.get_template(template_file)
    return template.render(template_vars) 
開發者ID:ktbyers,項目名稱:python_course,代碼行數:14,代碼來源:napalm_ex6_alt.py

示例3: main

# 需要導入模塊: from jinja2 import environment [as 別名]
# 或者: from jinja2.environment import Environment [as 別名]
def main():
    parser = argparse.ArgumentParser(description='Example OIDC Provider.')
    parser.add_argument("-p", "--port", default=80, type=int)
    parser.add_argument("-b", "--base", default="https://localhost", type=str)
    parser.add_argument("-d", "--debug", action="store_true")
    parser.add_argument("settings")
    args = parser.parse_args()

    # Load configuration
    with open(args.settings, "r") as f:
        settings = yaml.load(f)

    issuer = args.base.rstrip("/")

    template_dirs = settings["server"].get("template_dirs", "templates")
    jinja_env = Environment(loader=FileSystemLoader(template_dirs))
    authn_broker, auth_routing = setup_authentication_methods(
        settings["authn"], jinja_env)

    # Setup userinfo
    userinfo_conf = settings["userinfo"]
    cls = make_cls_from_name(userinfo_conf["class"])
    i = cls(**userinfo_conf["kwargs"])
    userinfo = UserInfo(i)

    client_db = {}
    provider = Provider(issuer, SessionDB(issuer), client_db, authn_broker,
                        userinfo, AuthzHandling(), verify_client, None)
    provider.baseurl = issuer
    provider.symkey = rndstr(16)

    # Setup keys
    path = os.path.join(os.path.dirname(__file__), "static")
    try:
        os.makedirs(path)
    except OSError, e:
        if e.errno != errno.EEXIST:
            raise e
        pass 
開發者ID:ga4gh,項目名稱:ga4gh-server,代碼行數:41,代碼來源:server.py

示例4: setUp

# 需要導入模塊: from jinja2 import environment [as 別名]
# 或者: from jinja2.environment import Environment [as 別名]
def setUp(self):
        self.loader = FileSystemLoader(self.TEMPLATE_PATH)
        self.env = Environment(loader=self.loader,
                               autoescape=True,
                               extensions=['jinja2.ext.with_', 'jinja2.ext.autoescape'])
        self.temp_dir = tempfile.mkdtemp() 
開發者ID:jonbretman,項目名稱:jinja-to-js,代碼行數:8,代碼來源:test_jinja_to_js.py

示例5: gen_file_jinja

# 需要導入模塊: from jinja2 import environment [as 別名]
# 或者: from jinja2.environment import Environment [as 別名]
def gen_file_jinja(self, template_file, data, output, dest_path):
        if not os.path.exists(dest_path):
            os.makedirs(dest_path)
        output = join(dest_path, output)
        logger.debug("Generating: %s" % output)

        """ Fills data to the project template, using jinja2. """
        env = Environment()
        env.loader = FileSystemLoader(self.TEMPLATE_DIR)
        # TODO: undefined=StrictUndefined - this needs fixes in templates
        template = env.get_template(template_file)
        target_text = template.render(data)

        open(output, "w").write(target_text)
        return dirname(output), output 
開發者ID:project-generator,項目名稱:project_generator,代碼行數:17,代碼來源:tool.py

示例6: run

# 需要導入模塊: from jinja2 import environment [as 別名]
# 或者: from jinja2.environment import Environment [as 別名]
def run(self, results):
        """Writes report.
        @param results: Cuckoo results dict.
        @raise CuckooReportError: if fails to write report.
        """
        if not HAVE_JINJA2:
            raise CuckooReportError("Failed to generate HTML report: "
                                    "Jinja2 Python library is not installed")

        shots_path = os.path.join(self.analysis_path, "shots")
        if os.path.exists(shots_path):
            shots = []
            counter = 1
            for shot_name in os.listdir(shots_path):
                if not shot_name.endswith(".jpg"):
                    continue

                shot_path = os.path.join(shots_path, shot_name)

                if os.path.getsize(shot_path) == 0:
                    continue

                shot = {}
                shot["id"] = os.path.splitext(File(shot_path).get_name())[0]
                shot["data"] = base64.b64encode(open(shot_path, "rb").read())
                shots.append(shot)

                counter += 1

            shots.sort(key=lambda shot: shot["id"])
            results["screenshots"] = shots
        else:
            results["screenshots"] = []

        env = Environment(autoescape=True)
        env.loader = FileSystemLoader(os.path.join(CUCKOO_ROOT,
                                                   "data", "html"))

        try:
            tpl = env.get_template("report.html")
            html = tpl.render({"results": results})
        except Exception as e:
            raise CuckooReportError("Failed to generate HTML report: %s" % e)
        
        try:
            with codecs.open(os.path.join(self.reports_path, "report.html"), "w", encoding="utf-8") as report:
                report.write(html)
        except (TypeError, IOError) as e:
            raise CuckooReportError("Failed to write HTML report: %s" % e)

        return True 
開發者ID:davidoren,項目名稱:CuckooSploit,代碼行數:53,代碼來源:reporthtml.py


注:本文中的jinja2.environment.Environment方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。