1
1
#!/usr/bin/env python3
2
+ # -*- coding: utf-8 -*-
2
3
3
4
# This script manages the use of a file with a unique name, like
4
5
# `Sketch.ino.globals.h`, in the Sketch source directory to provide compiler
@@ -290,18 +291,18 @@ def copy_create_build_file(source_fqfn, build_target_fqfn):
290
291
else :
291
292
# Place holder - Must have an empty file to satisfy parameter list
292
293
# specifications in platform.txt.
293
- with open (build_target_fqfn , 'w' ):
294
+ with open (build_target_fqfn , 'w' , encoding = "utf-8" ):
294
295
pass
295
296
return True # file changed
296
297
297
298
298
299
def add_include_line (build_opt_fqfn , include_fqfn ):
299
300
if not os .path .exists (include_fqfn ):
300
301
# If file is missing, we need an place holder
301
- with open (include_fqfn , 'w' ):
302
+ with open (include_fqfn , 'w' , encoding = "utf-8" ):
302
303
pass
303
304
print ("add_include_line: Created " + include_fqfn )
304
- with open (build_opt_fqfn , 'a' ) as build_opt :
305
+ with open (build_opt_fqfn , 'a' , encoding = "utf-8" ) as build_opt :
305
306
build_opt .write ('-include "' + include_fqfn .replace ('\\ ' , '\\ \\ ' ) + '"\n ' )
306
307
307
308
@@ -313,7 +314,7 @@ def extract_create_build_opt_file(globals_h_fqfn, file_name, build_opt_fqfn):
313
314
"""
314
315
global build_opt_signature
315
316
316
- build_opt = open (build_opt_fqfn , 'w' )
317
+ build_opt = open (build_opt_fqfn , 'w' , encoding = "utf-8" )
317
318
if not os .path .exists (globals_h_fqfn ) or (0 == os .path .getsize (globals_h_fqfn )):
318
319
build_opt .close ()
319
320
return False
@@ -324,7 +325,7 @@ def extract_create_build_opt_file(globals_h_fqfn, file_name, build_opt_fqfn):
324
325
# If the source sketch did not have the file Sketch.ino.globals.h, an empty
325
326
# file was created in the ./core/ folder.
326
327
# By using the copy, open will always succeed.
327
- with open (globals_h_fqfn , 'r' ) as src :
328
+ with open (globals_h_fqfn , 'r' , encoding = "utf-8" ) as src :
328
329
for line in src :
329
330
line = line .strip ()
330
331
line_no += 1
@@ -389,7 +390,7 @@ def enable_override(enable, commonhfile_fqfn):
389
390
return
390
391
elif not enable :
391
392
return
392
- with open (commonhfile_fqfn , 'w' ) as file :
393
+ with open (commonhfile_fqfn , 'w' , encoding = "utf-8" ) as file :
393
394
if enable :
394
395
file .write ("//Override aggressive caching\n " )
395
396
# enable workaround when getsize(commonhfile_fqfn) is non-zero, disabled when zero
@@ -481,7 +482,7 @@ def get_preferences_txt(file_fqfn, key):
481
482
# Get Key Value, key is allowed to be missing.
482
483
# We assume file file_fqfn exists
483
484
basename = os .path .basename (file_fqfn )
484
- with open (file_fqfn ) as file :
485
+ with open (file_fqfn , encoding = "utf-8" ) as file :
485
486
for line in file :
486
487
name , value = line .partition ("=" )[::2 ]
487
488
if name .strip ().lower () == key :
@@ -527,16 +528,16 @@ def check_preferences_txt(runtime_ide_path, preferences_file):
527
528
528
529
529
530
def touch (fname , times = None ):
530
- with open (fname , "a " ) as file :
531
+ with open (fname , "ab " ) as file :
531
532
os .utime (file .fileno (), times )
532
533
533
534
def synchronous_touch (globals_h_fqfn , commonhfile_fqfn ):
534
535
global debug_enabled
535
536
# touch both files with the same timestamp
536
537
touch (globals_h_fqfn )
537
- with open (globals_h_fqfn , 'r' ) as file :
538
+ with open (globals_h_fqfn , "rb" ) as file :
538
539
ts = os .stat (file .fileno ())
539
- with open (commonhfile_fqfn , 'a' ) as file2 :
540
+ with open (commonhfile_fqfn , "ab" ) as file2 :
540
541
os .utime (file2 .fileno (), ns = (ts .st_atime_ns , ts .st_mtime_ns ))
541
542
542
543
if debug_enabled :
0 commit comments