tools: fw-update: Don't wrap datetime parsing in a catch KeyError block
Currently, all of the datetime parse is wrapped in a `catch KeyError`
block. However, the only part of this that would raise a KeyError is
where we extract the PackageReleaseDateTime from the metadata dict.
Instead, just do the key lookup separately, and parse outside of the
catch block.
Then, since we're handling a default anyway, just use .get() and then we
don't need to catch the KeyError.
Signed-off-by: Jeremy Kerr <jk@codeconstruct.com.au>
Change-Id: Iae6b92383af4fe49770e77005fcb575faa125703
diff --git a/tools/fw-update/pldm_fwup_pkg_creator.py b/tools/fw-update/pldm_fwup_pkg_creator.py
index 42e8a5a..0209f1a 100755
--- a/tools/fw-update/pldm_fwup_pkg_creator.py
+++ b/tools/fw-update/pldm_fwup_pkg_creator.py
@@ -181,14 +181,18 @@
struct.pack("<BH", package_header_format_revision, package_header_size)
)
- try:
+ release_date_time_str = metadata["PackageHeaderInformation"].get(
+ "PackageReleaseDateTime", None
+ )
+
+ if release_date_time_str is not None:
release_date_time = datetime.strptime(
- metadata["PackageHeaderInformation"]["PackageReleaseDateTime"],
- "%d/%m/%Y %H:%M:%S",
+ release_date_time_str, "%d/%m/%Y %H:%M:%S"
)
- write_pkg_release_date_time(pldm_fw_up_pkg, release_date_time)
- except KeyError:
- write_pkg_release_date_time(pldm_fw_up_pkg, datetime.now())
+ else:
+ release_date_time = datetime.now()
+
+ write_pkg_release_date_time(pldm_fw_up_pkg, release_date_time)
component_bitmap_bit_length = write_component_bitmap_bit_length(
pldm_fw_up_pkg, metadata