You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

79 lines
1.7 KiB

  1. '''
  2. Validates that the json has meaningful keys
  3. '''
  4. import itertools
  5. a = {
  6. 'required' : [
  7. {
  8. 'component': 'TextField',
  9. 'data': {
  10. 'display_name': 'filename',
  11. 'help_text': 'path to file you want to process',
  12. 'command_args': ['-f', '--infile']
  13. }
  14. },
  15. {
  16. 'component': 'FileChooser',
  17. 'data': {
  18. 'display_name': 'Output Location',
  19. 'help_text': 'Where to save the file',
  20. 'command_args': ['-o', '--outfile']
  21. }
  22. }
  23. ],
  24. 'optional' : [
  25. {
  26. 'component': 'RadioGroup',
  27. 'data': [
  28. {
  29. 'display_name': 'Output Location',
  30. 'help_text': 'Where to save the file',
  31. 'command_args': ['-o', '--outfile']
  32. }, {
  33. 'display_name': 'Output Location',
  34. 'help_text': 'Where to save the file',
  35. 'command_args': ['-o', '--outfile']
  36. }
  37. ]
  38. }
  39. ]
  40. }
  41. VALID_WIDGETS = (
  42. 'FileChooser',
  43. 'DirChooser',
  44. 'DateChooser',
  45. 'TextField',
  46. 'Dropdown',
  47. 'Counter',
  48. 'RadioGroup'
  49. )
  50. class MalformedBuildSpecException(Exception):
  51. pass
  52. def validate(json_string):
  53. required = json_string.get('required')
  54. optional = json_string.get('optional')
  55. if not required or not optional:
  56. raise MalformedBuildSpecException("All objects must be children of 'required,' or 'optional'")
  57. objects = [item for key in json_string for item in json_string[key]]
  58. for obj in objects:
  59. if obj['component'] not in VALID_WIDGETS:
  60. raise MalformedBuildSpecException("Invalid Component name: {0}".format(obj['component']))
  61. if __name__ == '__main__':
  62. validate(a)