Fix develop (#12039)
Fixes file encoding errors on Windows, and layouts not correctly merging into info.json. * force utf8 encoding * correctly merge layouts and layout aliases * show what aliases point to
This commit is contained in:
parent
23ed6c4ec0
commit
1581ea48dc
10 changed files with 66 additions and 32 deletions
|
@ -40,7 +40,7 @@ file_header = """\
|
|||
|
||||
|
||||
def collect_defines(filepath):
|
||||
with open(filepath, 'r') as f:
|
||||
with open(filepath, 'r', encoding='utf-8') as f:
|
||||
content = f.read()
|
||||
define_search = re.compile(r'(?m)^#\s*define\s+(?:.*\\\r?\n)*.*$', re.MULTILINE)
|
||||
value_search = re.compile(r'^#\s*define\s+(?P<name>[a-zA-Z0-9_]+(\([^\)]*\))?)\s*(?P<value>.*)', re.DOTALL)
|
||||
|
@ -146,17 +146,17 @@ def chibios_confmigrate(cli):
|
|||
if cli.args.input.name == "chconf.h" and ("CHCONF_H" in input_defs["dict"] or "_CHCONF_H_" in input_defs["dict"] or cli.args.force):
|
||||
migrate_chconf_h(to_override, outfile=sys.stdout)
|
||||
if cli.args.overwrite:
|
||||
with open(cli.args.input, "w") as out_file:
|
||||
with open(cli.args.input, "w", encoding='utf-8') as out_file:
|
||||
migrate_chconf_h(to_override, outfile=out_file)
|
||||
|
||||
elif cli.args.input.name == "halconf.h" and ("HALCONF_H" in input_defs["dict"] or "_HALCONF_H_" in input_defs["dict"] or cli.args.force):
|
||||
migrate_halconf_h(to_override, outfile=sys.stdout)
|
||||
if cli.args.overwrite:
|
||||
with open(cli.args.input, "w") as out_file:
|
||||
with open(cli.args.input, "w", encoding='utf-8') as out_file:
|
||||
migrate_halconf_h(to_override, outfile=out_file)
|
||||
|
||||
elif cli.args.input.name == "mcuconf.h" and ("MCUCONF_H" in input_defs["dict"] or "_MCUCONF_H_" in input_defs["dict"] or cli.args.force):
|
||||
migrate_mcuconf_h(to_override, outfile=sys.stdout)
|
||||
if cli.args.overwrite:
|
||||
with open(cli.args.input, "w") as out_file:
|
||||
with open(cli.args.input, "w", encoding='utf-8') as out_file:
|
||||
migrate_mcuconf_h(to_override, outfile=out_file)
|
||||
|
|
|
@ -82,6 +82,10 @@ def generate_layouts(cli):
|
|||
layouts_h_lines.append(rows)
|
||||
layouts_h_lines.append('}')
|
||||
|
||||
for alias, target in kb_info_json.get('layout_aliases', {}).items():
|
||||
layouts_h_lines.append('')
|
||||
layouts_h_lines.append('#define %s %s' % (alias, target))
|
||||
|
||||
# Show the results
|
||||
layouts_h = '\n'.join(layouts_h_lines) + '\n'
|
||||
|
||||
|
|
|
@ -29,7 +29,7 @@ def show_keymap(kb_info_json, title_caps=True):
|
|||
else:
|
||||
cli.echo('{fg_blue}keymap_%s{fg_reset}:', cli.config.info.keymap)
|
||||
|
||||
keymap_data = json.load(keymap_path.open())
|
||||
keymap_data = json.load(keymap_path.open(encoding='utf-8'))
|
||||
layout_name = keymap_data['layout']
|
||||
|
||||
for layer_num, layer in enumerate(keymap_data['layers']):
|
||||
|
@ -57,7 +57,7 @@ def show_matrix(kb_info_json, title_caps=True):
|
|||
# Build our label list
|
||||
labels = []
|
||||
for key in layout['layout']:
|
||||
if key['matrix']:
|
||||
if 'matrix' in key:
|
||||
row = ROW_LETTERS[key['matrix'][0]]
|
||||
col = COL_LETTERS[key['matrix'][1]]
|
||||
|
||||
|
@ -91,6 +91,9 @@ def print_friendly_output(kb_info_json):
|
|||
cli.echo('{fg_blue}Size{fg_reset}: %s x %s' % (kb_info_json['width'], kb_info_json['height']))
|
||||
cli.echo('{fg_blue}Processor{fg_reset}: %s', kb_info_json.get('processor', 'Unknown'))
|
||||
cli.echo('{fg_blue}Bootloader{fg_reset}: %s', kb_info_json.get('bootloader', 'Unknown'))
|
||||
if 'layout_aliases' in kb_info_json:
|
||||
aliases = [f'{key}={value}' for key, value in kb_info_json['layout_aliases'].items()]
|
||||
cli.echo('{fg_blue}Layout aliases:{fg_reset} %s' % (', '.join(aliases),))
|
||||
|
||||
if cli.config.info.layouts:
|
||||
show_layouts(kb_info_json, True)
|
||||
|
|
|
@ -27,7 +27,7 @@ def kle2json(cli):
|
|||
cli.log.error('File {fg_cyan}%s{style_reset_all} was not found.', file_path)
|
||||
return False
|
||||
out_path = file_path.parent
|
||||
raw_code = file_path.open().read()
|
||||
raw_code = file_path.read_text(encoding='utf-8')
|
||||
# Check if info.json exists, allow overwrite with force
|
||||
if Path(out_path, "info.json").exists() and not cli.args.force:
|
||||
cli.log.error('File {fg_cyan}%s/info.json{style_reset_all} already exists, use -f or --force to overwrite.', out_path)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue