Unverified Commit 4098c53f authored by Lucas Saavedra Vaz's avatar Lucas Saavedra Vaz Committed by GitHub

fix(get.py): Add version checking for installed tools (#10160)

* fix(get.py): Add version checking of installed tools

* change(tools): Push generated binaries to PR

* Fix for different file formats

* change(tools): Push generated binaries to PR

* fix paths

* change(tools): Push generated binaries to PR

* Move to using checksum

* change(tools): Push generated binaries to PR

* Clean code

* change(tools): Push generated binaries to PR

* Add checksum check for libs

* change(tools): Push generated binaries to PR

* ci(pre-commit): Apply automatic fixes

* change(tools): Push generated binaries to PR

---------
Co-authored-by: default avatargithub-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: default avatarpre-commit-ci-lite[bot] <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com>
parent c7ac06c8
No preview for this file type
...@@ -147,7 +147,36 @@ def verify_files(filename, destination, rename_to): ...@@ -147,7 +147,36 @@ def verify_files(filename, destination, rename_to):
return True return True
def unpack(filename, destination, force_extract): # noqa: C901 def is_latest_version(destination, dirname, rename_to, cfile, checksum):
current_version = None
expected_version = None
try:
expected_version = checksum
with open(os.path.join(destination, rename_to, ".package_checksum"), "r") as f:
current_version = f.read()
if verbose:
print(f"\nTool: {rename_to}")
print(f"Current version: {current_version}")
print(f"Expected version: {expected_version}")
if current_version and current_version == expected_version:
if verbose:
print("Latest version already installed. Skipping extraction")
return True
if verbose:
print("New version detected")
except Exception as e:
if verbose:
print(f"Falied to verify version for {rename_to}: {e}")
return False
def unpack(filename, destination, force_extract, checksum): # noqa: C901
dirname = "" dirname = ""
cfile = None # Compressed file cfile = None # Compressed file
file_is_corrupted = False file_is_corrupted = False
...@@ -196,11 +225,11 @@ def unpack(filename, destination, force_extract): # noqa: C901 ...@@ -196,11 +225,11 @@ def unpack(filename, destination, force_extract): # noqa: C901
rename_to = "esp32-arduino-libs" rename_to = "esp32-arduino-libs"
if not force_extract: if not force_extract:
if verify_files(filename, destination, rename_to): if is_latest_version(destination, dirname, rename_to, cfile, checksum):
print(" Files ok. Skipping Extraction") if verify_files(filename, destination, rename_to):
return True print(" Files ok. Skipping Extraction")
else: return True
print(" Extracting archive...") print(" Extracting archive...")
else: else:
print(" Forcing extraction") print(" Forcing extraction")
...@@ -225,6 +254,9 @@ def unpack(filename, destination, force_extract): # noqa: C901 ...@@ -225,6 +254,9 @@ def unpack(filename, destination, force_extract): # noqa: C901
shutil.rmtree(rename_to) shutil.rmtree(rename_to)
shutil.move(dirname, rename_to) shutil.move(dirname, rename_to)
with open(os.path.join(destination, rename_to, ".package_checksum"), "w") as f:
f.write(checksum)
if verify_files(filename, destination, rename_to): if verify_files(filename, destination, rename_to):
print(" Files extracted successfully.") print(" Files extracted successfully.")
return True return True
...@@ -324,11 +356,11 @@ def get_tool(tool, force_download, force_extract): ...@@ -324,11 +356,11 @@ def get_tool(tool, force_download, force_extract):
print("Tool {0} already downloaded".format(archive_name)) print("Tool {0} already downloaded".format(archive_name))
sys.stdout.flush() sys.stdout.flush()
if "esp32-arduino-libs" not in archive_name and sha256sum(local_path) != checksum: if sha256sum(local_path) != checksum:
print("Checksum mismatch for {0}".format(archive_name)) print("Checksum mismatch for {0}".format(archive_name))
return False return False
return unpack(local_path, ".", force_extract) return unpack(local_path, ".", force_extract, checksum)
def load_tools_list(filename, platform): def load_tools_list(filename, platform):
...@@ -379,21 +411,17 @@ def identify_platform(): ...@@ -379,21 +411,17 @@ def identify_platform():
if __name__ == "__main__": if __name__ == "__main__":
parser = argparse.ArgumentParser(description="Download and extract tools") parser = argparse.ArgumentParser(description="Download and extract tools")
parser.add_argument("-v", "--verbose", type=bool, default=False, required=False, help="Print verbose output") parser.add_argument("-v", "--verbose", action="store_true", required=False, help="Print verbose output")
parser.add_argument( parser.add_argument("-d", "--force_download", action="store_true", required=False, help="Force download of tools")
"-d", "--force_download", type=bool, default=False, required=False, help="Force download of tools"
)
parser.add_argument( parser.add_argument("-e", "--force_extract", action="store_true", required=False, help="Force extraction of tools")
"-e", "--force_extract", type=bool, default=False, required=False, help="Force extraction of tools"
)
parser.add_argument( parser.add_argument(
"-f", "--force_all", type=bool, default=False, required=False, help="Force download and extraction of tools" "-f", "--force_all", action="store_true", required=False, help="Force download and extraction of tools"
) )
parser.add_argument("-t", "--test", type=bool, default=False, required=False, help=argparse.SUPPRESS) parser.add_argument("-t", "--test", action="store_true", required=False, help=argparse.SUPPRESS)
args = parser.parse_args() args = parser.parse_args()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment