mirror of
https://github.com/simonw/datasette.git
synced 2025-12-10 16:51:24 +01:00
WIP implementation of configure directory, refs #731
This commit is contained in:
parent
1b7b66c465
commit
62162dcdea
2 changed files with 48 additions and 15 deletions
|
|
@ -247,6 +247,34 @@ class Datasette:
|
|||
|
||||
self.register_renderers()
|
||||
|
||||
@classmethod
|
||||
def from_path(cls, path):
|
||||
path = Path(path)
|
||||
files = [str(p.resolve()) for p in path.glob("*.db")]
|
||||
inspect_data = None
|
||||
if (path / "inspect.json").exists():
|
||||
inspect_data = json.load((path / "inspect.json").open())
|
||||
metadata = None
|
||||
if (path / "metadata.json").exists():
|
||||
metadata = json.load((path / "metadata.json").open())
|
||||
template_dir = None
|
||||
if (path / "templates").exists():
|
||||
template_dir = str((path / "templates"))
|
||||
plugins_dir = None
|
||||
if (path / "plugins").exists():
|
||||
plugins = str((path / "plugins"))
|
||||
static_mounts = None
|
||||
if (path / "static").exists():
|
||||
static_mounts = [("static", str(path / "plugins"))]
|
||||
return cls(
|
||||
files,
|
||||
inspect_data=inspect_data,
|
||||
metadata=metadata,
|
||||
template_dir=template_dir,
|
||||
plugins_dir=plugins_dir,
|
||||
static_mounts=static_mounts,
|
||||
)
|
||||
|
||||
def add_database(self, name, db):
|
||||
self.databases[name] = db
|
||||
|
||||
|
|
|
|||
|
|
@ -352,21 +352,26 @@ def serve(
|
|||
click.echo(
|
||||
"Serve! files={} (immutables={}) on port {}".format(files, immutable, port)
|
||||
)
|
||||
ds = Datasette(
|
||||
files,
|
||||
immutables=immutable,
|
||||
cache_headers=not debug and not reload,
|
||||
cors=cors,
|
||||
inspect_data=inspect_data,
|
||||
metadata=metadata_data,
|
||||
sqlite_extensions=sqlite_extensions,
|
||||
template_dir=template_dir,
|
||||
plugins_dir=plugins_dir,
|
||||
static_mounts=static,
|
||||
config=dict(config),
|
||||
memory=memory,
|
||||
version_note=version_note,
|
||||
)
|
||||
|
||||
# if files is a single directory, do something special with it
|
||||
if 1 == len(files) and os.path.isdir(files[0]):
|
||||
ds = Datasette.from_path(files[0])
|
||||
else:
|
||||
ds = Datasette(
|
||||
files,
|
||||
immutables=immutable,
|
||||
cache_headers=not debug and not reload,
|
||||
cors=cors,
|
||||
inspect_data=inspect_data,
|
||||
metadata=metadata_data,
|
||||
sqlite_extensions=sqlite_extensions,
|
||||
template_dir=template_dir,
|
||||
plugins_dir=plugins_dir,
|
||||
static_mounts=static,
|
||||
config=dict(config),
|
||||
memory=memory,
|
||||
version_note=version_note,
|
||||
)
|
||||
if return_instance:
|
||||
# Private utility mechanism for writing unit tests
|
||||
return ds
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue