mirror of
https://github.com/simonw/datasette.git
synced 2025-12-10 16:51:24 +01:00
New datasette skeleton command for generating metadata.json
Closes #164
This commit is contained in:
parent
7e1ba161ec
commit
32cf5a4a72
1 changed files with 58 additions and 0 deletions
|
|
@ -104,6 +104,64 @@ def publish(publisher, files, name, metadata, extra_options, force, branch, **ex
|
|||
call(["heroku", "builds:create", "-a", app_name])
|
||||
|
||||
|
||||
@cli.command()
|
||||
@click.argument('files', type=click.Path(exists=True), nargs=-1, required=True)
|
||||
@click.option(
|
||||
'-m', '--metadata', default='metadata.json',
|
||||
help='Name of metadata file to generate'
|
||||
)
|
||||
@click.option(
|
||||
'sqlite_extensions', '--load-extension', envvar='SQLITE_EXTENSIONS', multiple=True,
|
||||
type=click.Path(exists=True, resolve_path=True), help='Path to a SQLite extension to load'
|
||||
)
|
||||
def skeleton(files, metadata, sqlite_extensions):
|
||||
"Generate a skeleton metadata.json file for specified SQLite databases"
|
||||
if os.path.exists(metadata):
|
||||
click.secho(
|
||||
'File {} already exists, will not over-write'.format(metadata),
|
||||
bg='red',
|
||||
fg='white',
|
||||
bold=True,
|
||||
err=True,
|
||||
)
|
||||
sys.exit(1)
|
||||
app = Datasette(files, sqlite_extensions=sqlite_extensions)
|
||||
databases = {}
|
||||
for database_name, info in app.inspect().items():
|
||||
databases[database_name] = {
|
||||
'title': None,
|
||||
'description': None,
|
||||
'description_html': None,
|
||||
'license': None,
|
||||
'license_url': None,
|
||||
'source': None,
|
||||
'source_url': None,
|
||||
'queries': {},
|
||||
'tables': {
|
||||
table_name: {
|
||||
'title': None,
|
||||
'description': None,
|
||||
'description_html': None,
|
||||
'license': None,
|
||||
'license_url': None,
|
||||
'source': None,
|
||||
'source_url': None,
|
||||
} for table_name in (info.get('tables') or {})
|
||||
}
|
||||
}
|
||||
open(metadata, 'w').write(json.dumps({
|
||||
'title': None,
|
||||
'description': None,
|
||||
'description_html': None,
|
||||
'license': None,
|
||||
'license_url': None,
|
||||
'source': None,
|
||||
'source_url': None,
|
||||
'databases': databases
|
||||
}, indent=4))
|
||||
click.echo('Wrote skeleton to {}'.format(metadata))
|
||||
|
||||
|
||||
@cli.command()
|
||||
@click.argument('files', type=click.Path(exists=True), nargs=-1, required=True)
|
||||
@click.option(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue