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/layouts.py | |
parent | 417f08911507307906f1dfbdb45d9d3a81232576 (diff) |
[CLI] Add common util for dumping generated content (#16674)
Diffstat (limited to 'lib/python/qmk/cli/generate/layouts.py')
-rwxr-xr-x | lib/python/qmk/cli/generate/layouts.py | 19 |
1 files changed, 4 insertions, 15 deletions
diff --git a/lib/python/qmk/cli/generate/layouts.py b/lib/python/qmk/cli/generate/layouts.py index a21311bd49..193633baf6 100755 --- a/lib/python/qmk/cli/generate/layouts.py +++ b/lib/python/qmk/cli/generate/layouts.py @@ -2,11 +2,12 @@ """ from milc import cli -from qmk.constants import COL_LETTERS, ROW_LETTERS +from qmk.constants import COL_LETTERS, ROW_LETTERS, GPL2_HEADER_C_LIKE, GENERATED_HEADER_C_LIKE from qmk.decorators import automagic_keyboard, automagic_keymap from qmk.info import info_json from qmk.keyboard import keyboard_completer, keyboard_folder from qmk.path import is_keyboard, normpath +from qmk.commands import dump_lines usb_properties = { 'vid': 'VENDOR_ID', @@ -38,7 +39,7 @@ def generate_layouts(cli): kb_info_json = info_json(cli.config.generate_layouts.keyboard) # Build the layouts.h file. - layouts_h_lines = ['/* This file was generated by `qmk generate-layouts`. Do not edit or copy.', ' */', '', '#pragma once'] + layouts_h_lines = [GPL2_HEADER_C_LIKE, GENERATED_HEADER_C_LIKE, '#pragma once'] if 'matrix_size' not in kb_info_json: cli.log.error('%s: Invalid matrix config.', cli.config.generate_layouts.keyboard) @@ -86,16 +87,4 @@ def generate_layouts(cli): layouts_h_lines.append('#endif') # Show the results - layouts_h = '\n'.join(layouts_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(layouts_h) - - if not cli.args.quiet: - cli.log.info('Wrote info_config.h to %s.', cli.args.output) - - else: - print(layouts_h) + dump_lines(cli.args.output, layouts_h_lines, cli.args.quiet) |