🔨 Python config helpers (#27483)
This commit is contained in:
+18
-33
@@ -1,36 +1,21 @@
|
||||
#!/usr/bin/env bash
|
||||
#!/usr/bin/env python
|
||||
|
||||
# exit on first failure
|
||||
set -e
|
||||
import sys, os,config
|
||||
|
||||
# Get SED_CMD, SED_I, and the BSDSED flag
|
||||
. $(dirname $0)/opt_sed
|
||||
def main():
|
||||
args = sys.argv[1:]
|
||||
|
||||
for opt in "$@" ; do
|
||||
DID=0 ; FOUND=0
|
||||
for FN in Marlin/Configuration.h Marlin/Configuration_adv.h; do
|
||||
if [[ $BSDSED ]]; then
|
||||
# BSD sed version (macOS)
|
||||
"${SED_CMD}" "${SED_I[@]}" \
|
||||
"/^[[:space:]]*#define[[:space:]]+${opt}\b/{
|
||||
s/^[[:space:]]*\(#define[[:space:]]+${opt}\b.*\)/\/\/\1/
|
||||
h
|
||||
\$b end
|
||||
}
|
||||
\$!b
|
||||
:end
|
||||
x
|
||||
/./{ x; q0; }
|
||||
x
|
||||
q1" \
|
||||
$FN && DID=1
|
||||
else
|
||||
# GNU sed version
|
||||
"${SED_CMD}" "${SED_I[@]}" \
|
||||
"/^\(\s*\)\(#define\s\+${opt}\b\s\?\)\(\s\s\)\?/{s//\1\/\/\2/;h};\${x;/./{x;q0};x;q1}" \
|
||||
$FN && DID=1
|
||||
fi
|
||||
((DID||FOUND)) || { grep -E "^\s*\/\/#define\s+${opt}\b" $FN >/dev/null && FOUND=1 ; }
|
||||
done
|
||||
((DID||FOUND)) || (echo "ERROR: $(basename $0) Can't find ${opt}" >&2 && exit 9)
|
||||
done
|
||||
for name in args:
|
||||
changed = False
|
||||
|
||||
for file in config.FILES:
|
||||
if os.path.exists(file):
|
||||
if config.enable(file, name, False):
|
||||
changed = True
|
||||
|
||||
if not changed:
|
||||
print(f"ERROR: Can't find {name}")
|
||||
exit(1)
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
||||
Reference in New Issue
Block a user