-
-
Save glasnt/7678d4bc64277e3d564e71c758cb2ff6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from datasette.database import Database | |
from datasette import hookimpl | |
from datasette.utils.asgi import Response | |
import os | |
` | |
async def reload_db(datasette): | |
spec = datasette.plugin_config('datasette-reload-db') | |
db_dir = os.listdir(spec['dir']) | |
databases = datasette.databases | |
for db in databases: | |
if db == '_internal': | |
continue | |
datasette.remove_database(db) | |
for db in db_dir: | |
datasette.add_database(Database( | |
datasette, | |
path=os.path.join(spec['dir'], db), | |
is_mutable=True | |
)) | |
return Response.redirect('/') | |
@hookimpl | |
def register_routes(): | |
return [ | |
(r"^/-reload-db", reload_db) | |
] | |
@hookimpl | |
def menu_links(datasette): | |
return [ | |
{"href": datasette.urls.path("/-reload-db"), "label": "Reload Databases"}, | |
] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment