ConfigurationChecker.py 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. class NoSynapeName(Exception):
  2. pass
  3. class NoSynapeNeurons(Exception):
  4. pass
  5. class NoSynapeSignals(Exception):
  6. pass
  7. class NoValidSignal(Exception):
  8. pass
  9. class NoEventID(Exception):
  10. pass
  11. class NoEventPeriod(Exception):
  12. pass
  13. class MultipleSameSynapseName(Exception):
  14. pass
  15. class ConfigurationChecker:
  16. def __init__(self):
  17. pass
  18. @staticmethod
  19. def check_synape_dict(synape_dict):
  20. if 'name' not in synape_dict:
  21. raise NoSynapeName("The Synapse does not have a name: %s" % synape_dict)
  22. if 'neurons' not in synape_dict:
  23. raise NoSynapeNeurons("The Synapse does not have neurons: %s" % synape_dict)
  24. if 'signals' not in synape_dict:
  25. raise NoSynapeSignals("The Synapse does not have signals: %s" % synape_dict)
  26. return True
  27. @staticmethod
  28. def check_neuron_dict(neuron_dict):
  29. # TODO check that the Neuron plugin exist
  30. return True
  31. @staticmethod
  32. def check_signal_dict(signal_dict):
  33. if ('event' not in signal_dict) and ('order' not in signal_dict):
  34. raise NoValidSignal("The signal is not an event or an order %s" % signal_dict)
  35. return True
  36. @staticmethod
  37. def check_event_dict(event_dict):
  38. # if 'id' not in event_dict:
  39. # raise NoEventID("Event must contain a unique ID: %s" % event_dict)
  40. if 'period' not in event_dict:
  41. raise NoEventPeriod("Event must contain a period: %s" % event_dict)
  42. return True
  43. @staticmethod
  44. def check_order_dict(order_dict):
  45. if order_dict is not None:
  46. return True
  47. return False
  48. @staticmethod
  49. def check_synapes(synapses_list):
  50. """
  51. Check the synapse list is ok. No double same name
  52. :param synapses_list:
  53. :type synapses_list: list of Synapse
  54. :return:
  55. """
  56. seen = set()
  57. for synapse in synapses_list:
  58. if synapse.name in seen:
  59. raise MultipleSameSynapseName("Synapse with same name: %s" % synapse.name)
  60. seen.add(synapse.name)
  61. return True