From e5823b56501598c39d3f57719cf32f344212ede6 Mon Sep 17 00:00:00 2001 From: Joel Challis Date: Fri, 18 Mar 2022 01:09:29 +0000 Subject: [CLI] Add common util for dumping generated content (#16674) --- lib/python/qmk/cli/generate/keyboard_h.py | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) (limited to 'lib/python/qmk/cli/generate/keyboard_h.py') 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(".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) -- cgit v1.2.1