🔨 PowerShell compatibility (#27720)
This commit is contained in:
@@ -16,7 +16,7 @@ def set(file_path, define_name, value):
|
||||
Returns True if the define was found and replaced, False otherwise.
|
||||
'''
|
||||
# Read the contents of the file
|
||||
with open(file_path, 'r') as f:
|
||||
with open(file_path, 'r', encoding='utf-8') as f:
|
||||
content = f.readlines()
|
||||
|
||||
modified = False
|
||||
@@ -32,7 +32,7 @@ def set(file_path, define_name, value):
|
||||
|
||||
# Write the modified content back to the file only if changes were made
|
||||
if modified:
|
||||
with open(file_path, 'w') as f:
|
||||
with open(file_path, 'w', encoding='utf-8') as f:
|
||||
f.writelines(content)
|
||||
return True
|
||||
|
||||
@@ -42,7 +42,7 @@ def add(file_path, define_name, value=""):
|
||||
'''
|
||||
Insert a define on the first blank line in a file.
|
||||
'''
|
||||
with open(file_path, 'r') as f:
|
||||
with open(file_path, 'r', encoding='utf-8') as f:
|
||||
content = f.readlines()
|
||||
|
||||
# Prepend a space to the value if it's not empty
|
||||
@@ -59,7 +59,7 @@ def add(file_path, define_name, value=""):
|
||||
# If no blank line is found, append to the end
|
||||
content.append(f"#define {define_name}{value}\n")
|
||||
|
||||
with open(file_path, 'w') as f:
|
||||
with open(file_path, 'w', encoding='utf-8') as f:
|
||||
f.writelines(content)
|
||||
|
||||
def enable(file_path, define_name, enable=True):
|
||||
@@ -68,7 +68,7 @@ def enable(file_path, define_name, enable=True):
|
||||
Returns True if the define was found, False otherwise.
|
||||
'''
|
||||
# Read the contents of the file
|
||||
with open(file_path, 'r') as f:
|
||||
with open(file_path, 'r', encoding='utf-8') as f:
|
||||
content = f.readlines()
|
||||
|
||||
# Prepare the regex
|
||||
@@ -96,7 +96,7 @@ def enable(file_path, define_name, enable=True):
|
||||
|
||||
# Write the modified content back to the file only if changes were made
|
||||
if modified:
|
||||
with open(file_path, 'w') as f:
|
||||
with open(file_path, 'w', encoding='utf-8') as f:
|
||||
f.writelines(content)
|
||||
|
||||
return found
|
||||
|
||||
@@ -25,7 +25,7 @@ def report_version(conf):
|
||||
print(k + ': ' + v)
|
||||
|
||||
def write_opt_file(conf, outpath='Marlin/apply_config.sh'):
|
||||
with open(outpath, 'w') as outfile:
|
||||
with open(outpath, 'w', encoding='utf-8') as outfile:
|
||||
for key, val in conf.items():
|
||||
if key in ('__INITIAL_HASH', 'VERSION'): continue
|
||||
|
||||
@@ -49,7 +49,7 @@ def write_opt_file(conf, outpath='Marlin/apply_config.sh'):
|
||||
def back_up_config(name):
|
||||
# Back up the existing file before modifying it
|
||||
conf_path = 'Marlin/' + name
|
||||
with open(conf_path, 'r') as f:
|
||||
with open(conf_path, 'r', encoding='utf-8') as f:
|
||||
# Write a filename.bak#.ext retaining the original extension
|
||||
parts = conf_path.split('.')
|
||||
nr = ''
|
||||
@@ -59,7 +59,7 @@ def back_up_config(name):
|
||||
nr = 1 if nr == '' else nr + 1
|
||||
continue
|
||||
|
||||
with open(bak_path, 'w') as b:
|
||||
with open(bak_path, 'w', encoding='utf-8') as b:
|
||||
b.writelines(f.readlines())
|
||||
break
|
||||
|
||||
@@ -83,7 +83,7 @@ def main():
|
||||
args = parser.parse_args()
|
||||
|
||||
try:
|
||||
infile = open(args.config_file, 'r')
|
||||
infile = open(args.config_file, 'r', encoding='utf-8')
|
||||
except:
|
||||
print(f'No {args.config_file} found.')
|
||||
sys.exit(1)
|
||||
|
||||
@@ -78,7 +78,7 @@ if pioutil.is_pio_build():
|
||||
modified_text = text.replace("BOTH(", "ALL(").replace("EITHER(", "ANY(")
|
||||
if text != modified_text:
|
||||
conf_modified = True
|
||||
with open(conf_path, 'w') as file:
|
||||
with open(conf_path, 'w', encoding="utf8") as file:
|
||||
file.write(modified_text)
|
||||
|
||||
if conf_modified:
|
||||
|
||||
@@ -70,7 +70,7 @@ def group_options(schema):
|
||||
def load_boards():
|
||||
bpath = Path("Marlin/src/core/boards.h")
|
||||
if bpath.is_file():
|
||||
with bpath.open() as bfile:
|
||||
with bpath.open(encoding='utf-8') as bfile:
|
||||
boards = []
|
||||
for line in bfile:
|
||||
if line.startswith("#define BOARD_"):
|
||||
|
||||
Reference in New Issue
Block a user