Commit 4d38637b authored by Kazuhiko Shiozaki's avatar Kazuhiko Shiozaki

Use a dedicated rebootstrap directory only if buildout:rebootstrap-directory is set.

parent 23c67201
......@@ -33,6 +33,13 @@ Example profile and invocation
parts =
realrun
# Uncomment the following to use a dedicated buildout directory to
# build rebootstrap python # that is mandatory if the major version
# of python is different # between buildout's python and rebootstrap
# python.
#
# rebootstrap-directory = rebootstrap
[slapospython]
recipe = plone.recipe.command
......
......@@ -25,17 +25,23 @@ class Rebootstrap:
self.logger = logging.getLogger(__name__)
self.buildout = buildout
buildout_directory = buildout['buildout']['directory']
self.rebootstrap_directory = os.path.join(
buildout_directory, 'rebootstrap'
)
# fetch section to build python, obligatory
self.python_section = (
buildout['buildout'].get('python') or \
buildout['rebootstrap']['section']
).strip()
self.wanted_python = buildout[self.python_section]['executable'].replace(
buildout_directory, self.rebootstrap_directory
)
self.python_section = buildout['buildout'].get('python','').strip()
if not self.python_section:
raise zc.buildout.UserError('buildout:python is not defined.')
if self.python_section not in buildout:
raise zc.buildout.UserError('[%s] is not defined.' % self.python_section)
self.wanted_python = buildout[self.python_section]['executable']
rebootstrap_directory = buildout['buildout'].get('rebootstrap-directory')
if rebootstrap_directory:
self.rebootstrap_directory = os.path.join(
buildout_directory, 'rebootstrap'
)
self.wanted_python = self.wanted_python.replace(
buildout_directory, self.rebootstrap_directory, 1
)
else:
self.rebootstrap_directory = buildout_directory
# query for currently running python
self.running_python = sys.executable
......@@ -43,6 +49,10 @@ class Rebootstrap:
if self.running_python != self.wanted_python:
self.install_section()
self.reboot()
elif self.python_section:
buildout = self.buildout['buildout']
if self.python_section not in buildout['parts'].split():
buildout['parts'] = self.python_section + '\n' + buildout['parts']
def reboot(self):
message = """
......@@ -58,12 +68,13 @@ Buildout will be restarted automatically to have this change applied.
self.logger.info(message)
args = map(zc.buildout.easy_install._safe_arg, sys.argv)
env = os.environ
if 'ORIG_PYTHON' not in env:
env['ORIG_PYTHON'] = sys.executable
os.execve(self.wanted_python, [self.wanted_python] + args, env)
def install_section(self):
# For safety, we always try to install/update instead of the condition
# if not os.path.exists(self.wanted_python):
if True:
if not os.path.exists(self.wanted_python) or \
self.rebootstrap_directory != self.buildout['buildout']['directory']:
self.logger.info('Installing section %r to provide %r' % (
self.python_section, self.wanted_python))
args = map(zc.buildout.easy_install._safe_arg, sys.argv)
......@@ -118,3 +129,26 @@ Buildout will be restarted automatically to have this change applied.
'%r\nUnfortunately even after installing this section executable was'
' not found.\nThis is section responsibility to provide python (eg. '
'by compiling it).' % (self.python_section, self.wanted_python))
_uninstall_part_orig = zc.buildout.buildout.Buildout._uninstall_part
def _uninstall_part(self, part, installed_part_options):
_uninstall_part_orig(self, part, installed_part_options)
try:
location = self[part].get('location')
except zc.buildout.buildout.MissingSection:
return
if location and sys.executable.startswith(location):
message = """
************ REBOOTSTRAP: IMPORTANT NOTICE ************
%r part that provides the running Python is uninstalled.
Buildout will be restarted automatically with the original Python.
************ REBOOTSTRAP: IMPORTANT NOTICE ************
""" % part
self._logger.info(message)
if getattr(self, 'dry_run', False):
sys.exit()
args = map(zc.buildout.easy_install._safe_arg, sys.argv)
env = os.environ
orig_python = env['ORIG_PYTHON']
os.execve(orig_python, [orig_python] + args, env)
zc.buildout.buildout.Buildout._uninstall_part = _uninstall_part
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