|
44 | 44 | build_remove_content,
|
45 | 45 | build_start,
|
46 | 46 | download_bundle,
|
| 47 | + download_example, |
47 | 48 | emit_build_log,
|
48 | 49 | get_content,
|
| 50 | + list_examples, |
49 | 51 | search_content,
|
50 | 52 | )
|
51 | 53 | from .api import RSConnectClient, RSConnectExecutor, RSConnectServer
|
|
60 | 62 | make_manifest_bundle,
|
61 | 63 | make_notebook_html_bundle,
|
62 | 64 | make_notebook_source_bundle,
|
63 |
| - make_voila_bundle, |
64 | 65 | make_tensorflow_bundle,
|
| 66 | + make_voila_bundle, |
65 | 67 | read_manifest_app_mode,
|
66 | 68 | validate_entry_point,
|
67 | 69 | validate_extra_files,
|
@@ -2872,6 +2874,88 @@ def system_caches_delete(
|
2872 | 2874 | ce.delete_runtime_cache(language, version, image_name, dry_run)
|
2873 | 2875 |
|
2874 | 2876 |
|
| 2877 | +@cli.group(no_args_is_help=True, help="Fetch Posit Connect jumpstart examples.") |
| 2878 | +def examples(): |
| 2879 | + pass |
| 2880 | + |
| 2881 | + |
| 2882 | +@examples.command( |
| 2883 | + name="list", |
| 2884 | + short_help="List jumpstart examples on a Posit Connect server.", |
| 2885 | +) |
| 2886 | +@server_args |
| 2887 | +@click.pass_context |
| 2888 | +def examples_list( |
| 2889 | + ctx: click.Context, |
| 2890 | + name: str, |
| 2891 | + server: Optional[str], |
| 2892 | + api_key: Optional[str], |
| 2893 | + insecure: bool, |
| 2894 | + cacert: Optional[str], |
| 2895 | + verbose: int, |
| 2896 | +): |
| 2897 | + set_verbosity(verbose) |
| 2898 | + output_params(ctx, locals().items()) |
| 2899 | + with cli_feedback("", stderr=True): |
| 2900 | + ce = RSConnectExecutor(ctx, name, server, api_key, insecure, cacert, logger=None).validate_server() |
| 2901 | + if not isinstance(ce.remote_server, RSConnectServer): |
| 2902 | + raise RSConnectException("rsconnect examples list` requires a Posit Connect server.") |
| 2903 | + examples = list_examples(ce.remote_server) |
| 2904 | + result = [{"name": ex["name"], "description": ex["description"]} for ex in examples] |
| 2905 | + json.dump(result, sys.stdout, indent=2) |
| 2906 | + |
| 2907 | + |
| 2908 | +@examples.command( |
| 2909 | + name="download", |
| 2910 | + short_help="Download a jumpstart example from a Posit Connect server.", |
| 2911 | +) |
| 2912 | +@server_args |
| 2913 | +@click.option( |
| 2914 | + "--example", |
| 2915 | + required=True, |
| 2916 | + help="The name of the example to download.", |
| 2917 | +) |
| 2918 | +@click.option( |
| 2919 | + "--output", |
| 2920 | + "-o", |
| 2921 | + type=click.Path(), |
| 2922 | + required=True, |
| 2923 | + help="Defines the output location for the download.", |
| 2924 | +) |
| 2925 | +@click.option( |
| 2926 | + "--overwrite", |
| 2927 | + is_flag=True, |
| 2928 | + help="Overwrite the output file if it already exists.", |
| 2929 | +) |
| 2930 | +@click.pass_context |
| 2931 | +def examples_download( |
| 2932 | + ctx: click.Context, |
| 2933 | + name: Optional[str], |
| 2934 | + server: Optional[str], |
| 2935 | + api_key: Optional[str], |
| 2936 | + insecure: bool, |
| 2937 | + cacert: Optional[str], |
| 2938 | + example: str, |
| 2939 | + output: str, |
| 2940 | + overwrite: bool, |
| 2941 | + verbose: int, |
| 2942 | +): |
| 2943 | + set_verbosity(verbose) |
| 2944 | + output_params(ctx, locals().items()) |
| 2945 | + with cli_feedback("", stderr=True): |
| 2946 | + ce = RSConnectExecutor(ctx, name, server, api_key, insecure, cacert, logger=None).validate_server() |
| 2947 | + if not isinstance(ce.remote_server, RSConnectServer): |
| 2948 | + raise RSConnectException("`rsconnect examples download` requires a Posit Connect server.") |
| 2949 | + if exists(output) and not overwrite: |
| 2950 | + raise RSConnectException("The output file already exists: %s" % output) |
| 2951 | + |
| 2952 | + result = download_example(ce.remote_server, example) |
| 2953 | + if not isinstance(result.response_body, bytes): |
| 2954 | + raise RSConnectException("The response body must be bytes (not string or None).") |
| 2955 | + with open(output, "wb") as f: |
| 2956 | + f.write(result.response_body) |
| 2957 | + |
| 2958 | + |
2875 | 2959 | if __name__ == "__main__":
|
2876 | 2960 | cli()
|
2877 | 2961 | click.echo()
|
0 commit comments