From 897888db419239f013561b155de5993b1966820e Mon Sep 17 00:00:00 2001 From: jorgemanzo Date: Fri, 4 Oct 2019 23:38:34 -0700 Subject: Add CLI command for flashing a keyboard A new CLI subcommand was added, flash, which behaves very similar to the already present compile CLI comamnd, but with the added ability to target a bootloader. The command is used like so: qmk flash [-h] [-b] [-kb KEYBOARD] [-km KEYMAP] [-bl BOOTLOADER] [filename]. A -kb and -km is expected, or a configurator export JSON filename. A bootloader can be specified using -bl , and if left unspecified, the target is assumed to be :flash. -bl can be used to list the available bootloaders. If -km is provided, but no -kb , then a message is printed suggesting the user to run qmk list_keyboards. --- lib/python/qmk/commands.py | 57 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 lib/python/qmk/commands.py (limited to 'lib/python/qmk/commands.py') diff --git a/lib/python/qmk/commands.py b/lib/python/qmk/commands.py new file mode 100644 index 0000000000..9fbf00f165 --- /dev/null +++ b/lib/python/qmk/commands.py @@ -0,0 +1,57 @@ +"""Functions that build make commands +""" +import json +import qmk.keymap + +def create_make_command(keyboard, keymap, target=None): + """Create a make compile command + + Args: + keyboard + The path of the keyboard, for example 'plank' + + keymap + The name of the keymap, for example 'algernon' + + target + Usually a bootloader. + + Returns: + A command that can be run to make the specified keyboard and keymap + """ + if target is None: + return ['make', ':'.join((keyboard, keymap))] + return ['make', ':'.join((keyboard, keymap, target))] + +def parse_configurator_json(configurator_filename): + """Open and parse a configurator json export + """ + file = open(configurator_filename) + user_keymap = json.load(file) + file.close() + return user_keymap + +def compile_configurator_json(configurator_filename, bootloader=None): + """Convert a configurator export JSON file into a C file + + Args: + configurator_filename + The configurator JSON export file + + bootloader + A bootloader to flash + + Returns: + A command to run to compile and flash the C file. + """ + # Parse the configurator json + user_keymap = parse_configurator_json(configurator_filename) + + # Write the keymap C file + qmk.keymap.write(user_keymap['keyboard'], user_keymap['keymap'], user_keymap['layout'], user_keymap['layers']) + + # Return a command that can be run to make the keymap and flash if given + if bootloader is None: + return create_make_command(user_keymap['keyboard'], user_keymap['keymap']) + return create_make_command(user_keymap['keyboard'], user_keymap['keymap'], bootloader) + -- cgit v1.2.3 From 7891de7f6d64431cedbd580a3f7863533dc8be88 Mon Sep 17 00:00:00 2001 From: QMK Bot Date: Sat, 16 Nov 2019 07:10:19 +0000 Subject: format code according to conventions [skip ci] --- lib/python/qmk/commands.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'lib/python/qmk/commands.py') diff --git a/lib/python/qmk/commands.py b/lib/python/qmk/commands.py index 9fbf00f165..f83a89578e 100644 --- a/lib/python/qmk/commands.py +++ b/lib/python/qmk/commands.py @@ -3,6 +3,7 @@ import json import qmk.keymap + def create_make_command(keyboard, keymap, target=None): """Create a make compile command @@ -23,6 +24,7 @@ def create_make_command(keyboard, keymap, target=None): return ['make', ':'.join((keyboard, keymap))] return ['make', ':'.join((keyboard, keymap, target))] + def parse_configurator_json(configurator_filename): """Open and parse a configurator json export """ @@ -31,6 +33,7 @@ def parse_configurator_json(configurator_filename): file.close() return user_keymap + def compile_configurator_json(configurator_filename, bootloader=None): """Convert a configurator export JSON file into a C file @@ -54,4 +57,3 @@ def compile_configurator_json(configurator_filename, bootloader=None): if bootloader is None: return create_make_command(user_keymap['keyboard'], user_keymap['keymap']) return create_make_command(user_keymap['keyboard'], user_keymap['keymap'], bootloader) - -- cgit v1.2.3