slash.core.envs

Module Contents

Classes

Functions

convert

Convert the subscription to a config file.

Data

API

slash.core.envs.logger

None

slash.core.envs.yaml

‘YAML(…)’

slash.core.envs.convert(sub: Union[str, pathlib.Path], tgt: pathlib.Path) pathlib.Path

Convert the subscription to a config file.

Arguments: sub: str The subscription URL, or path to the config file. tgt: Path The target path to save the converted subscription.

class slash.core.envs.Env(name: str, subscriptions: Optional[List[str]] = None, last_updated: Optional[str] = None)

Initialization

Create an environment object.

Arguments: name: str The name of the environment. The only identifier to this environment. subscriptions: Optional[List[str]] The subscriptions to the environment. It can be a path to the config file or a URL. You can specify multiple subscriptions and all these should point to the same config files. If None, an empty config file will be created. last_updated: Optional[str] The last time the subscription was updated.

property workdir: pathlib.Path
save(path: pathlib.Path = None) None

Save the environment.

save_to(path: pathlib.Path) None

Save as a json file.

classmethod load_from(path: pathlib.Path) slash.core.envs.Env

Load from a json file.

destroy() None

Destroy the environment.

update(workdir: pathlib.Path = None) bool

Update the environment. It is okay if the update fails, as the environment will automatically update if the config file is not found when activated, or we can still use the old config file if the config file already exists.

Returns: is_updated: bool Whether the update is successful.

_get_config() dict

Get the subscription config content.

The config file will be parsed into a python object.

_set_config(content: dict)

Set the subscription config content.

set_port(port: int = 7890)

Set the port of the environment.

set_controller(port: Optional[int] = None, ui_folder: Optional[Union[str, pathlib.Path]] = None, local_only: bool = False, secret: Optional[str] = None) str

Set the controller of the environment.

Arguments: port: Optional[int] The port of the controller. If None, the controller will be disabled. ui_folder: Optional[Union[str, Path]] The folder of the UI. If None, the UI will be disabled. local_only: bool Whether the controller is only accessible from the local machine. secret: Optional[str] The secret key of the controller. If None, a new secret key will be generated.

Returns: secret: str The secret key of the controller. If the controller is disabled, it will return an empty string.

set_dialer_proxy(config: slash.core.config.SlashConfig) bool

Set the dialer proxy of the environment.

class slash.core.envs.EnvsManager

Initialization

property envs: Dict[str, slash.core.envs.Env]

Get all environments. Hot reload from disk.

create_env(*args, **kwargs) slash.core.envs.Env

Create a new environment.

Arguments: name: str The name of the environment. subscriptions: List[str] The subscriptions to the environment. It can be a path to the config file or a URL. You can specify multiple subscriptions and all these should point to the same config files. If None, an empty config file will be created.

Returns: env: Env The created environment.

remove_env(name: str)
get_env(name)
get_envs()