'Adds single index to a database.
It will use :py:meth:`inspect.getsource` to get class source.
Then it will build real index file, save it in ``_indexes`` directory.'

def _add_single_index(self, p, i, index):

    code = getsource(index.__class__)
    if (not code.startswith('c')):
        import textwrap
        code = textwrap.dedent(code)
    index._order = i
    cls_code = getattr(index, 'classes_code', [])
    classes_code = ''
    for curr in cls_code:
        classes_code += (getsource(curr) + '\n\n')
    with io.FileIO(os.path.join(p, (('%.2d%s' % (i, index.name)) + '.py')), 'w') as f:
        f.write(header_for_indexes(index.name, index.__class__.__name__, getattr(self, 'custom_header', ''), getattr(index, 'custom_header', ''), classes_code))
        f.write(code)
    return True
