From d3262d10f739599786d9973bdd7c7f122094309e Mon Sep 17 00:00:00 2001 From: Joe LeVeque Date: Wed, 4 Nov 2020 15:06:44 -0800 Subject: [PATCH] [generate_asic_config_checksum.py] Convert to Python 3 (#5783) - Convert script to Python 3 - Need to open file in binary mode before hashing due to new string data type in Python 3 being unicode by default. This should probably have been done regardless. - Reorganize imports alphabetically - When running the script, don't explicitly call `python`. Instead let the program loader use the interpreter specified in the shebang (which is now `python3`). --- build_debian.sh | 3 ++- files/build_scripts/generate_asic_config_checksum.py | 8 ++++---- 2 files changed, 6 insertions(+), 5 deletions(-) mode change 100644 => 100755 files/build_scripts/generate_asic_config_checksum.py diff --git a/build_debian.sh b/build_debian.sh index db736d16946e..2bb284182db1 100755 --- a/build_debian.sh +++ b/build_debian.sh @@ -463,7 +463,8 @@ EOF sudo cp ./files/scripts/core_cleanup.py $FILESYSTEM_ROOT/usr/bin/core_cleanup.py ## Copy ASIC config checksum -python files/build_scripts/generate_asic_config_checksum.py +sudo chmod 755 files/build_scripts/generate_asic_config_checksum.py +./files/build_scripts/generate_asic_config_checksum.py if [[ ! -f './asic_config_checksum' ]]; then echo 'asic_config_checksum not found' exit 1 diff --git a/files/build_scripts/generate_asic_config_checksum.py b/files/build_scripts/generate_asic_config_checksum.py old mode 100644 new mode 100755 index 638259ce938a..41ef6f045e21 --- a/files/build_scripts/generate_asic_config_checksum.py +++ b/files/build_scripts/generate_asic_config_checksum.py @@ -1,8 +1,8 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 -import syslog -import os import hashlib +import os +import syslog SYSLOG_IDENTIFIER = 'asic_config_checksum' @@ -45,7 +45,7 @@ def generate_checksum(checksum_files): checksum = hashlib.sha1() for checksum_file in checksum_files: try: - with open(checksum_file, 'r') as f: + with open(checksum_file, 'rb') as f: for chunk in iter(lambda: f.read(CHUNK_SIZE), b""): checksum.update(chunk) except IOError as e: