Python yaml.YAMLObject() Examples

The following are 8 code examples of yaml.YAMLObject(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module yaml , or try the search function .
Example #1
Source File: config.py    From wfrog with GNU General Public License v3.0 6 votes vote down vote up
def get_help_desc(self, module, summary=False):
        self.logger.debug("Getting info on module '"+module.__name__+"'")
        elements = inspect.getmembers(module, lambda l : inspect.isclass(l) and yaml.YAMLObject in inspect.getmro(l))
        desc={}
        for element in elements:
            self.logger.debug("Getting doc of "+element[0])
            # Gets the documentation of the first superclass
            superclass = inspect.getmro(element[1])[1]
            fulldoc=superclass.__doc__

            # Add the doc of the super-super-class if _element_doc is
            if hasattr(inspect.getmro(superclass)[1], "_element_doc") and inspect.getmro(superclass)[1].__doc__  is not None:
                fulldoc = fulldoc + inspect.getmro(superclass)[1].__doc__

            firstline=fulldoc.split(".")[0]
            self.logger.debug(firstline)

            module_name = module.__name__.split('.')[-1]

            if summary:
                desc[element[1].yaml_tag] = [ firstline, module_name ]
            else:
                desc[element[1].yaml_tag] = [ fulldoc, module_name ]
        return desc 
Example #2
Source File: tests.py    From yacs with Apache License 2.0 5 votes vote down vote up
def test_load_cfg_invalid_type(self):
        class CustomClass(yaml.YAMLObject):
            """A custom class that yaml.safe_load can load."""

            yaml_loader = yaml.SafeLoader
            yaml_tag = u"!CustomClass"

        # FOO.BAR.QUUX will have type CustomClass, which is not allowed
        cfg_string = "FOO:\n BAR:\n  QUUX: !CustomClass {}"
        with self.assertRaises(AssertionError):
            yacs.config.load_cfg(cfg_string) 
Example #3
Source File: vividict.py    From RAFCON with Eclipse Public License 1.0 5 votes vote down vote up
def to_yaml(cls, dumper, vividict):
        """Implementation for the abstract method of the base class YAMLObject
        """
        dictionary = cls.vividict_to_dict(vividict, native_strings=True)
        node = dumper.represent_mapping(cls.yaml_tag, dictionary)
        return node 
Example #4
Source File: vividict.py    From RAFCON with Eclipse Public License 1.0 5 votes vote down vote up
def from_yaml(cls, loader, node):
        """Implementation for the abstract method of the base class YAMLObject
        """
        dict_representation = loader.construct_mapping(node, deep=True)
        vividict = cls.from_dict(dict_representation)
        return vividict 
Example #5
Source File: menu_loader.py    From mGui with MIT License 5 votes vote down vote up
def __new__(cls):
        res = yaml.YAMLObject.__new__(cls)
        setattr(res, 'key', 'Menu_Proxy')
        setattr(res, 'label', '')
        setattr(res, 'items', [])
        setattr(res, 'after', None)
        setattr(res, 'options', {})
        setattr(res, 'preMenuCommand', None)
        setattr(res, 'postMenuCommand', '')
        return res 
Example #6
Source File: menu_loader.py    From mGui with MIT License 5 votes vote down vote up
def __new__(cls):
        res = yaml.YAMLObject.__new__(cls)
        setattr(res, 'key', 'Menu_Proxy')
        setattr(res, 'label', '')
        setattr(res, 'items', [])
        setattr(res, 'options', {})
        setattr(res, 'preMenuCommand', None)
        setattr(res, 'postMenuCommand', '')
        return res 
Example #7
Source File: menu_loader.py    From mGui with MIT License 5 votes vote down vote up
def __new__(cls):
        res = yaml.YAMLObject.__new__(cls)
        setattr(res, 'items', [])
        setattr(res, 'options', {})
        return res 
Example #8
Source File: setup.py    From wfrog with GNU General Public License v3.0 5 votes vote down vote up
def setup_settings(self, settings_def_file, source_file, target_file):
        self.logger.debug('Current settings file: '+str(source_file))
        self.logger.debug('New settings file:'+target_file)
        defs = yaml.load( file(settings_def_file, 'r') )
        if source_file is not None:
            source = yaml.load( file(source_file, 'r') )
        else:
            source = {}
        target = {}
        try:
            os.makedirs(os.path.dirname(target_file))
        except:
            pass
            
        # First question is about the station
        section = {}
        section['name'] = "station"
        section['description'] = "Station information"
        section['type'] = 'dict'
        question = {}
        question['name'] = "driver"
        question['description'] = "the driver for your station model"
        question['type'] = 'choice'
        question['default'] = 'none'
        question['choices'] = {}
        section['children'] =[question]
        
        stations = inspect.getmembers(wfdriver.station, lambda l : inspect.isclass(l) and yaml.YAMLObject in inspect.getmro(l))
        for station in stations:
            station_class = station[1]
            if hasattr(station_class,('name')):
                question['choices'][str(station_class.yaml_tag)[1:]] = station_class.name
        
        defs.insert(0,section)        
            
        self.welcome(target_file)
        self.recurse_create(defs, source, target)
        yaml.dump(target, file(target_file, 'w'), default_flow_style=False)
        self.bye()
        return target_file