'Generates a Solr schema that reflects the indexes.'

def handle(self, **options):

    using = options.get(u'using')
    if (not isinstance(connections[using].get_backend(), SolrSearchBackend)):
        raise ImproperlyConfigured((u"'%s'    isn't    configured    as    a    SolrEngine" % using))
    schema_xml = self.build_template(using=using, template_filename=Command.schema_template_loc)
    solrcfg_xml = self.build_template(using=using, template_filename=Command.solrcfg_template_loc)
    filename = options.get(u'filename')
    configure_directory = options.get(u'configure_directory')
    reload_core = options.get(u'reload_core')
    if filename:
        self.stdout.write(u'Trying    to    write    schema    file    located    at    {}'.format(filename))
        self.write_file(filename, schema_xml)
        if reload_core:
            connections[using].get_backend().reload()
    if configure_directory:
        self.stdout.write(u'Trying    to    configure    core    located    at    {}'.format(configure_directory))
        managed_schema_path = os.path.join(configure_directory, u'managed-schema')
        if os.path.isfile(managed_schema_path):
            try:
                os.rename(managed_schema_path, (u'%s.old' % managed_schema_path))
            except (IOError, OSError) as exc:
                raise CommandError(u'Could    not    rename    old    managed    schema    file    {}:    {}'.format(managed_schema_path, exc))
        schema_xml_path = os.path.join(configure_directory, u'schema.xml')
        try:
            self.write_file(schema_xml_path, schema_xml)
        except EnvironmentError as exc:
            raise CommandError(u'Could    not    configure    {}:    {}'.format(schema_xml_path, exc))
        solrconfig_path = os.path.join(configure_directory, u'solrconfig.xml')
        try:
            self.write_file(solrconfig_path, solrcfg_xml)
        except EnvironmentError as exc:
            raise CommandError(u'Could    not    write    {}:    {}'.format(solrconfig_path, exc))
    if reload_core:
        core = settings.HAYSTACK_CONNECTIONS[using][u'URL'].rsplit(u'/', 1)[(-1)]
        if (u'ADMIN_URL' not in settings.HAYSTACK_CONNECTIONS[using]):
            raise ImproperlyConfigured((u"'ADMIN_URL'    must    be    specified    in    the    HAYSTACK_CONNECTIONS    for    the    %s    backend" % using))
        if (u'URL' not in settings.HAYSTACK_CONNECTIONS[using]):
            raise ImproperlyConfigured((u"'URL'    must    be    specified    in    the    HAYSTACK_CONNECTIONS    for    the    %s    backend" % using))
        try:
            self.stdout.write(u'Trying    to    reload    core    named    {}'.format(core))
            resp = requests.get(settings.HAYSTACK_CONNECTIONS[using][u'ADMIN_URL'], params={u'action': u'RELOAD', u'core': core})
            if (not resp.ok):
                raise CommandError(u'Failed    to    reload    core    \u2013    Solr    error:    {}'.format(resp))
        except CommandError:
            raise
        except Exception as exc:
            raise CommandError(u'Failed    to    reload    core    {}:    {}'.format(core, exc))
    if ((not filename) and (not configure_directory) and (not reload_core)):
        self.print_stdout(schema_xml)
