Prefix tmux container names with student
This commit is contained in:
@@ -3352,6 +3352,28 @@ def current_user_slug() -> str:
|
|||||||
return slug_value(os.environ.get("USER") or home_dir.name or f"uid{os.getuid()}", "user name")
|
return slug_value(os.environ.get("USER") or home_dir.name or f"uid{os.getuid()}", "user name")
|
||||||
|
|
||||||
|
|
||||||
|
def display_user_slug(raw_user: str) -> str:
|
||||||
|
match = re.fullmatch(r"u(\d+)", raw_user)
|
||||||
|
if match:
|
||||||
|
return f"u{int(match.group(1)):02d}"
|
||||||
|
return raw_user
|
||||||
|
|
||||||
|
|
||||||
|
def runtime_name_slug(raw_value: str, field_name: str) -> str:
|
||||||
|
slug = re.sub(r"[^a-z0-9]+", "_", raw_value.strip().lower()).strip("_")
|
||||||
|
if not slug:
|
||||||
|
raise SystemExit(f"Invalid {field_name}: {raw_value!r}")
|
||||||
|
return slug
|
||||||
|
|
||||||
|
|
||||||
|
def runtime_name(user_name: str, profile: str, selector: str, window_name: str) -> str:
|
||||||
|
selector_parts = selector.split("/")
|
||||||
|
name_parts = [display_user_slug(user_name), profile]
|
||||||
|
name_parts.extend(runtime_name_slug(part, "card selector") for part in selector_parts)
|
||||||
|
name_parts.append(runtime_name_slug(window_name, "tmux window name"))
|
||||||
|
return "_".join(name_parts)
|
||||||
|
|
||||||
|
|
||||||
def build_container_command(
|
def build_container_command(
|
||||||
config: WorkspaceConfig,
|
config: WorkspaceConfig,
|
||||||
selector: str,
|
selector: str,
|
||||||
@@ -3373,13 +3395,10 @@ def build_container_command(
|
|||||||
|
|
||||||
home_dir = Path(os.environ.get("HOME") or str(Path.home()))
|
home_dir = Path(os.environ.get("HOME") or str(Path.home()))
|
||||||
card_path_text = str(card_path)
|
card_path_text = str(card_path)
|
||||||
selector_slug = slug_value(selector.replace("/", "-"), "card selector")
|
|
||||||
window_slug = slug_value(window_name, "tmux window name")
|
|
||||||
user_name = current_user_slug()
|
user_name = current_user_slug()
|
||||||
host_uid = str(os.getuid())
|
host_uid = str(os.getuid())
|
||||||
host_gid = str(os.getgid())
|
host_gid = str(os.getgid())
|
||||||
container_name_parts = [selector_slug, window_slug, profile, user_name]
|
container_name = runtime_name(user_name, profile, selector, window_name)
|
||||||
container_name = "-".join(container_name_parts)
|
|
||||||
shell_rcfile = tool_root / "configs" / "rv-shell.bashrc"
|
shell_rcfile = tool_root / "configs" / "rv-shell.bashrc"
|
||||||
env_parts = [
|
env_parts = [
|
||||||
f"WORKSPACE_ROOT={shlex.quote(str(config.workspace_root))}",
|
f"WORKSPACE_ROOT={shlex.quote(str(config.workspace_root))}",
|
||||||
@@ -3464,7 +3483,7 @@ def run_tmux_container(config: WorkspaceConfig, args: argparse.Namespace) -> Non
|
|||||||
|
|
||||||
profile = normalize_env_profile(args.profile)
|
profile = normalize_env_profile(args.profile)
|
||||||
user_name = current_user_slug()
|
user_name = current_user_slug()
|
||||||
default_session_name = f"rvctl-{user_name}-{slug_value(selector.replace('/', '-'), 'card selector')}-{profile}"
|
default_session_name = runtime_name(user_name, profile, selector, args.window or config.defaults.get("tmux_window", "rv"))
|
||||||
session_name = args.session or default_session_name
|
session_name = args.session or default_session_name
|
||||||
window_name = args.window or config.defaults.get("tmux_window", "rv")
|
window_name = args.window or config.defaults.get("tmux_window", "rv")
|
||||||
instance = args.instance or config.defaults.get("instance", "shell")
|
instance = args.instance or config.defaults.get("instance", "shell")
|
||||||
|
|||||||
Reference in New Issue
Block a user