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()
|
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):
|
def add_database(self, name, db):
|
||||||
self.databases[name] = db
|
self.databases[name] = db
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -352,21 +352,26 @@ def serve(
|
||||||
click.echo(
|
click.echo(
|
||||||
"Serve! files={} (immutables={}) on port {}".format(files, immutable, port)
|
"Serve! files={} (immutables={}) on port {}".format(files, immutable, port)
|
||||||
)
|
)
|
||||||
ds = Datasette(
|
|
||||||
files,
|
# if files is a single directory, do something special with it
|
||||||
immutables=immutable,
|
if 1 == len(files) and os.path.isdir(files[0]):
|
||||||
cache_headers=not debug and not reload,
|
ds = Datasette.from_path(files[0])
|
||||||
cors=cors,
|
else:
|
||||||
inspect_data=inspect_data,
|
ds = Datasette(
|
||||||
metadata=metadata_data,
|
files,
|
||||||
sqlite_extensions=sqlite_extensions,
|
immutables=immutable,
|
||||||
template_dir=template_dir,
|
cache_headers=not debug and not reload,
|
||||||
plugins_dir=plugins_dir,
|
cors=cors,
|
||||||
static_mounts=static,
|
inspect_data=inspect_data,
|
||||||
config=dict(config),
|
metadata=metadata_data,
|
||||||
memory=memory,
|
sqlite_extensions=sqlite_extensions,
|
||||||
version_note=version_note,
|
template_dir=template_dir,
|
||||||
)
|
plugins_dir=plugins_dir,
|
||||||
|
static_mounts=static,
|
||||||
|
config=dict(config),
|
||||||
|
memory=memory,
|
||||||
|
version_note=version_note,
|
||||||
|
)
|
||||||
if return_instance:
|
if return_instance:
|
||||||
# Private utility mechanism for writing unit tests
|
# Private utility mechanism for writing unit tests
|
||||||
return ds
|
return ds
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue