Created
September 2, 2010 21:14
-
-
Save eevans/562964 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
from simplejson import loads | |
schema = loads(open('cassandra.avpr').read()) | |
print """ | |
class MissingFieldException(Exception): | |
pass | |
""" | |
for record in schema['types']: | |
if not record['type'] == 'record': | |
continue | |
print "class %s(dict):" % record['name'] | |
print " def __init__(self, **kwargs):" | |
for field in record['fields']: | |
if not isinstance(field['type'], list): | |
print " if not kwargs.has_key('%s'):" % field['name'] | |
print " raise MissingFieldException('%s')" % field['name'] | |
print " self['%s'] = kwargs.get('%s', None)" % (field['name'], field['name']) | |
print " def __setattr__(self, name, value):" | |
print " self[name] = value" | |
print " def __getattr__(self, name):" | |
print " return self[name]" | |
# vi:ai sw=4 ts=4 et |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment