Commit 09a167d9 authored by Boris Glimcher's avatar Boris Glimcher Committed by Tomasz Zawadzki
Browse files

python/rpc: move all helper functions into the same module

parent 117acba9
Loading
Loading
Loading
Loading
+1 −18
Original line number Diff line number Diff line
@@ -10,24 +10,7 @@ import logging
import copy
import ctypes

try:
    from shlex import quote
except ImportError:
    from pipes import quote

from .cmd_parser import remove_null


def print_array(a):
    print(" ".join((quote(v) for v in a)))


def print_dict(d):
    print(json.dumps(d, indent=2))


def print_json(s):
    print(json.dumps(s, indent=2).strip('"'))
from .cmd_parser import remove_null, print_array, print_dict, print_json


def get_addr_type(addr):
+42 −0
Original line number Diff line number Diff line
@@ -2,6 +2,18 @@
#  Copyright (C) 2021 Intel Corporation.
#  All rights reserved.

import json
import os
import sys
import io


try:
    from shlex import quote
except ImportError:
    from pipes import quote


args_global = ['server_addr', 'port', 'timeout', 'verbose', 'dry_run', 'conn_retries',
               'is_server', 'rpc_plugin', 'called_rpc_name', 'func', 'client', 'go_client']

@@ -22,3 +34,33 @@ def group_as(kwargs, name, values):
    group = {k: v for k, v in kwargs.items() if k in values and v is not None}
    rest = {k: v for k, v in kwargs.items() if k not in values}
    return {**rest, name: group}


def print_array(a):
    print(" ".join((quote(v) for v in a)))


def print_dict(d):
    print(json.dumps(d, indent=2))


def print_json(s):
    print(json.dumps(s, indent=2).strip('"'))


def json_dump(config, fd, indent):
    if indent is None:
        indent = 2
    elif indent < 0:
        indent = None
    json.dump(config, fd, indent=indent)
    fd.write('\n')


def json_load(j):
    if j == sys.stdin or isinstance(j, io.IOBase):
        return json.load(j)
    if os.path.exists(j):
        with open(j, "r") as j:
            return json.load(j)
    return json.loads(j)
+2 −23
Original line number Diff line number Diff line
@@ -3,30 +3,9 @@
#  Copyright (C) 2025 Dell Inc, or its subsidiaries.
#  All rights reserved.

import json
import os
import sys
import io

from . import client as rpc_client


def _json_dump(config, fd, indent):
    if indent is None:
        indent = 2
    elif indent < 0:
        indent = None
    json.dump(config, fd, indent=indent)
    fd.write('\n')


def _json_load(j):
    if j == sys.stdin or isinstance(j, io.IOBase):
        return json.load(j)
    if os.path.exists(j):
        with open(j, "r") as j:
            return json.load(j)
    return json.loads(j)
from .cmd_parser import json_dump as _json_dump
from .cmd_parser import json_load as _json_load


def save_config(client, fd, indent=2, subsystems=None):