Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minor refactoring to Adam's addition of tw info cmd #58

Open
wants to merge 3 commits into
base: dev
Choose a base branch
from
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:
1 change: 1 addition & 0 deletions tw_pywrap/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,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": lambda tw, args: helper.handle_generic_block(tw, "info", args, method_name=None),
"teams": (helper.handle_teams),
"participants": (helper.handle_participants),
"compute-envs": lambda tw, args: helper.handle_generic_block(
Expand Down
9 changes: 7 additions & 2 deletions tw_pywrap/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
Including handling methods for each block in the YAML file, and parsing
methods for each block in the YAML file.
"""

import yaml
from tw_pywrap import utils

import logging

def parse_yaml_block(file_path, block_name):
# Load the YAML file.
Expand All @@ -22,6 +23,11 @@ def parse_yaml_block(file_path, block_name):
name_values = set()

# 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 = parse_block(block_name, item)
name = find_name(cmd_args)
Expand Down Expand Up @@ -213,7 +219,6 @@ def handle_generic_block(tw, block, args, method_name="add"):
else:
method(method_name, *args)


def handle_teams(tw, args):
cmd_args, members_cmd_args = args
tw.teams("add", *cmd_args)
Expand Down
4 changes: 2 additions & 2 deletions tw_pywrap/tower.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ def _tw_run(self, cmd, *args, **kwargs):
)
stdout, _ = process.communicate()
stdout = stdout.decode("utf-8").strip()

# Error handling for stdout
if stdout:
if re.search(r"ERROR: (?!A pipeline).* already exists", stdout):
Expand All @@ -81,8 +80,9 @@ def _tw_run(self, cmd, *args, **kwargs):
elif to_json is True:
return json.loads(stdout)
else:
logging.info(stdout)
return stdout

# Allow any 'tw' subcommand to be called as a method.
def __getattr__(self, cmd):
"""
Expand Down
Loading