🎨 Adjust some Python formatting (#27649)

This commit is contained in:
Andrew 2025-01-23 20:48:58 -05:00 committed by GitHub
parent 861dd33fa1
commit 0a598071af
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 25 additions and 15 deletions

View file

@ -12,7 +12,7 @@ if pioutil.is_pio_build():
accumulating_xor_value = seed
for i in range(0, len(contents), 4):
value = struct.unpack('<I', contents[ i : i + 4])[0]
value = struct.unpack("<I", contents[i : i + 4])[0]
accumulating_xor_value = accumulating_xor_value ^ value
return accumulating_xor_value
@ -29,8 +29,8 @@ if pioutil.is_pio_build():
# This is the block counter
block_number = xor_seed * block_number
#load the xor key from the file
r7 = file_key
# load the xor key from the file
r7 = file_key
for loop_counter in range(0, block_size):
# meant to make sure different bits of the key are used.
@ -54,10 +54,10 @@ if pioutil.is_pio_build():
# and then with IP
xor_seed = xor_seed ^ ip
#Now store the byte back
# Now store the byte back
r1[loop_counter] = xor_seed & 0xFF
#increment the loop_counter
# increment the loop_counter
loop_counter = loop_counter + 1
def encrypt_file(input, output_file, file_length):
@ -82,15 +82,15 @@ if pioutil.is_pio_build():
# write the file_key
output_file.write(struct.pack("<I", file_key))
#TODO - how to enforce that the firmware aligns to block boundaries?
# TODO: - how to enforce that the firmware aligns to block boundaries?
block_count = len(input_file) // block_size
print ("Block Count is ", block_count)
print("Block Count is ", block_count)
for block_number in range(0, block_count):
block_offset = (block_number * block_size)
block_offset = block_number * block_size
block_end = block_offset + block_size
block_array = bytearray(input_file[block_offset: block_end])
block_array = bytearray(input_file[block_offset:block_end])
xor_block(block_array, block_array, block_number, block_size, file_key)
for n in range (0, block_size):
for n in range(0, block_size):
input_file[block_offset + n] = block_array[n]
# update the expected CRC value.

View file

@ -41,7 +41,7 @@ if pioutil.is_pio_build():
except:
print("Can't detect PlatformIO Version")
def blab(str,level=1):
def blab(str, level=1):
if verbose >= level:
print("[deps] %s" % str)
@ -206,6 +206,7 @@ if pioutil.is_pio_build():
else:
blab("Added src file %s " % relp, 3)
cur_srcs.add(relp)
# Special rule: If a direct folder is specified add all files within.
fullplain = os.path.join(marlinbasedir, plain)
if os.path.isdir(fullplain):
@ -218,6 +219,7 @@ if pioutil.is_pio_build():
def srepl(matchi):
g0 = matchi.group(0)
return r"**" + g0[1:]
gpattern = re.sub(r'[*]($|[^*])', srepl, plain)
gpattern = os.path.join(marlinbasedir, gpattern)
@ -230,14 +232,17 @@ if pioutil.is_pio_build():
blab("Removed src file %s (%s)" % (relp, str(info)), 3)
else:
blab("Removed src file %s " % relp, 3)
fullplain = os.path.join(marlinbasedir, plain)
if os.path.isdir(fullplain):
blab("Directory content removal for %s " % plain, 2)
def filt(x):
common = os.path.commonpath([plain, x])
if not common == os.path.normpath(plain): return True
onremove(x, "dcr")
return False
cur_srcs = set(filter(filt, cur_srcs))
else:
# Remove matching source entries.
@ -245,6 +250,7 @@ if pioutil.is_pio_build():
if not fnmatch.fnmatch(x, plain): return True
onremove(x)
return False
cur_srcs = set(filter(filt, cur_srcs))
# Transform the resulting set into a string.
for x in cur_srcs:

View file

@ -28,7 +28,10 @@ def apply_opt(name, val, conf=None):
# 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)
regex = re.compile(
rf"^(\s*)(//\s*)?(#define\s+)({name}\b)(\s?)(\s*)(.*?)(\s*)(//.*)?$",
re.IGNORECASE
)
# Find and enable and/or update all matches
for file in ("Configuration.h", "Configuration_adv.h"):

View file

@ -15,6 +15,7 @@ def blab(str):
# Invoke GCC to run the preprocessor and extract enabled features
#
preprocessor_cache = {}
def run_preprocessor(env, fn=None):
filename = fn or 'buildroot/share/PlatformIO/scripts/common-dependencies.h'
if filename in preprocessor_cache:

View file

@ -12,11 +12,11 @@ def logmsg(msg, line):
# Print a formatted error
def err(board, msg):
print(f'[ERROR] {board:30} {msg}')
print(f"[ERROR] {board:30} {msg}")
# Print a formatted warning
def warn(board, msg):
print(f'[WARNING] {board:30} {msg}')
print(f"[WARNING] {board:30} {msg}")
def bshort(board):
return board.replace('BOARD_', '')
@ -119,7 +119,7 @@ def boards_checks(argv):
print(f'[ERROR] Non-matching boards order in pins.h. Expected {bshort(boards_boards[i])} but got {bshort(pins_boards[i])}')
break
return ERRS;
return ERRS
if __name__ == '__main__':
ERR_COUNT = boards_checks(sys.argv[1:])