abstract_printer.py 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. import abc
  2. from slither.utils import output
  3. class IncorrectPrinterInitialization(Exception):
  4. pass
  5. class AbstractPrinter(metaclass=abc.ABCMeta):
  6. ARGUMENT = "" # run the printer with slither.py --ARGUMENT
  7. HELP = "" # help information
  8. WIKI = ""
  9. def __init__(self, slither, logger):
  10. self.slither = slither
  11. self.contracts = slither.contracts
  12. self.filename = slither.filename
  13. self.logger = logger
  14. if not self.HELP:
  15. raise IncorrectPrinterInitialization(
  16. "HELP is not initialized {}".format(self.__class__.__name__)
  17. )
  18. if not self.ARGUMENT:
  19. raise IncorrectPrinterInitialization(
  20. "ARGUMENT is not initialized {}".format(self.__class__.__name__)
  21. )
  22. if not self.WIKI:
  23. raise IncorrectPrinterInitialization(
  24. "WIKI is not initialized {}".format(self.__class__.__name__)
  25. )
  26. def info(self, info):
  27. if self.logger:
  28. self.logger.info(info)
  29. def generate_output(self, info, additional_fields=None):
  30. if additional_fields is None:
  31. additional_fields = {}
  32. printer_output = output.Output(info, additional_fields)
  33. printer_output.data["printer"] = self.ARGUMENT
  34. return printer_output
  35. @abc.abstractmethod
  36. def output(self, filename):
  37. """TODO Documentation"""
  38. return