def _create_wrappers(files_to_wrap, destination_dir, run_in_template_filename,
template_func,
inline=False, command=''):
os.path.exists(destination_dir) or os.makedirs(destination_dir)
with open(run_in_template_filename, 'r') as f:
run_in_template = template_func(f.read())
if not inline:
run_in_filename = os.path.join(destination_dir,
'run-in' + get_wrapper_extension())
with open(run_in_filename, 'w') as f:
f.write(run_in_template.replace('__COMMAND__', command))
os.chmod(run_in_filename,
os.stat(run_in_filename).st_mode | stat.S_IXUSR)
for filename in files_to_wrap:
basename = os.path.basename(filename)
if basename == 'run-in' + get_wrapper_extension():
continue
destination_filename = get_wrapper_full_path(destination_dir, basename)
if inline:
content = run_in_template.replace('__COMMAND__',
command + filename + ' ')
else:
content = get_wrapper_template().format(
command=command,
run_in_file=run_in_filename,
wrapped_file=filename)
with open(destination_filename, 'w') as f:
f.write(content)
os.chmod(destination_filename,
os.stat(destination_filename).st_mode | stat.S_IXUSR)
评论列表
文章目录