Skip to content
Merged
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
5 changes: 0 additions & 5 deletions cli/cmd/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
11 changes: 0 additions & 11 deletions cli/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ limitations under the License.
package cmd

import (
"encoding/base64"
"fmt"
"os"
"path/filepath"
Expand All @@ -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"
Expand Down Expand Up @@ -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
}
2 changes: 0 additions & 2 deletions cli/types/flags/output_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,12 @@ type OutputType int

const (
UnknownOutputType OutputType = iota
MixedOutputType // Internal only
PrettyOutputType
JSONOutputType
)

var _outputTypes = []string{
"unknown",
"mixed",
"pretty",
"json",
}
Expand Down
30 changes: 3 additions & 27 deletions pkg/cortex/client/cortex/binary/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
"""
Expand All @@ -36,21 +33,19 @@ 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.

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()
Expand All @@ -71,35 +66,16 @@ 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

process.wait()

if process.returncode == 0:
if mixed_output:
return result
return output

if result != "":
Expand Down
4 changes: 2 additions & 2 deletions pkg/cortex/client/cortex/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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, hide_output=True)

deploy_results = json.loads(output.strip())

Expand Down