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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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.none.none as none
  22. ### Decorators ###
  23. ## Print Decorator Variables
  24. ERROR = '\033[5;1;31mERROR\033[0m:'
  25. WARNING = '\033[5;1;33mWARNING\033[0m:'
  26. ### Classes ###
  27. class Emitters:
  28. '''
  29. Container class for KLL emitters
  30. NOTES: To add a new emitter
  31. - Add a new directory for your emitter (e.g. kiibohd)
  32. - Add at least two files in this directory (<name>.py and __init__.py)
  33. - In <name>.py have one class that inherits the Emitter class from common.emitter
  34. - Add to list of emitters below
  35. - Add import statement to the top of this file
  36. - The control object allows access to the entire set of KLL datastructures
  37. '''
  38. def __init__( self, control ):
  39. '''
  40. Emitter initialization
  41. @param control: ControlStage object, used to access data from other stages
  42. '''
  43. # Default emitter
  44. self.default = "kiibohd"
  45. # Dictionary of Emitters
  46. self.emitters = {
  47. 'kiibohd' : kiibohd.Kiibohd( control ),
  48. 'none' : none.Drop( control )
  49. }
  50. def emitter_default( self ):
  51. '''
  52. Returns string name of default emitter
  53. '''
  54. return self.default
  55. def emitter_list( self ):
  56. '''
  57. List of emitters available
  58. '''
  59. return list( self.emitters.keys() )
  60. def emitter( self, emitter ):
  61. '''
  62. Returns an emitter object
  63. '''
  64. return self.emitters[ emitter ]
  65. def command_line_args( self, args ):
  66. '''
  67. Group parser fan-out for emitter command line arguments
  68. @param args: Name space of processed arguments
  69. '''
  70. # Always process command line args in the same order
  71. for key, emitter in sorted( self.emitters.items(), key=lambda x: x[0] ):
  72. emitter.command_line_args( args )
  73. def command_line_flags( self, parser ):
  74. '''
  75. Group parser fan-out for emitter for command line options
  76. @param parser: argparse setup object
  77. '''
  78. # Always process command line flags in the same order
  79. for key, emitter in sorted( self.emitters.items(), key=lambda x: x[0] ):
  80. emitter.command_line_flags( parser )