28
28
import sys
29
29
import shutil
30
30
import hashlib
31
- import logging
32
31
import threading
33
32
from contextlib import suppress
34
33
from os .path import join , exists , isabs , splitdrive , commonpath , relpath
52
51
"esp-idf-size" : ">=1.6.1"
53
52
}
54
53
55
-
56
- def setup_logging ():
57
- """Setup logging with optional file output"""
58
- handlers = [logging .StreamHandler ()]
59
-
60
- # Only add file handler if writable and not disabled
61
- log_file = os .environ .get ('ARDUINO_FRAMEWORK_LOG_FILE' )
62
- if log_file :
63
- with suppress (OSError , PermissionError ):
64
- handlers .append (logging .FileHandler (log_file ))
65
-
66
- logging .basicConfig (
67
- level = logging .INFO ,
68
- format = '%(asctime)s - %(levelname)s - %(message)s' ,
69
- handlers = handlers
70
- )
71
-
72
-
73
- # Only setup logging if enabled via environment variable
74
- if os .environ .get ('ARDUINO_FRAMEWORK_ENABLE_LOGGING' ):
75
- setup_logging ()
76
-
77
54
# Constants for better performance
78
55
UNICORE_FLAGS = {
79
56
"CORE32SOLO1" ,
@@ -118,12 +95,6 @@ def get_platform_default_threshold(mcu):
118
95
119
96
default_value = platform_defaults .get (mcu , 31600 )
120
97
121
- # Debug output only in verbose mode
122
- if logging .getLogger ().isEnabledFor (logging .DEBUG ):
123
- logging .debug (
124
- f"Max. possible platform default threshold for { mcu } : "
125
- f"{ default_value } " )
126
-
127
98
return default_value
128
99
129
100
@@ -182,7 +153,7 @@ def validate_threshold(threshold, mcu):
182
153
print ("*** Consider using higher values for maximum performance ***" )
183
154
184
155
if original_threshold != threshold :
185
- logging . warning (f"Threshold adjusted from { original_threshold } to "
156
+ print (f"Threshold adjusted from { original_threshold } to "
186
157
f"max. possible value { threshold } for { mcu } " )
187
158
188
159
return threshold
@@ -413,7 +384,6 @@ def safe_delete_file(file_path: Union[str, Path],
413
384
try :
414
385
# Check existence
415
386
if not file_path .exists ():
416
- logging .warning (f"File does not exist: { file_path } " )
417
387
return False
418
388
419
389
# Remove write protection if necessary
@@ -422,14 +392,11 @@ def safe_delete_file(file_path: Union[str, Path],
422
392
423
393
# Delete file
424
394
file_path .unlink ()
425
- logging .info (f"File deleted: { file_path } " )
426
395
return True
427
396
428
397
except PermissionError :
429
- logging .error (f"No permission to delete: { file_path } " )
430
398
return False
431
399
except Exception as e :
432
- logging .error (f"Error deleting { file_path } : { e } " )
433
400
return False
434
401
435
402
@@ -441,15 +408,12 @@ def safe_delete_directory(dir_path: Union[str, Path]) -> bool:
441
408
442
409
try :
443
410
if not dir_path .exists ():
444
- logging .warning (f"Directory does not exist: { dir_path } " )
445
411
return False
446
412
447
413
shutil .rmtree (dir_path )
448
- logging .info (f"Directory deleted: { dir_path } " )
449
414
return True
450
415
451
416
except Exception as e :
452
- logging .error (f"Error deleting { dir_path } : { e } " )
453
417
return False
454
418
455
419
@@ -484,7 +448,6 @@ def validate_platformio_path(path: Union[str, Path]) -> bool:
484
448
return not any (critical in path_str for critical in critical_paths )
485
449
486
450
except Exception as e :
487
- logging .error (f"Path validation error: { e } " )
488
451
return False
489
452
490
453
@@ -519,23 +482,15 @@ def validate_deletion_path(path: Union[str, Path],
519
482
normalized_critical = critical .resolve ()
520
483
if (normalized_path == normalized_critical or
521
484
normalized_critical in normalized_path .parents ):
522
- logging .error (f"Critical system path detected: { path } " )
523
485
return False
524
486
except (OSError , ValueError ):
525
487
# Path comparison failed, reject for safety
526
- logging .error (f"Path comparison failed for: { path } " )
527
488
return False
528
489
529
490
# Check against allowed patterns
530
491
path_str = str (path )
531
492
is_allowed = any (pattern in path_str for pattern in allowed_patterns )
532
493
533
- if not is_allowed :
534
- logging .error (f"Path does not match allowed patterns: { path } " )
535
- logging .error (f"Allowed patterns: { allowed_patterns } " )
536
- else :
537
- logging .info (f"Path validation successful: { path } " )
538
-
539
494
return is_allowed
540
495
541
496
@@ -545,41 +500,17 @@ def safe_framework_cleanup():
545
500
546
501
# Framework directory cleanup
547
502
if exists (FRAMEWORK_DIR ):
548
- logging .info (f"Attempting to validate framework path: "
549
- f"{ FRAMEWORK_DIR } " )
550
-
551
503
if validate_platformio_path (FRAMEWORK_DIR ):
552
- logging .info (f"Framework path validated successfully: "
553
- f"{ FRAMEWORK_DIR } " )
554
-
555
- if safe_delete_directory (FRAMEWORK_DIR ):
556
- print ("Framework successfully removed" )
557
- else :
504
+ if not safe_delete_directory (FRAMEWORK_DIR ):
558
505
print ("Error removing framework" )
559
506
success = False
560
- else :
561
- logging .error (f"PlatformIO path validation failed: "
562
- f"{ FRAMEWORK_DIR } " )
563
- success = False
564
507
565
508
# Framework libs directory cleanup
566
509
if exists (FRAMEWORK_LIB_DIR ):
567
- logging .info (f"Attempting to validate framework lib path: "
568
- f"{ FRAMEWORK_LIB_DIR } " )
569
-
570
510
if validate_platformio_path (FRAMEWORK_LIB_DIR ):
571
- logging .info (f"Framework lib path validated successfully: "
572
- f"{ FRAMEWORK_LIB_DIR } " )
573
-
574
- if safe_delete_directory (FRAMEWORK_LIB_DIR ):
575
- print ("Framework libs successfully removed" )
576
- else :
511
+ if not safe_delete_directory (FRAMEWORK_LIB_DIR ):
577
512
print ("Error removing framework libs" )
578
513
success = False
579
- else :
580
- logging .error (f"PlatformIO path validation failed: "
581
- f"{ FRAMEWORK_LIB_DIR } " )
582
- success = False
583
514
584
515
return success
585
516
@@ -1012,7 +943,7 @@ def get_frameworks_in_current_env():
1012
943
call_compile_libs ()
1013
944
flag_custom_sdkconfig = False
1014
945
else :
1015
- logging . error ("Framework cleanup failed - installation aborted" )
946
+ print ("Framework cleanup failed - installation aborted" )
1016
947
sys .exit (1 )
1017
948
1018
949
if flag_custom_sdkconfig and not flag_any_custom_sdkconfig :
0 commit comments