Created
February 20, 2015 11:00
-
-
Save mithrandi/cde58f5d4d1f88b8b331 to your computer and use it in GitHub Desktop.
Axiom legacy declaration generator
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/env python | |
from twisted.python.reflect import namedAny | |
template = """ | |
declareLegacyItem( | |
typeName=%r, | |
schemaVersion=%d, | |
attributes=dict( | |
%s)) | |
""" | |
def legacyItemCode(itemClass): | |
def _d(value): | |
if value is None: | |
return '' | |
return ', default=%r' % (value) | |
calculatedAttributes = ',\n '.join( | |
['%s=%s(allowNone=%r%s)' % (k, v.__class__.__name__, v.allowNone, _d(v.default)) | |
for k, v in itemClass.getSchema()]) | |
fmt = template % (itemClass.typeName, itemClass.schemaVersion, | |
calculatedAttributes) | |
return fmt | |
if __name__ == '__main__': | |
import sys | |
f = sys.stdout | |
f.write(legacyItemCode(namedAny(sys.argv[1]))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment