Skip to content

Commit

Permalink
cloudvision/cvlib: Add setStudioInputs
Browse files Browse the repository at this point in the history
*SetStudioInputs issue a setSome to the Studio inputs rAPI

Change-Id: I4e8a480188a6bc6eb07aacbd00369a5444558777
  • Loading branch information
Kaleb Guo committed Jan 2, 2024
1 parent 53a95c4 commit 7cee59e
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
1 change: 1 addition & 0 deletions cloudvision/cvlib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from .studio import (
Studio,
setStudioInput,
setStudioInputs,
getStudioInputs,
extractInputElems,
extractStudioInfoFromArgs,
Expand Down
31 changes: 30 additions & 1 deletion cloudvision/cvlib/studio.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Use of this source code is governed by the Apache License 2.0
# that can be found in the COPYING file.

from typing import Any, Dict, List
from typing import Any, Dict, List, Tuple
import json
from fmp import wrappers_pb2 as fmp_wrappers
import google.protobuf.wrappers_pb2 as pb
Expand Down Expand Up @@ -197,6 +197,35 @@ def setStudioInput(clientGetter, studioId: str, workspaceId: str, inputPath: Lis
raise InputUpdateException(inputPath, f"Value {value} was not set: {exc}") from None


def setStudioInputs(clientGetter, studioId: str, workspaceId: str, inputs: List[Tuple]):
'''
Uses the passed ctx.getApiClient function reference to
issue a setSome to the Studio inputs rAPI with the associated InputsConfig
'''
client = clientGetter(services.InputsConfigServiceStub)
wid = pb.StringValue(value=workspaceId)
sid = pb.StringValue(value=studioId)
inputsConfigs = []
for path, value in inputs:
item = models.InputsConfig(
key=models.InputsKey(
workspace_id=wid,
studio_id=sid,
path=fmp_wrappers.RepeatedString(values=path)
),
inputs=pb.StringValue(value=json.dumps(value))
)
inputsConfigs.append(item)
req = services.InputsConfigSetSomeRequest(
values=inputsConfigs
)
try:
for res in client.SetSome(request=req):
pass
except RpcError as exc:
raise InputUpdateException(err=f"Inputs {inputs} was not set: {exc}") from None


def extractInputElems(inputs, inputPath: List[str], elems: List[str] = [],
tagElems: List[str] = []):
'''
Expand Down

0 comments on commit 7cee59e

Please sign in to comment.