Ejemplo n.º 1
0
    def transfer(self, obj_1, obj_2, structure, structure_parent, class_module,
                 classname_gen):
        """Updates the values of the config nodes using the values of the
        attributes of the object provided using the given structure.

        :param obj_1: Object to be used for obtaining the values.
        :param obj_2: Object to be updated.
        :param structure: Structure of obj_1 & obj_2.
        :param str structure_parent: name of the root object for the structure.
        :param mod class_module: Module containing the classes used in the
            obj_2 structure.
        :param classname_gen: Callback function that can update the name of the
            class.
        """
        assert isinstance(structure, dict)
        assert isinstance(structure_parent, str)

        logger.debug2('Transferring data from obj_1 to obj_2\n'
                      '    ' + 'obj_1: ' + str(obj_1) + '\n'
                      '    ' + 'obj_2: ' + str(obj_2) + '\n'
                      '    ' + 'Root name: ' + structure_parent + '\n'
                      '    ' + 'Class module: ' + str(class_module))
        cb_dict = get_cb_dict(base_modules=class_module,
                              base_classname_gen=classname_gen,
                              path_basepath=os.path.dirname(self.config_path))
        return_val = DataHandler(cb_dict).transfer(obj_1, obj_2, structure,
                                                   structure_parent)
        logger.debug2('Transferred data from obj_1 to obj_2')
        return return_val
    def validate(self, validation_data):
        """Normalizes and validates the semantics of the data contained in the
            xml using the given validation_data.

        :param validation_data: Data that specifies how to validate the root
            node. This will in most cases be a dictionary.
        """
        logger.debug2('Normalizing and validating the xml semantics')
        try:
            cb_dict = get_cb_dict(path_basepath=os.path.dirname(self.config_path))
            self.root = DataHandler(cb_dict).validate(self.root, validation_data)
        except Exception as e:
            raise type(e), type(e)('xml->' + str(e)), sys.exc_info()[2]
        logger.debug2('Config data validated')
Ejemplo n.º 3
0
 def __init__(self, structure):
     assert isinstance(structure, dict)
     self.structure = structure
     cb_dict = get_cb_dict(path_basepath=os.path.curdir)
     self.root = DataHandler(cb_dict).detail(self.structure)