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 ...@@ -33,6 +33,13 @@ Example profile and invocation
parts = parts =
realrun 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] [slapospython]
recipe = plone.recipe.command recipe = plone.recipe.command
......
...@@ -25,17 +25,23 @@ class Rebootstrap: ...@@ -25,17 +25,23 @@ class Rebootstrap:
self.logger = logging.getLogger(__name__) self.logger = logging.getLogger(__name__)
self.buildout = buildout self.buildout = buildout
buildout_directory = buildout['buildout']['directory'] buildout_directory = buildout['buildout']['directory']
self.rebootstrap_directory = os.path.join(
buildout_directory, 'rebootstrap'
)
# fetch section to build python, obligatory # fetch section to build python, obligatory
self.python_section = ( self.python_section = buildout['buildout'].get('python','').strip()
buildout['buildout'].get('python') or \ if not self.python_section:
buildout['rebootstrap']['section'] raise zc.buildout.UserError('buildout:python is not defined.')
).strip() if self.python_section not in buildout:
self.wanted_python = buildout[self.python_section]['executable'].replace( raise zc.buildout.UserError('[%s] is not defined.' % self.python_section)
buildout_directory, self.rebootstrap_directory 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 # query for currently running python
self.running_python = sys.executable self.running_python = sys.executable
...@@ -43,6 +49,10 @@ class Rebootstrap: ...@@ -43,6 +49,10 @@ class Rebootstrap:
if self.running_python != self.wanted_python: if self.running_python != self.wanted_python:
self.install_section() self.install_section()
self.reboot() 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): def reboot(self):
message = """ message = """
...@@ -58,12 +68,13 @@ Buildout will be restarted automatically to have this change applied. ...@@ -58,12 +68,13 @@ Buildout will be restarted automatically to have this change applied.
self.logger.info(message) self.logger.info(message)
args = map(zc.buildout.easy_install._safe_arg, sys.argv) args = map(zc.buildout.easy_install._safe_arg, sys.argv)
env = os.environ env = os.environ
if 'ORIG_PYTHON' not in env:
env['ORIG_PYTHON'] = sys.executable
os.execve(self.wanted_python, [self.wanted_python] + args, env) os.execve(self.wanted_python, [self.wanted_python] + args, env)
def install_section(self): def install_section(self):
# For safety, we always try to install/update instead of the condition if not os.path.exists(self.wanted_python) or \
# if not os.path.exists(self.wanted_python): self.rebootstrap_directory != self.buildout['buildout']['directory']:
if True:
self.logger.info('Installing section %r to provide %r' % ( self.logger.info('Installing section %r to provide %r' % (
self.python_section, self.wanted_python)) self.python_section, self.wanted_python))
args = map(zc.buildout.easy_install._safe_arg, sys.argv) args = map(zc.buildout.easy_install._safe_arg, sys.argv)
...@@ -118,3 +129,26 @@ Buildout will be restarted automatically to have this change applied. ...@@ -118,3 +129,26 @@ Buildout will be restarted automatically to have this change applied.
'%r\nUnfortunately even after installing this section executable was' '%r\nUnfortunately even after installing this section executable was'
' not found.\nThis is section responsibility to provide python (eg. ' ' not found.\nThis is section responsibility to provide python (eg. '
'by compiling it).' % (self.python_section, self.wanted_python)) '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