[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`).
This commit is contained in:
Joe LeVeque 2020-11-04 15:06:44 -08:00 committed by GitHub
parent ba7fda7fd1
commit d3262d10f7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 5 deletions

View File

@ -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

8
files/build_scripts/generate_asic_config_checksum.py Normal file → Executable file
View File

@ -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: