guess_format_name#

hexrec.base.guess_format_name(file_path)[source]#

Guesses the record format name.

It analyzes the file extension by file_path against all the record formats registered into FILE_TYPES. The first record format to match the extension within its own BaseFile.FILE_EXT is returned.

If no extension matches, the file is parsed until a BaseFile.parse() succeds (no exception raised).

Parameters:

file_path (str) – File path to analyze.

Returns:

str – Record format registered within FILE_TYPES.

Raises:

ValueError – Cannot guess record file format.

See also

FILE_TYPES

Examples

>>> from hexrec import guess_format_name
>>> guess_format_name('simple.hex')
'ihex'
>>> guess_format_name('simple.srec')
'srec'
>>> guess_format_name('simple.s19')
'srec'
>>> guess_format_name('simple.mot')
'srec'
>>> guess_format_name('data.dat')
'raw'