本文整理匯總了Python中environ.Path方法的典型用法代碼示例。如果您正苦於以下問題:Python environ.Path方法的具體用法?Python environ.Path怎麽用?Python environ.Path使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類environ
的用法示例。
在下文中一共展示了environ.Path方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: generate_file_handler
# 需要導入模塊: import environ [as 別名]
# 或者: from environ import Path [as 別名]
def generate_file_handler(filename):
""" Generates a logging handler that writes to a file.
If the `ENABLE_LOGGING_TO_FILE` setting is `False`, `logging.NullHandler` will be used instead
of `logging.FileHandler`.
Args:
filename (str): Name of the file to which logs are written.
Returns:
dict
"""
handler = {"level": "INFO", "formatter": "standard"}
if ENABLE_LOGGING_TO_FILE:
handler.update(
{
"class": "logging.FileHandler",
"filename": environ.Path(LOG_FILE_PATH).path(filename),
}
)
else:
handler["class"] = "logging.NullHandler"
return handler
示例2: update_body
# 需要導入模塊: import environ [as 別名]
# 或者: from environ import Path [as 別名]
def update_body(app, pagename, templatename, context, doctree):
outdir = environ.Path(app.config.html_context['output_directory'])
project = app.config.project
version = app.config.version
if not os.path.exists(outdir.root):
os.makedirs(outdir.root)
directory_name = "{name}-{version}".format(name=project, version=version)
json_dir = outdir.path(directory_name)
if not os.path.exists(json_dir.root):
os.makedirs(json_dir.root)
try:
out_dir = json_dir.path('/'.join(pagename.split('/')[:-1]))
if not os.path.exists(out_dir()):
os.makedirs(out_dir())
out_file = json_dir.path(pagename + '.json')
to_write = open(out_file(), 'w+')
to_context = copy.copy(context)
# Use list here so we don't get an error on changing dict during iteration
for key in list(context):
if key not in KEYS:
del to_context[key]
to_write.write(json.dumps(to_context, indent=4))
except Exception:
log.exception('Failure in JSON search dump')