🔧 Update config.ini script
This commit is contained in:
parent
61d1ce7d2e
commit
a9c476c55e
@ -18,7 +18,16 @@ def apply_opt(name, val, conf=None):
|
|||||||
if name == "lcd": name, val = val, "on"
|
if name == "lcd": name, val = val, "on"
|
||||||
|
|
||||||
# Create a regex to match the option and capture parts of the line
|
# Create a regex to match the option and capture parts of the line
|
||||||
regex = re.compile(rf'^(\s*)(//\s*)?(#define\s+)({name}\b)(\s*)(.*?)(\s*)(//.*)?$', re.IGNORECASE)
|
# 1: Indentation
|
||||||
|
# 2: Comment
|
||||||
|
# 3: #define and whitespace
|
||||||
|
# 4: Option name
|
||||||
|
# 5: First space after name
|
||||||
|
# 6: Remaining spaces between name and value
|
||||||
|
# 7: Option value
|
||||||
|
# 8: Whitespace after value
|
||||||
|
# 9: End comment
|
||||||
|
regex = re.compile(rf'^(\s*)(//\s*)?(#define\s+)({name}\b)(\s?)(\s*)(.*?)(\s*)(//.*)?$', re.IGNORECASE)
|
||||||
|
|
||||||
# Find and enable and/or update all matches
|
# Find and enable and/or update all matches
|
||||||
for file in ("Configuration.h", "Configuration_adv.h"):
|
for file in ("Configuration.h", "Configuration_adv.h"):
|
||||||
@ -37,10 +46,11 @@ def apply_opt(name, val, conf=None):
|
|||||||
newline = re.sub(r'^(\s*)(#define)(\s{1,3})?(\s*)', r'\1//\2 \4', line)
|
newline = re.sub(r'^(\s*)(#define)(\s{1,3})?(\s*)', r'\1//\2 \4', line)
|
||||||
else:
|
else:
|
||||||
# For options with values, enable and set the value
|
# For options with values, enable and set the value
|
||||||
newline = match[1] + match[3] + match[4] + match[5] + val
|
addsp = '' if match[5] else ' '
|
||||||
if match[8]:
|
newline = match[1] + match[3] + match[4] + match[5] + addsp + val + match[6]
|
||||||
sp = match[7] if match[7] else ' '
|
if match[9]:
|
||||||
newline += sp + match[8]
|
sp = match[8] if match[8] else ' '
|
||||||
|
newline += sp + match[9]
|
||||||
lines[i] = newline
|
lines[i] = newline
|
||||||
blab(f"Set {name} to {val}")
|
blab(f"Set {name} to {val}")
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user