diff options
author | Markus Mohrhard <markus.mohrhard@googlemail.com> | 2017-06-17 18:43:07 +0200 |
---|---|---|
committer | Markus Mohrhard <markus.mohrhard@googlemail.com> | 2017-06-17 18:44:21 +0200 |
commit | d04ab636235d86be3571b8ffbee16183a5e30fb8 (patch) | |
tree | 8c022e0eed64a787fec28e26340c698cbc63cad3 /onlineupdate | |
parent | b690d647dabde355bd61fa7240bd8bd5ad170f79 (diff) |
updater: get the certificate code working on python2 and 3
Change-Id: Id1b4a443629c95fdbda59153c6f688629f6b1862
Diffstat (limited to 'onlineupdate')
-rwxr-xr-x | onlineupdate/source/update/updater/gen_cert_header.py | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/onlineupdate/source/update/updater/gen_cert_header.py b/onlineupdate/source/update/updater/gen_cert_header.py index 8fedcd9bcf62..a75af1e295fb 100755 --- a/onlineupdate/source/update/updater/gen_cert_header.py +++ b/onlineupdate/source/update/updater/gen_cert_header.py @@ -1,8 +1,12 @@ -#!/usr/bin/env python3 +#!/usr/bin/env python import sys import binascii -import configparser + +try: + from configparser import ConfigParser +except ImportError: + from ConfigParser import SafeConfigParser as ConfigParser def file_byte_generator(filename): with open(filename, "rb") as f: @@ -10,7 +14,10 @@ def file_byte_generator(filename): return block def create_header(array_name, in_filename): - hexified = ["0x" + binascii.hexlify(bytes([inp])).decode('ascii') for inp in file_byte_generator(in_filename)] + if sys.version_info >= (3,0): + hexified = ["0x" + binascii.hexlify(bytes([inp])).decode('ascii') for inp in file_byte_generator(in_filename)] + else: + hexified = ["0x" + binascii.hexlify(inp).decode('ascii') for inp in file_byte_generator(in_filename)] print("const uint8_t " + array_name + "[] = {") print(", ".join(hexified)) print("};") @@ -20,6 +27,6 @@ if __name__ == '__main__': if len(sys.argv) < 3: print('ERROR: usage: gen_cert_header.py array_name update_config_file') sys.exit(1); - config = configparser.ConfigParser() + config = ConfigParser() config.read(sys.argv[2]) - sys.exit(create_header(sys.argv[1], config['Updater']['certificate-der'])) + sys.exit(create_header(sys.argv[1], config.get('Updater', 'certificate-der'))) |