Пример #1
0
 def validate_file(self, name, attrs):
     if not isinstance(name, str):
         raise DFEValidationException('file name must be a string, is {t}: {n}'.
                                      format(t=type(name), n=name))
     if 'path' not in attrs:
         raise DFEValidationException('"path" must be in file attributes of file {n}'.
                                      format(n=name))
Пример #2
0
 def validate_version(self, version):
     if version is None:
         raise DFEValidationException('version must be present')
     elif version not in [1, '1']:
         raise DFEValidationException(
             'version {v} is not understood by this dfe version'.format(v=version)
         )
Пример #3
0
 def validate_config(self, config, name_required=True):
     if not isinstance(config, dict):
         raise DFEValidationException('configuration item must be a mapping, is {t}: {c}'.
                                      format(t=type(config), c=config))
     if name_required and 'name' not in config:
         raise DFEValidationException('name must be present in config entry {c}'.
                                      format(c=config))
     self.validate_name(config.get('name', ''))
     self.validate_tag(config.get('tag', ''))
     self.validate_files(config.get('files', {}))
     self.validate_vars(config.get('vars', {}))
Пример #4
0
 def validate_vars(self, vars):
     if not isinstance(vars, dict):
         raise DFEValidationException('vars must be a dict, is {t}: {v}'.
                                      format(t=type(vars), v=vars))
     for a in ['name', 'tag', 'files']:
         if a in vars:
             raise DFEValidationException(
                 '{a} must not be in vars, it is filled in automatically: {v}'.
                 format(a=a, v=vars)
             )
     for name, value in vars.items():
         if not isinstance(name, str):
             raise DFEValidationException('var name must be a string, is {t}: {n}'.
                                          format(t=type(name), n=name))
Пример #5
0
    def validate_files(self, files):
        if not isinstance(files, dict):
            raise DFEValidationException('files must be a mapping, is {t}: {f}'.
                                         format(t=type(files), f=files))

        for name, attrs in files.items():
            self.validate_file(name, attrs)
Пример #6
0
 def validate_tag(self, tag):
     if not isinstance(tag, str):
         raise DFEValidationException('tag must be a string, is {t}: {g}'.
                                      format(t=type(tag), g=tag))
Пример #7
0
 def validate_name(self, name):
     if not isinstance(name, str):
         raise DFEValidationException('name must be a string, is {t}: {n}'.
                                      format(t=type(name), n=name))
Пример #8
0
 def validate_configurations(self, configurations):
     if not isinstance(configurations, list):
         raise DFEValidationException('configurations must be a list, is {t}'.
                                      format(t=type(configurations)))
     for c in configurations:
         self.validate_config(c)
Пример #9
0
 def validate_defaults(self, defaults):
     if not isinstance(defaults, dict):
         raise DFEValidationException('defaults must be a dict, is {t}'.
                                      format(t=type(defaults)))
     # this is actually just a normal config, except we don't enforce `name` to be here
     self.validate_config(defaults, name_required=False)