Last active
December 15, 2015 11:09
-
-
Save segfault87/5251202 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import Rx | |
import yaml | |
import sys | |
PREFIXES = ['base', 'stage', 'npc'] | |
SCHEMAS = [ | |
'/base/amount', | |
'/base/color', | |
'/base/num_or_null', | |
'/base/duration', | |
'/base/score', | |
'/stage/level', | |
'/stage/stage', | |
'/stage/stages', | |
'/npc/action', | |
'/npc/state', | |
'/npc/npc', | |
'/npc/npcs', | |
] | |
rx = Rx.Factory({ "register_core_types": True }); | |
def load_yaml(name): | |
if not name.startswith('/'): | |
name = '/%s' % name | |
return yaml.load(open('schemas%s.yml' % name).read()) | |
documents = [(key, load_yaml(key)) for key in SCHEMAS] | |
documents_dict = dict(documents) | |
[rx.add_prefix(name, '/%s/' % name) for name in PREFIXES] | |
[rx.learn_type(k, v) for (k, v) in documents] | |
if len(sys.argv) < 2: | |
print 'usage: %s [target-schema]' % sys.argv[0] | |
sys.exit(1) | |
target_schema = rx.make_schema(documents_dict[sys.argv[1]]) | |
document = yaml.load(sys.stdin.read()) | |
if target_schema.check(document): | |
print 'passed.' | |
else: | |
print 'did not pass.' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment