def update(branch=None): """Update the local buildout from its mercurial repository. """ buildout_directory = _env.hostout.options.get('path') fallback_user = _env.user or 'root' buildout_user = _env.hostout.options.get('buildout-user', fallback_user) local_sudo = _env.hostout.options.get('local-sudo') == "true" assert buildout_directory, u'No path found for the selected hostout' # Pull with _lcd(buildout_directory): cmd = 'hg pull' cmd = 'su {0:s} -c "{1:s}"'.format(buildout_user, cmd) if local_sudo: cmd = 'sudo {0:s}'.format(cmd) if _output.running: print('[localhost] update: {0:s}'.format(cmd)) _local(cmd) # Update branch = bool(branch) and ' {0:s}'.format(branch) or '' with _lcd(buildout_directory): cmd = 'hg update -C{0:s}'.format(branch) cmd = 'su {0:s} -c "{1:s}"'.format(buildout_user, cmd) if _env.hostout.options.get('local-sudo') == 'true': cmd = 'sudo {0:s}'.format(cmd) if _output.running: print('[localhost] update: {0:s}'.format(cmd)) _local(cmd)
def buildout(*args): """Execute the local buildout """ buildout_directory = _env.hostout.options.get('path') fallback_user = _env.user or 'root' buildout_user = _env.hostout.options.get('buildout-user', fallback_user) effective_user = _env.hostout.options.get('effective-user', fallback_user) local_sudo = _env.hostout.options.get('local-sudo') == "true" assert buildout_directory, u'No path found for the selected hostout' # Configure offline = '-o' in args and ' -o' or '' parts = [arg for arg in args if not arg.startswith('-')] parts = parts and ' install {0:s}'.format(' '.join(parts)) or '' # Chown var-directory var_directory = os.path.join(buildout_directory, 'var') cmd = 'chown -R {0:s} {1:s}'.format(buildout_user, var_directory) if local_sudo: cmd = 'sudo {0:s}'.format(cmd) if _output.running: print('[localhost] pull: {0:s}'.format(cmd)) _local(cmd) # Buildout with _lcd(buildout_directory): cmd = 'bin/buildout{0:s}{1:s}'.format(parts, offline) cmd = 'su {0:s} -c "{1:s}"'.format(buildout_user, cmd) if local_sudo: cmd = 'sudo {0:s}'.format(cmd) if _output.running: print('[localhost] buildout: {0:s}'.format(cmd)) _local(cmd) # Chown var-directory var_directory = os.path.join(buildout_directory, 'var') cmd = 'chown -R {0:s} {1:s}'.format(effective_user, var_directory) if local_sudo: cmd = 'sudo {0:s}'.format(cmd) if _output.running: print('[localhost] pull: {0:s}'.format(cmd)) _local(cmd)
def bootstrap(): """Execute bootstrap for the local buildout. The default effective python could be overridden by setting ``bootstrap-python`` -hostout-option with a path to an another python executable. """ buildout_directory = _env.hostout.options.get('path') fallback_user = _env.user or 'root' buildout_user = _env.hostout.options.get('buildout-user', fallback_user) local_sudo = _env.hostout.options.get('local-sudo') == "true" assert buildout_directory, u'No path found for the selected hostout' buildout_python = _env.hostout.options.get('executable') bootstrap_python = ( _env.hostout.options.get('bootstrap-python') or buildout_python ) # Bootstrap with _lcd(buildout_directory): cmd = '{0:s} bootstrap.py --distribute'.format(bootstrap_python) cmd = 'su {0:s} -c "{1:s}"'.format(buildout_user, cmd) if local_sudo: cmd = 'sudo {0:s}'.format(cmd) if _output.running: print('[localhost] bootstrap: %s' % cmd) with _settings(warn_only=True): res = _local(cmd) if res.failed: print('First bootstrap failed: we have a new bootstrap which ' 'has --distribute option now default. Trying again...') cmd = '{0:s} bootstrap.py'.format(bootstrap_python) cmd = 'su {0:s} -c "{1:s}"'.format(buildout_user, cmd) if local_sudo: cmd = 'sudo {0:s}'.format(cmd) if _output.running: print('[localhost] bootstrap: %s' % cmd) _local(cmd)
def cd(path): if _is_local(env.host): return _lcd(path) else: return _cd(path)