From 10361db248381d8cc6ee0891cb86150d630554db Mon Sep 17 00:00:00 2001 From: vishal Date: Wed, 10 Mar 2021 19:21:56 -0500 Subject: [PATCH 1/3] Remove mixed output from python client --- cli/cmd/deploy.go | 5 ---- cli/cmd/root.go | 11 -------- pkg/cortex/client/cortex/binary/__init__.py | 30 +++------------------ pkg/cortex/client/cortex/client.py | 4 +-- 4 files changed, 5 insertions(+), 45 deletions(-) diff --git a/cli/cmd/deploy.go b/cli/cmd/deploy.go index c8dfd398df..904dab8999 100644 --- a/cli/cmd/deploy.go +++ b/cli/cmd/deploy.go @@ -110,11 +110,6 @@ var _deployCmd = &cobra.Command{ exit.Error(err) } fmt.Print(string(bytes)) - case flags.MixedOutputType: - err := mixedPrint(deployResults) - if err != nil { - exit.Error(err) - } case flags.PrettyOutputType: message, err := deployMessage(deployResults, env.Name) if err != nil { diff --git a/cli/cmd/root.go b/cli/cmd/root.go index 3f1d09f96a..adcdce6ba1 100644 --- a/cli/cmd/root.go +++ b/cli/cmd/root.go @@ -17,7 +17,6 @@ limitations under the License. package cmd import ( - "encoding/base64" "fmt" "os" "path/filepath" @@ -27,7 +26,6 @@ import ( "github.com/cortexlabs/cortex/pkg/lib/errors" "github.com/cortexlabs/cortex/pkg/lib/exit" "github.com/cortexlabs/cortex/pkg/lib/files" - libjson "github.com/cortexlabs/cortex/pkg/lib/json" s "github.com/cortexlabs/cortex/pkg/lib/strings" "github.com/cortexlabs/cortex/pkg/lib/telemetry" homedir "github.com/mitchellh/go-homedir" @@ -238,12 +236,3 @@ func envStringIfNotSpecified(envName string, cmd *cobra.Command) (string, error) return "", nil } - -func mixedPrint(a interface{}) error { - jsonBytes, err := libjson.Marshal(a) - if err != nil { - return err - } - fmt.Print(fmt.Sprintf("~~cortex~~%s~~cortex~~", base64.StdEncoding.EncodeToString(jsonBytes))) - return nil -} diff --git a/pkg/cortex/client/cortex/binary/__init__.py b/pkg/cortex/client/cortex/binary/__init__.py index 94749057ea..5a6e85fefc 100644 --- a/pkg/cortex/client/cortex/binary/__init__.py +++ b/pkg/cortex/client/cortex/binary/__init__.py @@ -13,14 +13,11 @@ # limitations under the License. import os -import base64 import sys import subprocess from typing import List from cortex.exceptions import CortexBinaryException -MIXED_CORTEX_MARKER = "~~cortex~~" - def run(): """ @@ -36,7 +33,6 @@ def run(): def run_cli( args: List[str], hide_output: bool = False, - mixed_output: bool = False, ) -> str: """ Runs the Cortex binary with the specified arguments. @@ -44,13 +40,12 @@ def run_cli( Args: args: Arguments to use when invoking the Cortex CLI. hide_output: Flag to prevent streaming CLI output to stdout. - mixed_output: Used to handle CLI output that both prints to stdout and should be returned. Raises: CortexBinaryException: Cortex CLI command returned an error. Returns: - The stdout from the Cortex CLI command, or the result if mixed_output output. + The stdout from the Cortex CLI command. """ env = os.environ.copy() @@ -71,26 +66,9 @@ def run_cli( for c in iter(lambda: process.stdout.read(1), ""): output += c - if mixed_output: - if output[-2:] == "\n~" or output == "~": - processing_result = True - output = output[:-1] - if processing_result: - result += c - if ( - result[: len(MIXED_CORTEX_MARKER)] == MIXED_CORTEX_MARKER - and result[-len(MIXED_CORTEX_MARKER) :] == MIXED_CORTEX_MARKER - and len(result) > len(MIXED_CORTEX_MARKER) - ): - result = result[len(MIXED_CORTEX_MARKER) : -len(MIXED_CORTEX_MARKER)] - result = base64.b64decode(result).decode("utf8") - processed_result = True - - output = output[:-1] if not hide_output: - if (not mixed_output) or (mixed_output and not processing_result): - sys.stdout.write(c) - sys.stdout.flush() + sys.stdout.write(c) + sys.stdout.flush() if processed_result == True: processing_result = False @@ -98,8 +76,6 @@ def run_cli( process.wait() if process.returncode == 0: - if mixed_output: - return result return output if result != "": diff --git a/pkg/cortex/client/cortex/client.py b/pkg/cortex/client/cortex/client.py index d148904cd6..aacf906ebd 100644 --- a/pkg/cortex/client/cortex/client.py +++ b/pkg/cortex/client/cortex/client.py @@ -239,14 +239,14 @@ def _deploy( "--env", self.env_name, "-o", - "mixed", + "json", "-y", ] if force: args.append("--force") - output = run_cli(args, mixed_output=True) + output = run_cli(args) deploy_results = json.loads(output.strip()) From 68046d5a0a069c4d22bb30ee6b958fcc8da8d749 Mon Sep 17 00:00:00 2001 From: vishal Date: Wed, 10 Mar 2021 19:22:43 -0500 Subject: [PATCH 2/3] Remove mixed output from types --- cli/types/flags/output_type.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/cli/types/flags/output_type.go b/cli/types/flags/output_type.go index 6f586dfed6..44081ab81c 100644 --- a/cli/types/flags/output_type.go +++ b/cli/types/flags/output_type.go @@ -20,14 +20,12 @@ type OutputType int const ( UnknownOutputType OutputType = iota - MixedOutputType // Internal only PrettyOutputType JSONOutputType ) var _outputTypes = []string{ "unknown", - "mixed", "pretty", "json", } From 0407adf68455de92374214d8131887c7b2951bc8 Mon Sep 17 00:00:00 2001 From: vishal Date: Fri, 12 Mar 2021 09:59:20 -0500 Subject: [PATCH 3/3] Hide deploy output --- pkg/cortex/client/cortex/client.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/cortex/client/cortex/client.py b/pkg/cortex/client/cortex/client.py index aacf906ebd..158842aa47 100644 --- a/pkg/cortex/client/cortex/client.py +++ b/pkg/cortex/client/cortex/client.py @@ -246,7 +246,7 @@ def _deploy( if force: args.append("--force") - output = run_cli(args) + output = run_cli(args, hide_output=True) deploy_results = json.loads(output.strip())