Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions tests/info.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
info:
12 changes: 7 additions & 5 deletions tw_pywrap/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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__":
Expand Down
11 changes: 11 additions & 0 deletions tw_pywrap/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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 <block_name>`
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))

Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion tw_pywrap/tower.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down