Skip to content

Commit

Permalink
added comms
Browse files Browse the repository at this point in the history
  • Loading branch information
aj-ya committed May 21, 2024
1 parent 705a21d commit c31b88e
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 26 deletions.
2 changes: 1 addition & 1 deletion outpostcli/constants.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
cli_version = "0.0.40"
cli_version = "0.0.41"
CLI_BINARY_NAME = "outpostcli"
22 changes: 1 addition & 21 deletions outpostcli/lfs/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
import os
import subprocess
import sys
from typing import Dict, Optional

import click
from outpostkit.repository.lfs.logger import create_lfs_logger

from outpostcli.constants import CLI_BINARY_NAME
from outpostcli.lfs.comms import read_msg, write_msg
from outpostcli.lfs.storage_class.gcs import gcs_multipart_upload
from outpostcli.lfs.storage_class.s3 import aws_multipart_upload
from outpostcli.utils import click_group
Expand Down Expand Up @@ -73,26 +73,6 @@ def enable_largefiles(path):
click.echo("Local repository set up for largefiles")


def write_msg(msg: Dict):
"""Write out the message in Line delimited JSON."""
msg_str = json.dumps(msg) + "\n"
sys.stdout.write(msg_str)
sys.stdout.flush()

def read_msg() -> Optional[Dict]:
"""Read Line delimited JSON from stdin."""
msg = json.loads(sys.stdin.readline().strip())
_log.info(msg)
if "terminate" in (msg.get("type"), msg.get("event")):
# terminate message received
return None

if msg.get("event") not in ("download", "upload"):
# logger.critical("Received unexpected message")
sys.exit(1)

return msg

@lfs.command(name=MULTIPART_UPLOAD_COMMAND_NAME)
def multipart_upload():
try:
Expand Down
29 changes: 29 additions & 0 deletions outpostcli/lfs/comms.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import json
import sys
from typing import Dict, Optional

from outpostkit.repository.lfs.logger import create_lfs_logger

_log = create_lfs_logger(__name__)


def write_msg(msg: Dict):
"""Write out the message in Line delimited JSON."""
msg_str = json.dumps(msg) + "\n"
sys.stdout.write(msg_str)
sys.stdout.flush()


def read_msg() -> Optional[Dict]:
"""Read Line delimited JSON from stdin."""
msg = json.loads(sys.stdin.readline().strip())
_log.info(msg)
if "terminate" in (msg.get("type"), msg.get("event")):
# terminate message received
return None

if msg.get("event") not in ("download", "upload"):
# logger.critical("Received unexpected message")
sys.exit(1)

return msg
2 changes: 1 addition & 1 deletion outpostcli/lfs/storage_class/gcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import requests
from outpostkit.repository.lfs.logger import create_lfs_logger

from outpostcli.lfs.commands import write_msg
from outpostcli.lfs.comms import write_msg
from outpostcli.lfs.exc import LFSException, ProxyLFSException
from outpostcli.lfs.parallel import multimap
from outpostcli.lfs.part import PartInfo, transfer_part
Expand Down
2 changes: 1 addition & 1 deletion outpostcli/lfs/storage_class/s3.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import requests
from outpostkit.repository.lfs.logger import create_lfs_logger

from outpostcli.lfs.commands import write_msg
from outpostcli.lfs.comms import write_msg
from outpostcli.lfs.exc import LFSException, ProxyLFSException
from outpostcli.lfs.parallel import multimap
from outpostcli.lfs.part import PartInfo, transfer_part
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "outpostcli"
version = "0.0.40"
version = "0.0.41"
description = "CLI for Outpost"
readme = "README.md"
license = { file = "LICENSE" }
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

setup(
name="outpostcli",
version="0.0.40",
version="0.0.41",
py_modules=["outpostcli"],
install_requires=["Click", "outpostkit"],
entry_points={
Expand Down

0 comments on commit c31b88e

Please sign in to comment.