def _install(package, src_dir, dst_dir, params, prefix_len=None, rec=None):
"""Interpolate source directory into target directory with params."""
package_name = package.__name__
contents = pkg_resources.resource_listdir(package_name, src_dir)
if prefix_len is None:
prefix_len = len(src_dir) + 1
for item in contents:
resource_path = '/'.join([src_dir, item])
dst_path = os.path.join(dst_dir, resource_path[prefix_len:])
if pkg_resources.resource_isdir(package_name,
'/'.join([src_dir, item])):
fs.mkdir_safe(dst_path)
if rec:
rec.write('%s/\n' % dst_path)
_install(package,
os.path.join(src_dir, item),
dst_dir,
params,
prefix_len=prefix_len,
rec=rec)
else:
if resource_path.endswith('.swp'):
continue
_LOGGER.info('Render: %s => %s', resource_path, dst_path)
resource_str = pkg_resources.resource_string(package_name,
resource_path)
if rec:
rec.write('%s\n' % dst_path)
_update(dst_path, _render(resource_str.decode('utf-8'), params))
评论列表
文章目录