44from pathlib import Path
55from subprocess import run
66from time import sleep
7+ from typing import Optional
78
89import click
910from kubernetes .stream import stream
1011
1112# When we want to select pods based on their role in Warnet, we use "mission" tags. The "mission"
1213# tag for "lightning" nodes is stored in LIGHTNING_MISSION.
13- from warnet .constants import LIGHTNING_MISSION
14+ from warnet .constants import LIGHTNING_MISSION , USER_DIR_TAG
1415from warnet .k8s import (
1516 download ,
1617 get_default_namespace ,
1718 get_mission ,
1819 get_static_client ,
1920 wait_for_pod ,
2021)
21- from warnet .plugins import get_plugins_directory_or as get_plugin_directory
22+ from warnet .plugins import get_plugins_directory_or
2223from warnet .process import run_command
2324from warnet .status import _get_tank_status as network_status
2425
@@ -86,9 +87,11 @@ def list_simln_podnames():
8687
8788
8889@simln .command ()
90+ @click .argument ("pod_name" , type = str )
8991def download_results (pod_name : str ):
9092 """Download SimLN results to the current directory"""
91- print (download (pod_name , source_path = Path ("/working/results" )))
93+ dest = download (pod_name , source_path = Path ("/working/results" ))
94+ print (f"Downloaded results to: { dest } " )
9295
9396
9497def prepare_and_launch_activity () -> str :
@@ -123,10 +126,10 @@ def get_example_activity():
123126 print (json .dumps (_get_example_activity ()))
124127
125128
126- def _launch_activity (activity : list [dict ]) -> str :
129+ def _launch_activity (activity : list [dict ], user_dir : Optional [ str ] = None ) -> str :
127130 """Launch a SimLN chart which includes the `activity`"""
128131 random_digits = "" .join (random .choices ("0123456789" , k = 10 ))
129- plugin_dir = get_plugin_directory ( )
132+ plugin_dir = get_plugins_directory_or ( user_dir )
130133 _generate_nodes_file (activity , plugin_dir / Path ("simln/charts/simln/files/sim.json" ))
131134 command = f"helm upgrade --install simln-{ random_digits } { plugin_dir } /simln/charts/simln"
132135 log .info (f"generate activity: { command } " )
@@ -137,10 +140,12 @@ def _launch_activity(activity: list[dict]) -> str:
137140# Take note of how click expects us to explicitly declare command line arguments.
138141@simln .command ()
139142@click .argument ("activity" , type = str )
140- def launch_activity (activity : str ):
143+ @click .pass_context
144+ def launch_activity (ctx , activity : str ):
141145 """Takes a SimLN Activity which is a JSON list of objects."""
142146 parsed_activity = json .loads (activity )
143- print (_launch_activity (parsed_activity ))
147+ user_dir = ctx .obj .get (USER_DIR_TAG )
148+ print (_launch_activity (parsed_activity , user_dir ))
144149
145150
146151def _init_network ():
0 commit comments