diff --git a/tests/info.yml b/tests/info.yml new file mode 100644 index 0000000..4ab1e57 --- /dev/null +++ b/tests/info.yml @@ -0,0 +1 @@ +info: \ No newline at end of file diff --git a/tw_pywrap/cli.py b/tw_pywrap/cli.py index 1e19c8a..4c801e5 100644 --- a/tw_pywrap/cli.py +++ b/tw_pywrap/cli.py @@ -52,6 +52,7 @@ def __init__(self, tw, list_for_add_method): def handle_block(self, block, args): # Handles a block of commands by calling the appropriate function. block_handler_map = { + "info": helper.handle_info, "teams": helper.handle_teams, "participants": helper.handle_participants, "compute-envs": helper.handle_compute_envs, @@ -95,11 +96,12 @@ def main(): # Returns a dict that maps block names to lists of command line arguments. cmd_args_dict = helper.parse_all_yaml(options.yaml, list(data.keys())) - for block, args_list in cmd_args_dict.items(): - for args in args_list: - # Run the methods for each block - block_manager.handle_block(block, args) - time.sleep(3) + # Flatten commands to list of tuples + cmd_sets = [(block, arg) for block, args in cmd_args_dict.items() for arg in args] + for block, args in cmd_sets: + # Run the methods for each block + block_manager.handle_block(block, args) + time.sleep(3) if __name__ == "__main__": diff --git a/tw_pywrap/helper.py b/tw_pywrap/helper.py index d4402cf..4139625 100644 --- a/tw_pywrap/helper.py +++ b/tw_pywrap/helper.py @@ -3,6 +3,7 @@ Including handling methods for each block in the YAML file, and parsing methods for each block in the YAML file. """ + import json import yaml @@ -24,6 +25,11 @@ def parse_yaml_block(file_path, block_name): cmd_args_list = [] # Iterate over each item in the block. + # If no commands supplied just run `tw ` + if block is None: + logging.warn(f"No arguments applied to {block_name}") + block = [{}] # List of empty dict + for item in block: cmd_args_list.append(parse_block(block_name, item)) @@ -204,6 +210,11 @@ def handle_add_block(tw, block, args): method("add", *args) +def handle_info(tw, args): + method = getattr(tw, "info") + method(*args) + + def handle_teams(tw, args): cmd_args, members_cmd_args = args tw.teams("add", *cmd_args) diff --git a/tw_pywrap/tower.py b/tw_pywrap/tower.py index 5e65c52..3afa543 100644 --- a/tw_pywrap/tower.py +++ b/tw_pywrap/tower.py @@ -58,7 +58,7 @@ def _tw_run(self, cmd, *args, **kwargs): process = subprocess.Popen(full_cmd, stdout=subprocess.PIPE, shell=True) stdout, _ = process.communicate() stdout = stdout.decode("utf-8").strip() - + logging.info(stdout) return stdout # Allow any 'tw' subcommand to be called as a method.