Beispiel #1
0
    def test_read_config_file(self):
        current_config_file = THIS_FOLDER + r"..\Configurator\Core\config.yaml"

        manager = ConfigManager()
        obj = manager.read_config_file(current_config_file)
        print(self.print_obj(obj))
        self.assertIsNotNone(obj)
Beispiel #2
0
    def GetConnectionDetails(cls,
                             sectionName,
                             type_attr_name=None,
                             current_config_file="",
                             sheet_name=None):
        # type: (str) -> object
        """
        to do : get the section from the Configuration manager
        :param sectionName:
        :param type_attr_name: the attribute name we use to identify the type of Channel
        :return: Object that represent some connection data
        """

        if isinstance(sectionName, bytes):
            sectionName = sectionName.decode('utf-8')

        if current_config_file == "":
            current_config_file = cls.GetSetupPath()
        current_key = cls._config_data.setup_reasource_data.base_entry_name + sectionName.lower(
        ) if sheet_name is None else "{}.{}".format(sheet_name,
                                                    sectionName.lower())
        manager = ConfigManager()
        tmp = manager.get_obj(current_key,
                              current_config_file,
                              section_type_key=type_attr_name)
        return tmp
Beispiel #3
0
def GetConfigData():
    global configData
    if configData is None:
        configData = ConfigManager().read_config_file(
            os.path.join(base_path, "ResourceManagerConfig.yaml"))

    return configData
Beispiel #4
0
    def GetConnectionData(cls,
                          channelName,
                          type_attr_name=None,
                          current_config_file="",
                          sheet_name=None,
                          section_name=None):
        if current_config_file == "":
            current_config_file = cls.GetSetupPath()

        if isinstance(current_config_file, bytes):
            current_config_file = current_config_file.decode('utf-8')

        if current_config_file.startswith('.'):
            import os
            current_config_file = current_config_file.replace(
                '.', os.path.dirname(os.path.realpath(__file__)))

        current_key = cls._config_data.setup_reasource_data.communication_section_name if sheet_name is None else "{}.{}".format(
            sheet_name, section_name)

        manager = ConfigManager()
        commSettings = manager.get_obj(current_key,
                                       current_config_file,
                                       section_type_key=type_attr_name)

        try:
            sectionName = getattr(commSettings, channelName)
        except Exception as e:
            raise PythonComException("The channel name doesnt exists")

        connectionDetails = cls.GetConnectionDetails(
            sectionName.value,
            type_attr_name,
            current_config_file=current_config_file,
            sheet_name=sheet_name)
        return connectionDetails
Beispiel #5
0
 def check_config(self, key, c_file, prototype=None):
     manager = ConfigManager()
     obj = manager.get_obj(key, c_file, prototype)
     print(self.print_obj(obj))
     self.assertIsNotNone(obj)
Beispiel #6
0
    def GetSetupPath(cls,
                     setup_name="",
                     setup_list_path="",
                     settings_section_name="",
                     attribute_name=""):
        manager = ConfigManager()
        low_strip = ABCConfigurationReader.low_strip

        if setup_list_path == "":
            setup_list_path = cls._config_data.setup_reasource_data.setup_list_path

        setup_list_path = cls.FixPathForOS(setup_list_path)

        if setup_list_path.startswith('.'):
            setup_list_path = os.path.dirname(
                os.path.realpath(__file__)) + setup_list_path[1:]

        if attribute_name == "":
            attribute_name = cls._config_data.setup_reasource_data.base_setup_attr_name + " " + str(
                cls._setupNum)

        attribute_name = low_strip(attribute_name)

        if settings_section_name == "":
            settings_section_name = cls._config_data.setup_reasource_data.common_settings_section_name

        if setup_name == "":
            orig_pc_name = platform.node()
            _pc_name = orig_pc_name
            try:
                setup_name = _pc_name
            except Exception as e:
                setup_name = ""

        setup_name = low_strip(setup_name.lower())

        section_obj = manager.get_obj(settings_section_name, setup_list_path)

        _pc_data = None
        try:
            if setup_name != "":
                _pc_data = getattr(section_obj, setup_name)
        except Exception as e:
            _pc_data = None

        if _pc_data is None:
            try:
                _pc_data = getattr(section_obj, "local_host")
            except Exception as e:
                raise PythonComException(
                    "Current computer name \"{}\" doesnt exists".format(
                        setup_name))

        try:
            setup_config_file_path = getattr(_pc_data, attribute_name)
        except Exception as e:
            raise PythonComException(
                "Setup name \"{}\" doesnt exists".format(attribute_name))

        if isinstance(setup_config_file_path, bytes):
            setup_config_file_path = setup_config_file_path.decode('utf-8')

        if setup_config_file_path.startswith('.'):
            setup_config_file_path = os.path.join(
                os.path.dirname(os.path.realpath(__file__)),
                setup_config_file_path[2:])

        return setup_config_file_path