Buckets:
AnonymousSpottedToad/candidate_bucket / codebase /python /bluesky_tiled /tiled /commandline /_profile.py
| import typer | |
| profile_app = typer.Typer(no_args_is_help=True) | |
| def profile_paths(): | |
| "List the locations that the client will search for profiles (client-side configuration)." | |
| from ..profiles import paths | |
| print("\n".join(str(p) for p in paths)) | |
| def profile_list(): | |
| "List the profiles (client-side configuration) found and the files they were read from." | |
| from ..profiles import load_profiles | |
| profiles = load_profiles() | |
| if not profiles: | |
| typer.echo("No profiles found.") | |
| return | |
| max_len = max(len(name) for name in profiles) | |
| PADDING = 4 | |
| print( | |
| "\n".join( | |
| f"{name:<{max_len + PADDING}}{filepath}" | |
| for name, (filepath, _) in profiles.items() | |
| ) | |
| ) | |
| def profile_show(profile_name: str): | |
| "Show the content of a profile." | |
| import sys | |
| import yaml | |
| from ..profiles import load_profiles | |
| profiles = load_profiles() | |
| try: | |
| filepath, content = profiles[profile_name] | |
| except KeyError: | |
| typer.echo( | |
| f"The profile {profile_name!r} could not be found. " | |
| "Use tiled profile list to see profile names.", | |
| err=True, | |
| ) | |
| raise typer.Abort() | |
| print(f"Source: {filepath}", file=sys.stderr) | |
| print("--", file=sys.stderr) | |
| print(yaml.dump(content), file=sys.stdout) | |
| def profile_edit(profile_name: str): | |
| "Show the content of a profile." | |
| import sys | |
| from ..profiles import load_profiles | |
| profiles = load_profiles() | |
| try: | |
| filepath, content = profiles[profile_name] | |
| except KeyError: | |
| typer.echo( | |
| f"The profile {profile_name!r} could not be found. " | |
| "Use tiled profile list to see profile names.", | |
| err=True, | |
| ) | |
| raise typer.Abort() | |
| print(f"Opening {filepath} in default text editor...", file=sys.stderr) | |
| import os | |
| import platform | |
| import subprocess | |
| if platform.system() == "Darwin": | |
| subprocess.call(("open", filepath)) | |
| elif platform.system() == "Windows": | |
| os.startfile(filepath) | |
| else: | |
| subprocess.call(("xdg-open", filepath)) | |
| def create( | |
| uri: str = typer.Argument(..., help="URI 'http[s]://...'"), | |
| name: str = typer.Option("auto", help="Profile name, a short convenient alias"), | |
| set_default: bool = typer.Option( | |
| True, help="Set new profile as the default profile." | |
| ), | |
| overwrite: bool = typer.Option( | |
| False, "--overwrite", help="Overwrite an existing profile of this name." | |
| ), | |
| no_verify: bool = typer.Option(False, "--no-verify", help="Skip SSL verification."), | |
| ): | |
| """ | |
| Create a 'profile' that can be used to connect to a Tiled server. | |
| """ | |
| from ..profiles import ProfileExists, create_profile, set_default_profile_name | |
| try: | |
| create_profile(name=name, uri=uri, verify=not no_verify, overwrite=overwrite) | |
| except ProfileExists: | |
| typer.echo( | |
| f"A profile named {name!r} already exists. Use --overwrite to overwrite it." | |
| ) | |
| raise typer.Abort() | |
| if set_default: | |
| set_default_profile_name(name) | |
| typer.echo(f"Tiled profile {name!r} created and set as the default.", err=True) | |
| else: | |
| typer.echo(f"Tiled profile {name!r} created.", err=True) | |
| def delete( | |
| name: str = typer.Argument(..., help="Profile name"), | |
| ): | |
| from ..profiles import ( | |
| delete_profile, | |
| get_default_profile_name, | |
| set_default_profile_name, | |
| ) | |
| # Unset the default if this profile is currently the default. | |
| default = get_default_profile_name() | |
| if default == name: | |
| set_default_profile_name(None) | |
| delete_profile(name) | |
| typer.echo(f"Tiled profile {name!r} deleted.", err=True) | |
| def get_default(): | |
| """ | |
| Show the current default Tiled profile. | |
| """ | |
| from ..profiles import get_default_profile_name, load_profiles | |
| name = get_default_profile_name() | |
| if name is None: | |
| typer.echo("No default.", err=True) | |
| else: | |
| import yaml | |
| source_filepath, profile_content = load_profiles()[name] | |
| typer.echo(f"# Profile name: {name!r}") | |
| typer.echo(f"# {source_filepath} \n") | |
| typer.echo(yaml.dump(profile_content)) | |
| def set_default(profile_name: str): | |
| """ | |
| Set the default Tiled profile. | |
| """ | |
| from ..profiles import set_default_profile_name | |
| set_default_profile_name(profile_name) | |
| def clear_default(): | |
| """ | |
| Clear the default Tiled profile. | |
| """ | |
| from ..profiles import set_default_profile_name | |
| set_default_profile_name(None) | |
Xet Storage Details
- Size:
- 4.87 kB
- Xet hash:
- 1e24454d23d9f8bbdf97b5580a5d4a5119cdf00268e3a7ae2899df501e994c7f
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.