def annotate():
    """Read buildout configuration and returns 'buildout' section as a dict.
    """

    buildout_directory = _env.hostout.options.get('path')
    fallback_user = _env.user or 'root'
    buildout_user = _env.hostout.options.get('buildout-user', fallback_user)

    assert buildout_directory, u'No path found for the selected hostout'

    my_home = os.environ.get('HOME')
    try:
        os.environ['HOME'] = os.path.expanduser('~{0:s}'.format(buildout_user))
        buildout = zc.buildout.buildout.Buildout(
            '{0:s}/{1:s}'.format(buildout_directory,
                                 _env.hostout.options['buildout']), []
        )
        return buildout.get('buildout')
    finally:
        if my_home is not None:
            os.environ['HOME'] = my_home
        else:
            del os.environ['HOME']
    def __init__(self, buildout, name, options):
        self.buildout = buildout
        self.name = (options.get('name') or '').strip() or name
        self.options = options

        # Set allowed outputs
        self.outputs = listify(options.get('outputs', '') or '')

        # Set allow cached flag
        self.allow_from_cache = (
            options.get('allow-from-cache', '').strip().lower()
            in ('true', 'yes', 'on', 'enable', 'enabled', '1')
        )

        # Set filename prefix
        self.prefix = os.path.join(
            (options.get('prefix') or '').strip(),
            (options.get('name') or '').strip() or name)

        # Parse propagatedBuildInputs from buildout already in __init__ to pass
        # found additional eggs forward to zc.recipe.egg
        propagated_eggs = []
        propagated_build_inputs = {}
        for section in listify(self.options.get('propagated-build-inputs')):
            if section in self.buildout:
                for key, value in self.buildout.get(section).items():
                    propagated_build_inputs[key] = listify(value)
                    propagated_eggs.extend(listify(value))
            elif '=' in section:
                # is not a section, but inline mapping
                key, value = section.split('=', 1)
                propagated_build_inputs.setdefault(key, [])
                propagated_build_inputs[key].extend(value.split(','))
                propagated_eggs.extend(value.split(','))

        # Get buildout options
        buildout_opts = buildout.get('buildout', {}) or {}
        self.parts = [part for part
                      in listify(options.get('parts', None)
                                 or buildout_opts.get('parts', None) or '')
                      if part != name]

        # Resolve recipe eggs for included parts
        # noinspection PyProtectedMember
        self.recipes = [zc.buildout.buildout._recipe(buildout.get(part))[0]
                        for part in self.parts]

        # Update options['eggs'] with found additional propagatedBuildInputs
        # and recipe eggs
        options = options.copy()
        options['eggs'] = '\n'.join([options.get('eggs', ''),
                                     '\n'.join(set(propagated_eggs)),
                                     '\n'.join(set(self.recipes))])

        # Save revolved egg and parsed propagatedBuildInputs
        self.egg = zc.recipe.egg.Scripts(buildout, name, options)
        self.propagated_build_inputs = propagated_build_inputs

        # Create index
        # noinspection PyProtectedMember
        self.index = zc.buildout.easy_install._get_index(
            (buildout_opts.get('index', None) or '').strip() or None,
            listify(buildout_opts.get('find-links', None) or ''),
            listify(buildout_opts.get('allow-hosts', None) or '') or ('*',))
Exemple #3
0
    def __init__(self, buildout, name, options):
        self.buildout = buildout
        self.name = (options.get('name') or '').strip() or name
        self.options = options

        # Set allowed outputs
        self.outputs = listify(options.get('outputs', '') or '')

        # Set allow cached flag
        self.allow_from_cache = (options.get('allow-from-cache',
                                             '').strip().lower()
                                 in ('true', 'yes', 'on', 'enable', 'enabled',
                                     '1'))

        # Set filename prefix
        self.prefix = os.path.join((options.get('prefix') or '').strip(),
                                   (options.get('name') or '').strip() or name)

        # Parse propagatedBuildInputs from buildout already in __init__ to pass
        # found additional eggs forward to zc.recipe.egg
        propagated_eggs = []
        propagated_build_inputs = {}
        for section in listify(self.options.get('propagated-build-inputs')):
            if section in self.buildout:
                for key, value in self.buildout.get(section).items():
                    propagated_build_inputs[key] = listify(value)
                    propagated_eggs.extend(listify(value))
            elif '=' in section:
                # is not a section, but inline mapping
                key, value = section.split('=', 1)
                propagated_build_inputs.setdefault(key, [])
                propagated_build_inputs[key].extend(value.split(','))
                propagated_eggs.extend(value.split(','))

        # Get buildout options
        buildout_opts = buildout.get('buildout', {}) or {}
        self.parts = [
            part for part in listify(
                options.get('parts', None) or buildout_opts.get('parts', None)
                or '') if part != name
        ]

        # Resolve recipe eggs for included parts
        # noinspection PyProtectedMember
        self.recipes = [
            zc.buildout.buildout._recipe(buildout.get(part))[0]
            for part in self.parts
        ]

        # Update options['eggs'] with found additional propagatedBuildInputs
        # and recipe eggs
        options = options.copy()
        options['eggs'] = '\n'.join([
            options.get('eggs', ''), '\n'.join(set(propagated_eggs)),
            '\n'.join(set(self.recipes))
        ])

        # Save revolved egg and parsed propagatedBuildInputs
        self.egg = zc.recipe.egg.Scripts(buildout, name, options)
        self.propagated_build_inputs = propagated_build_inputs

        # Create index
        # noinspection PyProtectedMember
        self.index = zc.buildout.easy_install._get_index(
            (buildout_opts.get('index', None) or '').strip() or None,
            listify(buildout_opts.get('find-links', None) or ''),
            listify(buildout_opts.get('allow-hosts', None) or '') or ('*', ))