# HG changeset patch # User Jacob Alexander # Date 1424590454 28800 # Node ID 8b82e0ceac05e1206a5818eae115cda983f72236 # Parent 0a2ddc9f2e0bc5d3473f0feb76543dc93e6ee608 Adding backend specific template and output defaults. diff -r 0a2ddc9f2e0b -r 8b82e0ceac05 backends/kiibohd.py --- a/backends/kiibohd.py Sat Feb 21 23:19:35 2015 -0800 +++ b/backends/kiibohd.py Sat Feb 21 23:34:14 2015 -0800 @@ -36,6 +36,10 @@ ### Classes ### class Backend( BackendBase ): + # Default templates and output files + templatePaths = ["templates/kiibohdKeymap.h", "templates/kiibohdDefs.h"] + outputPaths = ["generatedKeymap.h", "kll_defs.h"] + # USB Code Capability Name def usbCodeCapability( self ): return "usbKeyOut"; diff -r 0a2ddc9f2e0b -r 8b82e0ceac05 kll.py --- a/kll.py Sat Feb 21 23:19:35 2015 -0800 +++ b/kll.py Sat Feb 21 23:34:14 2015 -0800 @@ -83,7 +83,8 @@ # Optional Arguments pArgs.add_argument( '-b', '--backend', type=str, default="kiibohd", help="Specify target backend for the KLL compiler.\n" - "Default: kiibohd" ) + "Default: kiibohd\n" + "Options: kiibohd, json" ) pArgs.add_argument( '-d', '--default', type=str, nargs='+', help="Specify .kll files to layer on top of the default map to create a combined map." ) pArgs.add_argument( '-p', '--partial', type=str, nargs='+', action='append', @@ -91,13 +92,11 @@ "Each -p defines another partial map.\n" "Base .kll files (that define the scan code maps) must be defined for each partial map." ) pArgs.add_argument( '-t', '--templates', type=str, nargs='+', - default=["templates/kiibohdKeymap.h", "templates/kiibohdDefs.h"], help="Specify template used to generate the keymap.\n" - "Default: templates/kiibohdKeymap.h templates/kiibohdDefs.h" ) + "Default: " ) pArgs.add_argument( '-o', '--outputs', type=str, nargs='+', - default=["generatedKeymap.h", "kll_defs.h"], help="Specify output file. Writes to current working directory by default.\n" - "Default: generatedKeymap.h kll_defs.h" ) + "Default: " ) pArgs.add_argument( '-h', '--help', action="help", help="This message." ) diff -r 0a2ddc9f2e0b -r 8b82e0ceac05 kll_lib/backends.py --- a/kll_lib/backends.py Sat Feb 21 23:19:35 2015 -0800 +++ b/kll_lib/backends.py Sat Feb 21 23:34:14 2015 -0800 @@ -36,15 +36,22 @@ ### Classes ### class BackendBase: + # Default templates and output files + templatePaths = [] + outputPaths = [] + # Initializes backend # Looks for template file and builds list of fill tags - def __init__( self, templatePaths=[] ): - self.templatePaths = templatePaths + def __init__( self, templatePaths ): + # Use defaults if no template is specified + if templatePaths is not None: + self.templatePaths = templatePaths + self.fill_dict = dict() # Process each template and add to tagList self.tagList = [] - for templatePath in templatePaths: + for templatePath in self.templatePaths: # Does template exist? if not os.path.isfile( templatePath ): print ( "{0} '{1}' does not exist...".format( ERROR, templatePath ) ) @@ -73,6 +80,10 @@ # Generates the output keymap with fill tags filled def generate( self, outputPaths ): + # Use default if not specified + if outputPaths is None: + outputPaths = self.outputPaths + for templatePath, outputPath in zip( self.templatePaths, outputPaths ): # Process each line of the template, outputting to the target path with open( outputPath, 'w' ) as outputFile: