Commit 8bbb027b authored by Kazuhiko Shiozaki's avatar Kazuhiko Shiozaki Committed by Julien Muchembled

Add a wrapper shell script for very long shebang scripts for all installed files.

parent d59ad5fd
......@@ -44,6 +44,7 @@ import os
import pkg_resources
import re
import shutil
import stat
import subprocess
import sys
import tempfile
......@@ -213,6 +214,42 @@ def _format_picked_versions(picked_versions, required_by):
output.extend(required_output)
return output
def _fix_shebang(installed_files):
is_executable = stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH
path_list = installed_files.splitlines()
for path in path_list:
if os.path.isdir(path):
file_list = []
for (dirpath, _, filename_list) in os.walk(path):
if dirpath.endswith('/EGG-INFO/scripts'):
# shebang conversion of egg scripts will be done in
# zc.buildout.easy_install.script
continue
for filename in filename_list:
file_path = os.path.join(dirpath, filename)
if os.path.isfile(file_path):
file_list.append(file_path)
else:
file_list = [path]
for file_path in file_list:
if file_path.endswith('.shebang') or os.path.islink(file_path):
continue
st_mode = os.stat(file_path).st_mode
if not st_mode & is_executable:
continue
header = file(file_path).readline(128)
m = re.match('^#! ?(/.*)', header)
if not m or len(header) < 128:
continue
shebang_abspath = file_path + '.shebang'
os.rename(file_path, shebang_abspath)
file(file_path, 'w').write('''#!/bin/sh
exec %s "%s.shebang" "$@"
''' % (m.groups()[0], file_path))
os.chmod(file_path, stat.S_IMODE(st_mode))
if not os.path.isdir(path):
path_list.append(shebang_abspath)
return '\n'.join(sorted(path_list))
_buildout_default_options = _annotate_section({
'allow-hosts': '*',
......@@ -812,6 +849,7 @@ class Buildout(DictMixin):
elif not isinstance(installed_files, str):
installed_files = '\n'.join(installed_files)
installed_files = _fix_shebang(installed_files)
saved_options['__buildout_installed__'] = installed_files
saved_options['__buildout_signature__'] = signature
installed_part_options[part] = saved_options
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment