Yaml file class
| 140 | |
| 141 | |
| 142 | class YamlFile: |
| 143 | """Yaml file class""" |
| 144 | |
| 145 | def __init__(self, path): |
| 146 | self._path = path |
| 147 | with open(path) as yaml_file: |
| 148 | self.data = yaml.safe_load(yaml_file) |
| 149 | self.validate() |
| 150 | |
| 151 | def validate(self): |
| 152 | # print('Validating ' + str(self._path.replace('\\', '/').split('/')[-1:][0])) |
| 153 | if self.data is None: |
| 154 | print('\n[ERROR] File: ' + self._path) |
| 155 | print("This file has no data:") |
| 156 | exit(0) |
| 157 | for module in self.data: |
| 158 | if 'module_name' in module and module['module_name'] is None: |
| 159 | print('\n[ERROR] File: ' + self._path) |
| 160 | print("'module_name' is empty in:") |
| 161 | exit(0) |
| 162 | if 'classes' in module: |
| 163 | if not module['classes']: |
| 164 | print('\n[ERROR] File: ' + self._path) |
| 165 | print("'classes' is empty in:") |
| 166 | exit(0) |
| 167 | for cl in module['classes']: |
| 168 | if 'class_name' in cl and cl['class_name'] is None: |
| 169 | print('\n[ERROR] File: ' + self._path) |
| 170 | print("'class_name' is empty in:") |
| 171 | exit(0) |
| 172 | if 'instance_variables' in cl and cl['instance_variables']: |
| 173 | for iv in cl['instance_variables']: |
| 174 | if 'var_name' not in iv: |
| 175 | print('\n[ERROR] File: ' + self._path) |
| 176 | print("'var_name' not found inside 'instance_variables' of class: " + cl['class_name']) |
| 177 | exit(0) |
| 178 | if 'var_name' in iv and iv['var_name'] is None: |
| 179 | print('\n[ERROR] File: ' + self._path) |
| 180 | print("'var_name' is empty in:") |
| 181 | exit(0) |
| 182 | if 'methods' in cl and cl['methods']: |
| 183 | for met in cl['methods']: |
| 184 | if 'def_name' not in met: |
| 185 | print('\n[ERROR] File: ' + self._path) |
| 186 | print("'def_name' not found inside 'methods' of class: " + cl['class_name']) |
| 187 | exit(0) |
| 188 | if 'def_name' in met and met['def_name'] is None: |
| 189 | print('\n[ERROR] File: ' + self._path) |
| 190 | print("'def_name' is empty in:") |
| 191 | exit(0) |
| 192 | if 'params' in met and met['params']: |
| 193 | for param in met['params']: |
| 194 | if 'param_name' not in param: |
| 195 | print('\n[ERROR] File: ' + self._path) |
| 196 | print("'param_name' not found inside 'params' of class: " + cl['class_name']) |
| 197 | exit(0) |
| 198 | if 'param_name' in param and param['param_name'] is None: |
| 199 | print('\n[ERROR] File: ' + self._path) |