home / github / issue_comments

Menu
  • Search all tables
  • GraphQL API

issue_comments: 1760412424

This data as json

html_url issue_url id node_id user created_at updated_at author_association body reactions issue performed_via_github_app
https://github.com/simonw/datasette/issues/2199#issuecomment-1760412424 https://api.github.com/repos/simonw/datasette/issues/2199 1760412424 IC_kwDOBm6k_c5o7cMI 9599 2023-10-12T21:51:44Z 2023-10-12T21:51:44Z OWNER

Started playing with this plugin idea, now tearing myself away to work on something more important: ```python from datasette import hookimpl import click import pathlib

@hookimpl def register_commands(cli): @cli.group() def upgrade(): """ Apply configuration upgrades to an existing Datasette instance """ pass

@upgrade.command()
@click.argument(
    "metadata", type=click.Path(exists=True)
)
@click.option(
    "new_metadata", "-m", "--new-metadata", help="Path to new metadata.yaml file", type=click.Path(exists=False)
)
@click.option(
    "new_datasette", "-c", "--new-datasette", help="Path to new datasette.yaml file", type=click.Path(exists=False)
)
@click.option(
    "output_dir", "-e", "--output-dir", help="Directory to write new files to", type=click.Path(), default="."
)
def metadata_to_config(metadata, new_metadata, new_datasette, output_dir):
    """
    Upgrade an existing metadata.json/yaml file to the new metadata.yaml and
    datasette.yaml split introduced prior to Datasette 1.0.
    """
    print("Upgrading {} to new metadata.yaml format".format(metadata))
    output_dir = pathlib.Path(output_dir)
    if not new_metadata:
        # Pick a filename for the new metadata.yaml file that does not yet exist
        new_metadata = pick_filename("metadata", output_dir)
    if not new_datasette:
        new_datasette = pick_filename("datasette", output_dir)
    print("New metadata.yaml file will be written to {}".format(new_metadata))
    print("New datasette.yaml file will be written to {}".format(new_datasette))

def pick_filename(base, output_dir): options = ["{}.yaml".format(base), "{}-new.yaml".format(base)] i = 0 while True: option = options.pop(0) option_path = output_dir / option if not option_path.exists(): return option_path # If we ran out if not options: i += 1 options = ["{}-new-{}.yaml".format(base, i)] ```

{
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
1940346034  
Powered by Datasette · Queries took 0.874ms · About: github-to-sqlite