1
0
mirror of https://github.com/ARM-software/workload-automation.git synced 2025-01-31 02:01:16 +00:00

utils/serializer: Handle empty file extensions

The ValueError does not given enough information in the case of an empty file
extension. Add a special case to handle files with no extension and
prompt the user.
This commit is contained in:
Waleed El-Geresy 2018-06-14 16:15:33 +01:00 committed by setrofim
parent 88731fe489
commit 578d2d3a16

View File

@ -299,6 +299,12 @@ def load(s, fmt='json', *args, **kwargs):
def _read_pod(fh, fmt=None):
if fmt is None:
fmt = os.path.splitext(fh.name)[1].lower().strip('.')
if fmt == '':
# Special case of no given file extension
message = ("Could not determine format " +
"from file extension for \"{}\". ".format(getattr(fh, 'name', '<none>')) +
"Please specify it or modify the fmt parameter.")
raise ValueError(message)
if fmt == 'yaml':
return yaml.load(fh)
elif fmt == 'json':