mirror of
https://github.com/MarlinFirmware/Marlin.git
synced 2025-07-18 20:27:55 -06:00
🧑💻 Python scripts cleanup, improve (#27533)
This commit is contained in:
parent
8d864d797a
commit
a7bd35b993
19 changed files with 37 additions and 56 deletions
|
@ -11,7 +11,7 @@
|
|||
# been extended to evaluate conditions and can determine what options are actually enabled, not just which
|
||||
# options are uncommented. That will be migrated to this script for standalone migration.
|
||||
#
|
||||
import re,json
|
||||
import re, json
|
||||
from pathlib import Path
|
||||
|
||||
def extend_dict(d:dict, k:tuple):
|
||||
|
@ -120,8 +120,6 @@ def extract_files(filekey):
|
|||
defgrep = re.compile(r'^(//)?\s*(#define)\s+([A-Za-z0-9_]+)\s*(.*?)\s*(//.+)?$')
|
||||
# Pattern to match a float value
|
||||
flt = r'[-+]?\s*(\d+\.|\d*\.\d+)([eE][-+]?\d+)?[fF]?'
|
||||
# Defines to ignore
|
||||
ignore = ('CONFIGURATION_H_VERSION', 'CONFIGURATION_ADV_H_VERSION', 'CONFIG_EXAMPLES_DIR', 'CONFIG_EXPORT')
|
||||
# Start with unknown state
|
||||
state = Parse.NORMAL
|
||||
# Serial ID
|
||||
|
@ -138,7 +136,7 @@ def extract_files(filekey):
|
|||
eol_options = False # The options came from end of line, so only apply once
|
||||
join_line = False # A flag that the line should be joined with the previous one
|
||||
line = '' # A line buffer to handle \ continuation
|
||||
last_added_ref = None # Reference to the last added item
|
||||
last_added_ref = {} # Reference to the last added item
|
||||
# Loop through the lines in the file
|
||||
for the_line in fileobj.readlines():
|
||||
line_number += 1
|
||||
|
@ -175,7 +173,8 @@ def extract_files(filekey):
|
|||
comment_buff = []
|
||||
if cline != '':
|
||||
# A (block or slash) comment was already added
|
||||
cfield = 'notes' if 'comment' in last_added_ref else 'comment'
|
||||
if 'comment' in last_added_ref:
|
||||
cfield = 'notes'
|
||||
last_added_ref[cfield] = cline
|
||||
|
||||
#
|
||||
|
@ -220,7 +219,6 @@ def extract_files(filekey):
|
|||
# Temperature sensors are done
|
||||
if state == Parse.GET_SENSORS:
|
||||
options_json = f'[ {options_json[:-2]} ]'
|
||||
|
||||
state = Parse.NORMAL
|
||||
|
||||
# Strip the leading '* ' from block comments
|
||||
|
@ -230,7 +228,7 @@ def extract_files(filekey):
|
|||
if state == Parse.GET_SENSORS:
|
||||
sens = re.match(r'^(-?\d+)\s*:\s*(.+)$', cline)
|
||||
if sens:
|
||||
s2 = sens[2].replace("'","''")
|
||||
s2 = sens[2].replace("'", "''")
|
||||
options_json += f"{sens[1]}:'{sens[1]} - {s2}', "
|
||||
|
||||
elif state == Parse.BLOCK_COMMENT:
|
||||
|
@ -255,12 +253,11 @@ def extract_files(filekey):
|
|||
comment_buff = []
|
||||
state = Parse.BLOCK_COMMENT
|
||||
eol_options = False
|
||||
|
||||
elif cpos2 != -1 and (cpos2 < cpos1 or cpos1 == -1):
|
||||
cpos = cpos2
|
||||
|
||||
# Comment after a define may be continued on the following lines
|
||||
if defmatch != None and cpos > 10:
|
||||
if defmatch is not None and cpos > 10:
|
||||
state = Parse.EOL_COMMENT
|
||||
prev_comment = '\n'.join(comment_buff)
|
||||
comment_buff = []
|
||||
|
@ -327,10 +324,10 @@ def extract_files(filekey):
|
|||
conditions.append([ f'!defined({line[7:].strip()})' ])
|
||||
|
||||
# Handle a complete #define line
|
||||
elif defmatch != None:
|
||||
elif defmatch is not None:
|
||||
|
||||
# Get the match groups into vars
|
||||
enabled, define_name, val = defmatch[1] == None, defmatch[3], defmatch[4]
|
||||
enabled, define_name, val = defmatch[1] is None, defmatch[3], defmatch[4]
|
||||
|
||||
# Increment the serial ID
|
||||
sid += 1
|
||||
|
@ -375,7 +372,7 @@ def extract_files(filekey):
|
|||
|
||||
# If the comment_buff is not empty, add the comment to the info
|
||||
if comment_buff:
|
||||
full_comment = '\n'.join(comment_buff)
|
||||
full_comment = '\n'.join(comment_buff).strip()
|
||||
|
||||
# An EOL comment will be added later
|
||||
# The handling could go here instead of above
|
||||
|
@ -392,6 +389,14 @@ def extract_files(filekey):
|
|||
if units == 's' or units == 'sec': units = 'seconds'
|
||||
define_info['units'] = units
|
||||
|
||||
if 'comment' not in define_info or define_info['comment'] == '':
|
||||
if prev_comment:
|
||||
define_info['comment'] = prev_comment
|
||||
prev_comment = ''
|
||||
|
||||
if 'comment' in define_info and define_info['comment'] == '':
|
||||
del define_info['comment']
|
||||
|
||||
# Set the options for the current #define
|
||||
if define_name == "MOTHERBOARD" and boards != '':
|
||||
define_info['options'] = boards
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue