Gather the top files

def get_tops(self):
        '''
        Gather the top files
        '''
        tops = DefaultOrderedDict(list)
        include = DefaultOrderedDict(list)
        done = DefaultOrderedDict(list)
        found = 0  # did we find any contents in the top files?
        # Gather initial top files
        merging_strategy = self.opts['top_file_merging_strategy']
        if merging_strategy == 'same' and not self.opts['saltenv']:
            if not self.opts['default_top']:
                raise SaltRenderError(
                    'top_file_merging_strategy set to \'same\', but no '
                    'default_top configuration option was set'
                )

        if self.opts['saltenv']:
            contents = self.client.cache_file(
                self.opts['state_top'],
                self.opts['saltenv']
            )
            if contents:
                found = 1
                tops[self.opts['saltenv']] = [
                    compile_template(
                        contents,
                        self.state.rend,
                        self.state.opts['renderer'],
                        self.state.opts['renderer_blacklist'],
                        self.state.opts['renderer_whitelist'],
                        saltenv=self.opts['saltenv']
                    )
                ]
            else:
                tops[self.opts['saltenv']] = [{}]

        else:
            found = 0
            state_top_saltenv = self.opts.get('state_top_saltenv', False)
            if state_top_saltenv \
                    and not isinstance(state_top_saltenv, six.string_types):
                state_top_saltenv = six.text_type(state_top_saltenv)

            for saltenv in [state_top_saltenv] if state_top_saltenv \
                    else self._get_envs():
                contents = self.client.cache_file(
                    self.opts['state_top'],
                    saltenv
                )
                if contents:
                    found = found + 1
                    tops[saltenv].append(
                        compile_template(
                            contents,
                            self.state.rend,
                            self.state.opts['renderer'],
                            self.state.opts['renderer_blacklist'],
                            self.state.opts['renderer_whitelist'],
                            saltenv=saltenv
                        )
                    )
                else:
                    tops[saltenv].append({})
                    log.debug('No contents loaded for saltenv \'%s\'', saltenv)

            if found > 1 and merging_strategy == 'merge' and not self.opts.get('env_order', None):
                log.warning(
                    'top_file_merging_strategy is set to \'%s\' and '
                    'multiple top files were found. Merging order is not '
                    'deterministic, it may be desirable to either set '
                    'top_file_merging_strategy to \'same\' or use the '
                    '\'env_order\' configuration parameter to specify the '
                    'merging order.', merging_strategy
                )

        if found == 0:
            log.debug(
                'No contents found in top file. If this is not expected, '
                'verify that the \'file_roots\' specified in \'etc/master\' '
                'are accessible. The \'file_roots\' configuration is: %s',
                repr(self.state.opts['file_roots'])
            )

        # 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_match in states:
                    for sls in fnmatch.filter(self.avail[saltenv], sls_match):
                        if sls in done[saltenv]:
                            continue
                        tops[saltenv].append(
                            compile_template(
                                self.client.get_state(
                                    sls,
                                    saltenv
                                ).get('dest', False),
                                self.state.rend,
                                self.state.opts['renderer'],
                                self.state.opts['renderer_blacklist'],
                                self.state.opts['renderer_whitelist'],
                                saltenv
                            )
                        )
                        done[saltenv].append(sls)
            for saltenv in pops:
                if saltenv in include:
                    include.pop(saltenv)
        return tops