Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1from ..utils import StaticMount
2import click
3import os
4import shutil
5import sys
8def add_common_publish_arguments_and_options(subcommand):
9 for decorator in reversed(
10 (
11 click.argument("files", type=click.Path(exists=True), nargs=-1),
12 click.option(
13 "-m",
14 "--metadata",
15 type=click.File(mode="r"),
16 help="Path to JSON/YAML file containing metadata to publish",
17 ),
18 click.option(
19 "--extra-options", help="Extra options to pass to datasette serve"
20 ),
21 click.option(
22 "--branch", help="Install datasette from a GitHub branch e.g. master"
23 ),
24 click.option(
25 "--template-dir",
26 type=click.Path(exists=True, file_okay=False, dir_okay=True),
27 help="Path to directory containing custom templates",
28 ),
29 click.option(
30 "--plugins-dir",
31 type=click.Path(exists=True, file_okay=False, dir_okay=True),
32 help="Path to directory containing custom plugins",
33 ),
34 click.option(
35 "--static",
36 type=StaticMount(),
37 help="Serve static files from this directory at /MOUNT/...",
38 multiple=True,
39 ),
40 click.option(
41 "--install",
42 help="Additional packages (e.g. plugins) to install",
43 multiple=True,
44 ),
45 click.option(
46 "--plugin-secret",
47 nargs=3,
48 type=(str, str, str),
49 callback=validate_plugin_secret,
50 multiple=True,
51 help="Secrets to pass to plugins, e.g. --plugin-secret datasette-auth-github client_id xxx",
52 ),
53 click.option(
54 "--version-note", help="Additional note to show on /-/versions"
55 ),
56 click.option(
57 "--secret",
58 help="Secret used for signing secure values, such as signed cookies",
59 envvar="DATASETTE_PUBLISH_SECRET",
60 default=lambda: os.urandom(32).hex(),
61 ),
62 click.option("--title", help="Title for metadata"),
63 click.option("--license", help="License label for metadata"),
64 click.option("--license_url", help="License URL for metadata"),
65 click.option("--source", help="Source label for metadata"),
66 click.option("--source_url", help="Source URL for metadata"),
67 click.option("--about", help="About label for metadata"),
68 click.option("--about_url", help="About URL for metadata"),
69 )
70 ):
71 subcommand = decorator(subcommand)
72 return subcommand
75def fail_if_publish_binary_not_installed(binary, publish_target, install_link):
76 """Exit (with error message) if ``binary` isn't installed"""
77 if not shutil.which(binary):
78 click.secho(
79 "Publishing to {publish_target} requires {binary} to be installed and configured".format(
80 publish_target=publish_target, binary=binary
81 ),
82 bg="red",
83 fg="white",
84 bold=True,
85 err=True,
86 )
87 click.echo(
88 "Follow the instructions at {install_link}".format(
89 install_link=install_link
90 ),
91 err=True,
92 )
93 sys.exit(1)
96def validate_plugin_secret(ctx, param, value):
97 for plugin_name, plugin_setting, setting_value in value:
98 if "'" in setting_value:
99 raise click.BadParameter("--plugin-secret cannot contain single quotes")
100 return value