Hi all,

Yesterday I emailed Kirill Simonov, the creator of PyYAML, to get help to
parse Puppet YAML file.

He gladly helped with the following code. This code is for parsing Puppet
log, but I'm sure you can modify it to parse other Puppet YAML file.

The idea is to create the correct loader for the Ruby object, then PyYAML
can read the data after that.

Here goes the code:

#!/usr/bin/env python

import yaml

def construct_ruby_object(loader, suffix, node):

    return loader.construct_yaml_map(node)

def construct_ruby_sym(loader, node):

    return loader.construct_yaml_str(node)

yaml.add_multi_constructor(u"!ruby/object:", construct_ruby_object)

yaml.add_constructor(u"!ruby/sym", construct_ruby_sym)


stream = file('201203130939.yaml','r')

mydata = yaml.load(stream)
print mydata



-- 
Sharuzzaman Ahmat Raslan

-- 
You received this message because you are subscribed to the Google Groups 
"Puppet Users" group.
To post to this group, send email to puppet-users@googlegroups.com.
To unsubscribe from this group, send email to 
puppet-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/puppet-users?hl=en.

Reply via email to