Gather the top files

def get_tops(self):
        '''
        Gather the top files
        '''
        tops = collections.defaultdict(list)
        include = collections.defaultdict(list)
        done = collections.defaultdict(list)
        errors = []
        # Gather initial top files
        try:
            saltenvs = set()
            if self.opts['pillarenv']:
                # If the specified pillarenv is not present in the available
                # pillar environments, do not cache the pillar top file.
                if self.opts['pillarenv'] not in self.opts['pillar_roots']:
                    log.debug(
                        'pillarenv \'%s\' not found in the configured pillar '
                        'environments (%s)',
                        self.opts['pillarenv'], ', '.join(self.opts['pillar_roots'])
                    )
                else:
                    saltenvs.add(self.opts['pillarenv'])
            else:
                saltenvs = self._get_envs()
                if self.opts.get('pillar_source_merging_strategy', None) == "none":
                    saltenvs &= set([self.saltenv or 'base'])

            for saltenv in saltenvs:
                top = self.client.cache_file(self.opts['state_top'], saltenv)
                if top:
                    tops[saltenv].append(compile_template(
                        top,
                        self.rend,
                        self.opts['renderer'],
                        self.opts['renderer_blacklist'],
                        self.opts['renderer_whitelist'],
                        saltenv=saltenv,
                        _pillar_rend=True,
                    ))
        except Exception as exc:
            errors.append(
                    ('Rendering Primary Top file failed, render error:\n{0}'
                        .format(exc)))
            log.exception('Pillar rendering failed for minion %s', self.minion_id)

        # Search initial top files for includes
        for saltenv, ctops in six.iteritems(tops):
            for ctop in ctops:
                if 'include' not in ctop:
                    continue
                for sls in ctop['include']:
                    include[saltenv].append(sls)
                ctop.pop('include')
        # Go through the includes and pull out the extra tops and add them
        while include:
            pops = []
            for saltenv, states in six.iteritems(include):
                pops.append(saltenv)
                if not states:
                    continue
                for sls in states:
                    if sls in done[saltenv]:
                        continue
                    try:
                        tops[saltenv].append(
                                compile_template(
                                    self.client.get_state(
                                        sls,
                                        saltenv
                                        ).get('dest', False),
                                    self.rend,
                                    self.opts['renderer'],
                                    self.opts['renderer_blacklist'],
                                    self.opts['renderer_whitelist'],
                                    saltenv=saltenv,
                                    _pillar_rend=True,
                                    )
                                )
                    except Exception as exc:
                        errors.append(
                                ('Rendering Top file {0} failed, render error'
                                 ':\n{1}').format(sls, exc))
                    done[saltenv].append(sls)
            for saltenv in pops:
                if saltenv in include:
                    include.pop(saltenv)

        return tops, errors