To be tested but
<pre>
    for row in c.execute(sql):
        db = None
        indices = row['sphinx_index']
        # db only filter can be applied to sphinx config, no need to query postgres db
        # database filter
        if options.index_filter is None:
            if options.database_filter is None or options.database_filter == row['database']:
                db = row['database']
            elif options.database_filter.split(".")[0] == row['database']:
                table =  pg_get_tables(row['sql'], row['database'])
                db = row['database'] if options.database_filter in table else None

        if options.command == 'list' and db is not None:
            for indice in indices.split(' '):
                resultat.append("%s -> %s" % (indice, db))

        if options.command == 'update' and db is not None:
            resultat.append("%s" % (indices))
</pre>
does the same as the code above.