diff options
author | jorgemanzo <jmanzo203689@gmail.com> | 2019-10-04 23:38:34 -0700 |
---|---|---|
committer | skullY <skullydazed@gmail.com> | 2019-11-15 23:06:07 -0800 |
commit | 897888db419239f013561b155de5993b1966820e (patch) | |
tree | dc9041ea683d9188961749aec7f511719fbde241 /lib/python/qmk/commands.py | |
parent | 4f5b34af565d00e069d3f37b3faa8091608ed21f (diff) | |
download | qmk_firmware-897888db419239f013561b155de5993b1966820e.tar.gz qmk_firmware-897888db419239f013561b155de5993b1966820e.zip |
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 <keyboard> and -km <keymap> is expected, or a configurator export JSON filename. A bootloader can be specified using -bl <target>, and if left unspecified, the target is assumed to be :flash. -bl can be used to list the available bootloaders.
If -km <keymap> is provided, but no -kb <keyboard>, then a message is printed suggesting the user to run qmk list_keyboards.
Diffstat (limited to 'lib/python/qmk/commands.py')
-rw-r--r-- | lib/python/qmk/commands.py | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/lib/python/qmk/commands.py b/lib/python/qmk/commands.py new file mode 100644 index 000000000..9fbf00f16 --- /dev/null +++ b/lib/python/qmk/commands.py | |||
@@ -0,0 +1,57 @@ | |||
1 | """Functions that build make commands | ||
2 | """ | ||
3 | import json | ||
4 | import qmk.keymap | ||
5 | |||
6 | def create_make_command(keyboard, keymap, target=None): | ||
7 | """Create a make compile command | ||
8 | |||
9 | Args: | ||
10 | keyboard | ||
11 | The path of the keyboard, for example 'plank' | ||
12 | |||
13 | keymap | ||
14 | The name of the keymap, for example 'algernon' | ||
15 | |||
16 | target | ||
17 | Usually a bootloader. | ||
18 | |||
19 | Returns: | ||
20 | A command that can be run to make the specified keyboard and keymap | ||
21 | """ | ||
22 | if target is None: | ||
23 | return ['make', ':'.join((keyboard, keymap))] | ||
24 | return ['make', ':'.join((keyboard, keymap, target))] | ||
25 | |||
26 | def parse_configurator_json(configurator_filename): | ||
27 | """Open and parse a configurator json export | ||
28 | """ | ||
29 | file = open(configurator_filename) | ||
30 | user_keymap = json.load(file) | ||
31 | file.close() | ||
32 | return user_keymap | ||
33 | |||
34 | def compile_configurator_json(configurator_filename, bootloader=None): | ||
35 | """Convert a configurator export JSON file into a C file | ||
36 | |||
37 | Args: | ||
38 | configurator_filename | ||
39 | The configurator JSON export file | ||
40 | |||
41 | bootloader | ||
42 | A bootloader to flash | ||
43 | |||
44 | Returns: | ||
45 | A command to run to compile and flash the C file. | ||
46 | """ | ||
47 | # Parse the configurator json | ||
48 | user_keymap = parse_configurator_json(configurator_filename) | ||
49 | |||
50 | # Write the keymap C file | ||
51 | qmk.keymap.write(user_keymap['keyboard'], user_keymap['keymap'], user_keymap['layout'], user_keymap['layers']) | ||
52 | |||
53 | # Return a command that can be run to make the keymap and flash if given | ||
54 | if bootloader is None: | ||
55 | return create_make_command(user_keymap['keyboard'], user_keymap['keymap']) | ||
56 | return create_make_command(user_keymap['keyboard'], user_keymap['keymap'], bootloader) | ||
57 | |||