'Make index from index.txt'

def make_index(self, original_path, full_path, content):

    if (u'{index}' in content):
        path = os.path.dirname(full_path)
        files = []
        index_path = os.path.join(path, u'index.txt')
        if os.path.exists(index_path):
            with open(index_path, u'r') as f:
                files = f.read().splitlines()
        for f in os.listdir(path):
            if (not os.path.isdir(os.path.join(path, f))):
                (name, extn) = f.rsplit(u'.', 1)
                if ((name not in files) and (name != u'index') and (extn in (u'md', u'html'))):
                    files.append(name)
        links_html = u"<ol    class='index-links'>"
        for line in files:
            fpath = os.path.join(os.path.dirname(original_path), line)
            title = self.db.sql(u'select    title    from    help    where    path    like    %s', (os.path.join(fpath, u'index') + u'%'))
            if (not title):
                title = self.db.sql(u'select    title    from    help    where    path    like    %s', (fpath + u'%'))
            if title:
                title = title[0][0]
                links_html += u"<li><a    data-path='{fpath}'>    {title}    </a></li>".format(fpath=fpath, title=title)
        links_html += u'</ol>'
        html = content.replace(u'{index}', links_html)
        self.db.sql(u'update    help    set    content=%s    where    path=%s', (html, original_path))
