|
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,
|
@@ -2815,6 +2817,88 @@ def system_caches_delete(
|
2815 | 2817 | ce.delete_runtime_cache(language, version, image_name, dry_run)
|
2816 | 2818 |
|
2817 | 2819 |
|
| 2820 | +@cli.group(no_args_is_help=True, help="Fetch Posit Connect jumpstart examples.") |
| 2821 | +def examples(): |
| 2822 | + pass |
| 2823 | + |
| 2824 | + |
| 2825 | +@examples.command( |
| 2826 | + name="list", |
| 2827 | + short_help="List jumpstart examples on a Posit Connect server.", |
| 2828 | +) |
| 2829 | +@server_args |
| 2830 | +@click.pass_context |
| 2831 | +def examples_list( |
| 2832 | + ctx: click.Context, |
| 2833 | + name: str, |
| 2834 | + server: Optional[str], |
| 2835 | + api_key: Optional[str], |
| 2836 | + insecure: bool, |
| 2837 | + cacert: Optional[str], |
| 2838 | + verbose: int, |
| 2839 | +): |
| 2840 | + set_verbosity(verbose) |
| 2841 | + output_params(ctx, locals().items()) |
| 2842 | + with cli_feedback("", stderr=True): |
| 2843 | + ce = RSConnectExecutor(ctx, name, server, api_key, insecure, cacert, logger=None).validate_server() |
| 2844 | + if not isinstance(ce.remote_server, RSConnectServer): |
| 2845 | + raise RSConnectException("rsconnect examples list` requires a Posit Connect server.") |
| 2846 | + examples = list_examples(ce.remote_server) |
| 2847 | + result = [{"name": ex["name"], "description": ex["description"]} for ex in examples] |
| 2848 | + json.dump(result, sys.stdout, indent=2) |
| 2849 | + |
| 2850 | + |
| 2851 | +@examples.command( |
| 2852 | + name="download", |
| 2853 | + short_help="Download a jumpstart example from a Posit Connect server.", |
| 2854 | +) |
| 2855 | +@server_args |
| 2856 | +@click.option( |
| 2857 | + "--example", |
| 2858 | + required=True, |
| 2859 | + help="The name of the example to download.", |
| 2860 | +) |
| 2861 | +@click.option( |
| 2862 | + "--output", |
| 2863 | + "-o", |
| 2864 | + type=click.Path(), |
| 2865 | + required=True, |
| 2866 | + help="Defines the output location for the download.", |
| 2867 | +) |
| 2868 | +@click.option( |
| 2869 | + "--overwrite", |
| 2870 | + is_flag=True, |
| 2871 | + help="Overwrite the output file if it already exists.", |
| 2872 | +) |
| 2873 | +@click.pass_context |
| 2874 | +def examples_download( |
| 2875 | + ctx: click.Context, |
| 2876 | + name: Optional[str], |
| 2877 | + server: Optional[str], |
| 2878 | + api_key: Optional[str], |
| 2879 | + insecure: bool, |
| 2880 | + cacert: Optional[str], |
| 2881 | + example: str, |
| 2882 | + output: str, |
| 2883 | + overwrite: bool, |
| 2884 | + verbose: int, |
| 2885 | +): |
| 2886 | + set_verbosity(verbose) |
| 2887 | + output_params(ctx, locals().items()) |
| 2888 | + with cli_feedback("", stderr=True): |
| 2889 | + ce = RSConnectExecutor(ctx, name, server, api_key, insecure, cacert, logger=None).validate_server() |
| 2890 | + if not isinstance(ce.remote_server, RSConnectServer): |
| 2891 | + raise RSConnectException("`rsconnect examples download` requires a Posit Connect server.") |
| 2892 | + if exists(output) and not overwrite: |
| 2893 | + raise RSConnectException("The output file already exists: %s" % output) |
| 2894 | + |
| 2895 | + result = download_example(ce.remote_server, example) |
| 2896 | + if not isinstance(result.response_body, bytes): |
| 2897 | + raise RSConnectException("The response body must be bytes (not string or None).") |
| 2898 | + with open(output, "wb") as f: |
| 2899 | + f.write(result.response_body) |
| 2900 | + |
| 2901 | + |
2818 | 2902 | if __name__ == "__main__":
|
2819 | 2903 | cli()
|
2820 | 2904 | click.echo()
|
0 commit comments