KLL Compiler
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.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

emitters.py 2.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. #!/usr/bin/env python3
  2. '''
  3. KLL Emitters Container Classes
  4. '''
  5. # Copyright (C) 2016 by Jacob Alexander
  6. #
  7. # This file is free software: you can redistribute it and/or modify
  8. # it under the terms of the GNU General Public License as published by
  9. # the Free Software Foundation, either version 3 of the License, or
  10. # (at your option) any later version.
  11. #
  12. # This file is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. # GNU General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU General Public License
  18. # along with this file. If not, see <http://www.gnu.org/licenses/>.
  19. ### Imports ###
  20. import emitters.kiibohd.kiibohd as kiibohd
  21. import emitters.kll.kll as kll
  22. import emitters.none.none as none
  23. ### Decorators ###
  24. ## Print Decorator Variables
  25. ERROR = '\033[5;1;31mERROR\033[0m:'
  26. WARNING = '\033[5;1;33mWARNING\033[0m:'
  27. ### Classes ###
  28. class Emitters:
  29. '''
  30. Container class for KLL emitters
  31. NOTES: To add a new emitter
  32. - Add a new directory for your emitter (e.g. kiibohd)
  33. - Add at least two files in this directory (<name>.py and __init__.py)
  34. - In <name>.py have one class that inherits the Emitter class from common.emitter
  35. - Add to list of emitters below
  36. - Add import statement to the top of this file
  37. - The control object allows access to the entire set of KLL datastructures
  38. '''
  39. def __init__( self, control ):
  40. '''
  41. Emitter initialization
  42. @param control: ControlStage object, used to access data from other stages
  43. '''
  44. # Default emitter
  45. self.default = "kiibohd"
  46. # Dictionary of Emitters
  47. self.emitters = {
  48. 'kiibohd' : kiibohd.Kiibohd( control ),
  49. 'kll' : kll.KLL( control ),
  50. 'none' : none.Drop( control )
  51. }
  52. def emitter_default( self ):
  53. '''
  54. Returns string name of default emitter
  55. '''
  56. return self.default
  57. def emitter_list( self ):
  58. '''
  59. List of emitters available
  60. '''
  61. return list( self.emitters.keys() )
  62. def emitter( self, emitter ):
  63. '''
  64. Returns an emitter object
  65. '''
  66. return self.emitters[ emitter ]
  67. def command_line_args( self, args ):
  68. '''
  69. Group parser fan-out for emitter command line arguments
  70. @param args: Name space of processed arguments
  71. '''
  72. # Always process command line args in the same order
  73. for key, emitter in sorted( self.emitters.items(), key=lambda x: x[0] ):
  74. emitter.command_line_args( args )
  75. def command_line_flags( self, parser ):
  76. '''
  77. Group parser fan-out for emitter for command line options
  78. @param parser: argparse setup object
  79. '''
  80. # Always process command line flags in the same order
  81. for key, emitter in sorted( self.emitters.items(), key=lambda x: x[0] ):
  82. emitter.command_line_flags( parser )