diff options
author | Joel Challis <git@zvecr.com> | 2022-03-18 01:09:29 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-03-18 01:09:29 +0000 |
commit | e5823b56501598c39d3f57719cf32f344212ede6 (patch) | |
tree | 8ce1045f22e40d8f7b739894d52e66d11afbeb11 /lib/python/qmk/cli/generate/keyboard_h.py | |
parent | 417f08911507307906f1dfbdb45d9d3a81232576 (diff) | |
download | qmk_firmware-e5823b56501598c39d3f57719cf32f344212ede6.tar.gz qmk_firmware-e5823b56501598c39d3f57719cf32f344212ede6.zip |
[CLI] Add common util for dumping generated content (#16674)
Diffstat (limited to 'lib/python/qmk/cli/generate/keyboard_h.py')
-rwxr-xr-x | lib/python/qmk/cli/generate/keyboard_h.py | 18 |
1 files changed, 4 insertions, 14 deletions
diff --git a/lib/python/qmk/cli/generate/keyboard_h.py b/lib/python/qmk/cli/generate/keyboard_h.py index f05178cede..2058865cbf 100755 --- a/lib/python/qmk/cli/generate/keyboard_h.py +++ b/lib/python/qmk/cli/generate/keyboard_h.py @@ -3,8 +3,10 @@ from milc import cli from qmk.info import info_json +from qmk.commands import dump_lines from qmk.keyboard import keyboard_completer, keyboard_folder from qmk.path import normpath +from qmk.constants import GPL2_HEADER_C_LIKE, GENERATED_HEADER_C_LIKE def would_populate_layout_h(keyboard): @@ -36,22 +38,10 @@ def generate_keyboard_h(cli): has_layout_h = would_populate_layout_h(cli.args.keyboard) # Build the layouts.h file. - keyboard_h_lines = ['/* This file was generated by `qmk generate-keyboard-h`. Do not edit or copy.', ' */', '', '#pragma once', '#include "quantum.h"'] + keyboard_h_lines = [GPL2_HEADER_C_LIKE, GENERATED_HEADER_C_LIKE, '#pragma once', '#include "quantum.h"'] if not has_layout_h: keyboard_h_lines.append('#pragma error("<keyboard>.h is only optional for data driven keyboards - kb.h == bad times")') # Show the results - keyboard_h = '\n'.join(keyboard_h_lines) + '\n' - - if cli.args.output: - cli.args.output.parent.mkdir(parents=True, exist_ok=True) - if cli.args.output.exists(): - cli.args.output.replace(cli.args.output.parent / (cli.args.output.name + '.bak')) - cli.args.output.write_text(keyboard_h) - - if not cli.args.quiet: - cli.log.info('Wrote keyboard_h to %s.', cli.args.output) - - else: - print(keyboard_h) + dump_lines(cli.args.output, keyboard_h_lines, cli.args.quiet) |