Skip to content

Commit

Permalink
[generate_asic_config_checksum.py] Convert to Python 3 (#5783)
Browse files Browse the repository at this point in the history
- 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`).
  • Loading branch information
jleveque authored Nov 4, 2020
1 parent ba7fda7 commit d3262d1
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
3 changes: 2 additions & 1 deletion build_debian.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions files/build_scripts/generate_asic_config_checksum.py
100644 → 100755
Original file line number Diff line number Diff line change
@@ -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'

Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit d3262d1

Please sign in to comment.