Low-level classes

Parsers

class pylspci.parsers.base.Parser[source]
default_lspci_args: Dict[str, Any] = {}

The default arguments that, when sent to lspci(), should provide the best output for this parser.

See lspci()’s documentation for a list of available arguments.

abstract parse(data: Union[str, Iterable[str], Iterable[Iterable[str]]]) List[Device][source]

Parse a string or list of strings as a list of devices.

Parameters:

data (str or Iterable[str] or Iterable[Iterable[str]]) – A string holding multiple devices, a list of strings, one for each device, or a list of lists of strings, one list for each device, with each list holding each part of the device output.

Returns:

A list of parsed devices.

Return type:

List[Device]

run(**kwargs: Any) List[Device][source]

Run the lspci command with the given arguments, defaulting to the parser’s default arguments, and parse the result.

Parameters:

**kwargs (Any) – Optional arguments to override the parser’s default arguments. See lspci()’s documentation for a list of available arguments.

Returns:

A list of parsed devices.

Return type:

List[Device]

class pylspci.parsers.simple.SimpleParser[source]

A parser for lspci -mm.

parse(data: Union[str, Iterable[str], Iterable[Iterable[str]]]) List[Device][source]

Parse a multiline string or a list of single-line strings from lspci -mm into devices.

Parameters:

data (str or Iterable[str] or Iterable[Iterable[str]]) – A string holding multiple devices, a list of strings, one for each device, or a list of lists of strings, one list for each device, with each list holding each part of the device output.

Returns:

A list of parsed devices.

Return type:

List[Device]

parse_line(args: Union[str, Iterable[str]]) Device[source]

Parse a single line from lspci -mm into a single device, either as the line or as a list of fields.

Parameters:

args (str or Iterable[str]) – Line or list of fields to parse from.

Returns:

A single parsed device.

Return type:

Device

run(**kwargs: Any) List[Device][source]

Run the lspci command with the given arguments, defaulting to the parser’s default arguments, and parse the result.

Parameters:

**kwargs (Any) – Optional arguments to override the parser’s default arguments. See lspci()’s documentation for a list of available arguments.

Returns:

A list of parsed devices.

Return type:

List[Device]

class pylspci.parsers.verbose.VerboseParser[source]

A parser for lspci -vvvmmk

default_lspci_args: Dict[str, Any] = {'kernel_drivers': True, 'verbose': True}

The default arguments that, when sent to lspci(), should provide the best output for this parser.

See lspci()’s documentation for a list of available arguments.

parse(data: Union[str, Iterable[str], Iterable[Iterable[str]]]) List[Device][source]

Parse an lspci -vvvmm[nnk] output, either as a single string holding multiple devices separated by two newlines, or as a list of multiline strings holding one device each.

Parameters:

data (str or Iterable[str] or Iterable[Iterable[str]]) – A string holding multiple devices, a list of strings, one for each device, or a list of lists of strings, one list for each device, with each list holding each part of the device output.

Returns:

A list of parsed devices.

Return type:

List[Device]

Implementation details

class pylspci.parsers.verbose.FieldMapping(field_name: str, field_type: Callable[[str], Any], many: bool = False)[source]

Helper class to map verbose output field names such as SVendor to Device fields such as subsytem_vendor.

Create new instance of FieldMapping(field_name, field_type, many)

field_name: str

Field name on the Device named tuple.

field_type: Callable[[str], Any]

Field type; a callable to use to parse the string value.

many: bool

Whether or not to use a List, if this field can be repeated multiple times in the lspci output.