tests_schema = Schema({ Optional(basestring): Or( Or(basestring, [basestring]), { "command": Or(basestring, [basestring]), Optional("requires"): [package_request_schema] } ) }) package_schema = Schema({ Optional("requires_rez_version"): And(basestring, Use(Version)), Required("name"): basestring, Optional("base"): basestring, Optional("version"): Or(basestring, And(Version, Use(str))), Optional('description'): basestring, Optional('authors'): [basestring], Optional('requires'): late_bound([package_request_schema]), Optional('build_requires'): late_bound([package_request_schema]), Optional('private_build_requires'): late_bound([package_request_schema]), # deliberately not possible to late bind Optional('variants'): [[package_request_schema]], Optional('relocatable'): late_bound(Or(None, bool)), Optional('hashed_variants'): bool,
# here we are simulating a resource repository, in reality this might be a # database or filesystem. pets = dict( kitten=dict(obi=dict(colors=["black", "white"], male=True, age=1.0), scully=dict(colors=["tabby"], male=False, age=0.5), mordor=dict(colors=["black"], male=True, age="infinite")), # bad data puppy=dict(taco=dict(colors=["brown"], male=True, age=0.6, owner="joe.bloggs"), ringo=dict(colors=["white", "grey"], male=True, age=0.8))) pet_schema = Schema({ Required("name"): basestring, Required("colors"): And([basestring], Use(set)), Required("male"): bool, Required("age"): float, Optional("owner"): basestring }) class BasePetResource(Resource): schema_error = PetResourceError def __init__(self, variables=None): super(BasePetResource, self).__init__(variables) self.validations = {} # tracks validations
'tools_info', 'excluded_tools', 'has_plugins', 'plugin_for', 'requires', 'build_requires', 'private_build_requires', 'variants', 'commands', 'pre_commands', 'post_commands', 'help', 'config', 'uuid', 'timestamp', 'release_message', 'changelog', 'vcs', 'revision', 'previous_version', 'previous_revision', 'has_plugins', 'plugin_for', 'plugin_launch_commands' ] version_schema = Or(basestring, And(Version, Use(str))) package_request_schema = Or(basestring, And(PackageRequest, Use(str))) source_code_schema = Or(SourceCode, And(basestring, Use(SourceCode))) # package serialisation schema package_serialise_schema = Schema({ Required("name"): basestring, Optional("nice_name"): basestring, Optional("version"): version_schema, Optional("description"): basestring, Optional("authors"): [basestring], Optional("tools"): [basestring], Optional("tools_info"): dict, Optional("excluded_tools"): [basestring], Optional('requires'): [package_request_schema], Optional('build_requires'): [package_request_schema], Optional('private_build_requires'): [package_request_schema],
def late_bound(schema): return Or(SourceCode, schema) # used when 'requires' is late bound late_requires_schema = Schema( [Or(PackageRequest, And(basestring, Use(PackageRequest)))]) # ------------------------------------------------------------------------------ # schema dicts # ------------------------------------------------------------------------------ # requirements of all package-related resources # base_resource_schema_dict = {Required("name"): basestring} # package family # package_family_schema_dict = base_resource_schema_dict.copy() # schema common to both package and variant # tests_schema = Schema({ Optional(basestring): Or( Or(basestring, [basestring]), { "command": Or(basestring, [basestring]),