Commit 083636b5 authored by Gianluca Marotta's avatar Gianluca Marotta
Browse files

CT-220 Fixed Errors, added string documentation, changed class name

parent b032f05e
Loading
Loading
Loading
Loading
Loading
+22 −5
Original line number Diff line number Diff line
import json
from ska_telmodel.csp.schema import validate_csp_config

class ManageJson:
class JsonConfiguration:
    """
    A set of methods to manage the json configuration inside CSP code
    """
    def __init__(self, json_config:str, logger):
        self.major_version=None
        self.minor_version=None
@@ -9,6 +12,9 @@ class ManageJson:
        self.logger = logger

    def detect_version(self):
        """
        Detect the version of the json configuration
        """
        #ADR-22
        if 'interface' in self.config.keys():
            interface = self.config['interface']
@@ -16,7 +22,7 @@ class ManageJson:
            self.major_version = int(version_str.split('.')[0])
            self.minor_version = int(version_str.split('.')[1])
        #ADR-18
        elif 'common' in config.keys():
        elif 'common' in self.config.keys():
            self.major_version = 0
            self.minor_version = 2
        #pre ADR-18
@@ -24,9 +30,12 @@ class ManageJson:
            self.major_version = 0
            self.minor_version = 1
        self.version = [self.major_version, self.minor_version]
        self.logger.info(f'Version is{major_version}{minor_version}')
        self.logger.info(f'Version is{self.major_version}{self.minor_version}')

    def get_section(self, name:str):
        """
        Returns the correpondant section of json configuration
        """
        try:
            return self.config[name]
        except KeyError as e:
@@ -34,13 +43,21 @@ class ManageJson:
            raise ValueError(e) from e

    def conversion_02_01(self):
        """
        Converts the json from version 0.2 to version 0.1
        """
        common_dict = self.get_section('common')
        cbf_dict = self.get_section('cbf')
        config_converted = {**common_dict, **cbf_dict}
        validate_csp_config(0, config_converted)
        validate_csp_config(version=0, template=True, config=config_converted) #check template parameter
        self.config = config_converted
            
    def build_json(self):
    def build_json_cbf(self) -> dict:
        "
        Returns the json configuration dictionary to be passed to cbf.
        If a version 0.2 is given, it converts to 0.1
        "
        self.detect_version()
        if self.version == [0, 1]:
            pass
        elif self.version == [0,2]: