Skip to content

Override parser

override_parser

Contains classes to help with parsing INF files that may contain OVERRIDE information.

OpParseError

Class representing OpParseError types.

__init__

__init__(my_type: str) -> OpParseError

Verifies type is a valid OpParseError type.

__str__

__str__() -> str

String representation of the OpParseError type.

OverrideParser

OverrideParser is a simple file parser for .inf files.

OverrideParser must contain OVERRIDE data (i.e. overriding other .infs). Creating the object can be done by passing either a valid file path or a string containing the contents of an .inf file.

Will raise an exception if the file doesn't exist or if the contents do not contain any OVERRIDE data.

There is an argument to be made that this class should actually be

a subclass of InfParser, however, the InfParser is looking for far more details and has a much higher overhead. During a parser refactor, this should be considered.

There is a pattern used here where the object parses during

instantiation. This pattern does not necessarily match the other parsers. The pros and cons of this should also be weighed during any parser refactor.

__init__

__init__(
    file_path: Optional[str] = None,
    inf_contents: Optional[str] = None,
) -> OverrideParser

Inits and parses either a file or already parsed contents.

Parameters:

Name Type Description Default
file_path Optional[str]

Path to an INF file

None
inf_contents Optional[str]

Parsed lines as a string

None

get_override_lines staticmethod

get_override_lines(parse_contents: str) -> list

Parses contents and returns only lines that start with #OVERRIDE.

Returns:

Type Description
list[str]

lines starting with #OVERRIDE

parse_override_line staticmethod

parse_override_line(line_contents: str) -> dict

Parses an override_line.

Parameters:

Name Type Description Default
line_contents str

a line that starts with #OVERRIDE

required

Returns:

Type Description
dict

Key/Value pairs including version, original_path, current_hash, datetime

Raises:

Type Description
OpParseError

Failed to parse one of the keys