@post("/update_index")
def update_index():
    document_root = os.path.expanduser(config.get(
            "markupserve", "document_root"))

    indexed_paths = set()
    to_index = set()

    print "Starting!"

    if markupserve_index is None:
        print "No index found; aborting update"
        redirect('/')

    with markupserve_index.searcher() as searcher:
        writer = markupserve_index.writer()

        # Loop over all fields in the index
        for fields in searcher.all_stored_fields():
            indexed_path = os.path.join(document_root, fields["path"])
            indexed_paths.add(indexed_path)

            if not os.path.exists(indexed_path):
                # File was deleted since we last updated the index
                print "Deleting '%s' from index" % (indexed_path)
                remove_file_from_index(indexed_path, document_root, writer)
            else:
                # Check if file has been changed by hashing its contents
                with open(indexed_path, 'r') as fp:
                    file_hash = hash_file_contents(fp.read())

                if file_hash != fields["file_hash"]:
                    # File hash mismatch; delete from index and add to the list
                    # of files to re-index
                    print "MD5 hash mismatch for '%s': %s != %s" % (
                        indexed_path, file_hash, fields["file_hash"])
                    remove_file_from_index(indexed_path, document_root, writer)
                    to_index.add(indexed_path)

        # Add any path that has changed (or is not in the index) to the index
        for file_abspath in markup_files_in_subtree(document_root):
            if file_abspath in to_index:
                print "Updating index for '%s'" % (file_abspath)
                add_file_to_index(file_abspath, document_root, writer)
            elif file_abspath not in indexed_paths:
                print (file_abspath) % "Adding new file '%s' to index"
                add_file_to_index(file_abspath, document_root, writer)

        writer.commit()

        print "Done!"

        redirect('/')
dataset/ETHPy150Open alexras/markupserve/markupserve.py/update_index/swapped operands of `%`