From 97b5ef9c8ca73de3cc51d97977438dd949890346 Mon Sep 17 00:00:00 2001 From: Ryan Jarvis Date: Tue, 5 Feb 2019 15:43:13 -0800 Subject: [PATCH] Make string formatting consistent --- code/memanalyzer.py | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/code/memanalyzer.py b/code/memanalyzer.py index 2d849cc1..ddd6a788 100644 --- a/code/memanalyzer.py +++ b/code/memanalyzer.py @@ -56,7 +56,7 @@ def file_size(file): def analyse_memory(elf_file): - command = "%s -t '%s'" % (objdump_binary, elf_file) + command = "{} -t '{}'".format(objdump_binary, elf_file) response = subprocess.check_output(shlex.split(command)) if isinstance(response, bytes): response = response.decode('utf-8') @@ -67,8 +67,8 @@ def analyse_memory(elf_file): ret = {} for (id_, _) in list(sections.items()): - section_start_token = " _%s_start" % id_ - section_end_token = " _%s_end" % id_ + section_start_token = " _{}_start".format(id_) + section_end_token = " _{}_end".format(id_) section_start = -1 section_end = -1 for line in lines: @@ -93,9 +93,9 @@ def analyse_memory(elf_file): # print("{0: >10}|{1: >30}|{2:12X}|{3:12X}|{4:8}".format(id_, descr, section_start, section_end, section_length)) # i += 1 - # print("Total Used RAM : %d" % usedRAM) - # print("Free RAM : %d" % (TOTAL_DRAM - usedRAM)) - # print("Free IRam : %d" % usedIRAM) + # print("Total Used RAM : {:d}".format(usedRAM)) + # print("Free RAM : {:d}".format(TOTAL_DRAM - usedRAM)) + # print("Free IRam : {:d}".format(usedIRAM)) return ret @@ -103,7 +103,7 @@ def run(env_, modules_): flags = "" for item in modules_.items(): flags += "-D%s_SUPPORT=%d " % item - command = "ESPURNA_BOARD=\"WEMOS_D1_MINI_RELAYSHIELD\" ESPURNA_FLAGS=\"%s\" platformio run --silent --environment %s 2>/dev/null" % (flags, env_) + command = "ESPURNA_BOARD=\"WEMOS_D1_MINI_RELAYSHIELD\" ESPURNA_FLAGS=\"{}\" platformio run --silent --environment {} 2>/dev/null".format(flags, env_) subprocess.check_call(command, shell=True) @@ -164,7 +164,7 @@ if __name__ == '__main__': # Check test modules exist for module in test_modules: if module not in available_modules: - print("Module %s not found" % module) + print("Module {} not found".format(module)) sys.exit(2) # Define base configuration @@ -177,9 +177,9 @@ if __name__ == '__main__': # Show init message if len(test_modules) > 0: - print("Analyzing module(s) %s on top of %s configuration\n" % (", ".join(test_modules), "CORE" if args.core > 0 else "DEFAULT")) + print("Analyzing module(s) {} on top of {} configuration\n".format(", ".join(test_modules), "CORE" if args.core > 0 else "DEFAULT")) else: - print("Analyzing %s configuration\n" % ("CORE" if args.core > 0 else "DEFAULT")) + print("Analyzing {} configuration\n".format("CORE" if args.core > 0 else "DEFAULT")) output_format = "{:<20}|{:<15}|{:<15}|{:<15}|{:<15}|{:<15}|{:<15}|{:<15}" print(output_format.format( @@ -215,8 +215,8 @@ if __name__ == '__main__': # Build the core without modules to get base memory usage run(env, modules) - base = analyse_memory(".pioenvs/%s/firmware.elf" % env) - base['size'] = file_size(".pioenvs/%s/firmware.bin" % env) + base = analyse_memory(".pioenvs/{}/firmware.elf".format(env)) + base['size'] = file_size(".pioenvs/{}/firmware.bin".format(env)) calc_free(base) print(output_format.format( "CORE" if args.core == 1 else "DEFAULT", @@ -235,8 +235,8 @@ if __name__ == '__main__': modules[module] = 1 run(env, modules) - results[module] = analyse_memory(".pioenvs/%s/firmware.elf" % env) - results[module]['size'] = file_size(".pioenvs/%s/firmware.bin" % env) + results[module] = analyse_memory(".pioenvs/{}/firmware.elf".format(env)) + results[module]['size'] = file_size(".pioenvs/{}/firmware.bin".format(env)) calc_free(results[module]) modules[module] = 0 @@ -257,8 +257,8 @@ if __name__ == '__main__': for module in test_modules: modules[module] = 1 run(env, modules) - total = analyse_memory(".pioenvs/%s/firmware.elf" % env) - total['size'] = file_size(".pioenvs/%s/firmware.bin" % env) + total = analyse_memory(".pioenvs/{}/firmware.elf".format(env)) + total['size'] = file_size(".pioenvs/{}/firmware.bin".format(env)) calc_free(total) if len(test_modules) > 1: