def read_from_egg(tfile):
'''Read a relative path, getting the contents
locally or from the installed egg, parsing the contents
based on file_type if given, such as yaml
Params:
tfile: relative package path
file_type: file extension such as "json" or "yaml" or None
Returns:
contents: yaml or json loaded or raw
'''
template_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), tfile)
if not os.path.exists(template_path):
path_in_egg = os.path.join("btax", tfile)
buf = resource_stream(Requirement.parse("btax"), path_in_egg)
_bytes = buf.read()
contents = str(_bytes)
else:
with open(template_path, 'r') as f:
contents = f.read()
return contents
评论列表
文章目录