GUdev.Device

g GObject.Object GObject.Object GUdev.Device GUdev.Device GObject.Object->GUdev.Device

Subclasses:

None

Methods

Inherited:

GObject.Object (37)

Structs:

GObject.ObjectClass (5)

get_action ()

get_current_tags ()

get_device_file ()

get_device_file_symlinks ()

get_device_number ()

get_device_type ()

get_devtype ()

get_driver ()

get_is_initialized ()

get_name ()

get_number ()

get_parent ()

get_parent_with_subsystem (subsystem, devtype)

get_property (key)

get_property_as_boolean (key)

get_property_as_double (key)

get_property_as_int (key)

get_property_as_strv (key)

get_property_as_uint64 (key)

get_property_keys ()

get_seqnum ()

get_subsystem ()

get_sysfs_attr (name)

get_sysfs_attr_as_boolean (name)

get_sysfs_attr_as_boolean_uncached (name)

get_sysfs_attr_as_double (name)

get_sysfs_attr_as_double_uncached (name)

get_sysfs_attr_as_int (name)

get_sysfs_attr_as_int_uncached (name)

get_sysfs_attr_as_strv (name)

get_sysfs_attr_as_strv_uncached (name)

get_sysfs_attr_as_uint64 (name)

get_sysfs_attr_as_uint64_uncached (name)

get_sysfs_attr_keys ()

get_sysfs_attr_uncached (name)

get_sysfs_path ()

get_tags ()

get_usec_since_initialized ()

has_property (key)

has_sysfs_attr (key)

has_sysfs_attr_uncached (key)

Virtual Methods

Inherited:

GObject.Object (7)

Properties

None

Signals

Inherited:

GObject.Object (1)

Fields

Inherited:

GObject.Object (1)

Name

Type

Access

Description

parent

GObject.Object

r

Class Details

class GUdev.Device(**kwargs)
Bases:

GObject.Object

Abstract:

No

Structure:

GUdev.DeviceClass

The GUdev.Device class is used to get information about a specific device. Note that you cannot instantiate a GUdev.Device object yourself. Instead you must use GUdev.Client to obtain GUdev.Device objects.

To get basic information about a device, use GUdev.Device.get_subsystem(), GUdev.Device.get_devtype(), GUdev.Device.get_name(), GUdev.Device.get_number(), GUdev.Device.get_sysfs_path(), GUdev.Device.get_driver(), GUdev.Device.get_action(), GUdev.Device.get_seqnum(), GUdev.Device.get_device_type(), GUdev.Device.get_device_number(), GUdev.Device.get_device_file(), GUdev.Device.get_device_file_symlinks().

To navigate the device tree, use GUdev.Device.get_parent() and GUdev.Device.get_parent_with_subsystem().

To access udev properties for the device, use GUdev.Device.get_property_keys(), GUdev.Device.has_property(), GUdev.Device.get_property(), GUdev.Device.get_property_as_int(), GUdev.Device.get_property_as_uint64(), GUdev.Device.get_property_as_double(), GUdev.Device.get_property_as_boolean() and GUdev.Device.get_property_as_strv().

To access sysfs attributes for the device, use GUdev.Device.get_sysfs_attr_keys(), GUdev.Device.has_sysfs_attr(), GUdev.Device.get_sysfs_attr(), GUdev.Device.get_sysfs_attr_as_int(), GUdev.Device.get_sysfs_attr_as_uint64(), GUdev.Device.get_sysfs_attr_as_double(), GUdev.Device.get_sysfs_attr_as_boolean() and GUdev.Device.get_sysfs_attr_as_strv().

Note that all getters on GUdev.Device are non-reffing – returned values are owned by the object, should not be freed and are only valid as long as the object is alive.

By design, GUdev.Device will not react to changes for a device – it only contains a snapshot of information when the GUdev.Device object was created. To work with changes, you typically connect to the GUdev.Client ::uevent signal on a GUdev.Client and get a new GUdev.Device whenever an event happens.

get_action()
Returns:

An action string.

Return type:

str

Gets the most recent action (e.g. “add”, “remove”, “change”, etc.) for self.

get_current_tags()
Returns:

A None terminated string array of current tags. This array is owned by self and should not be freed by the caller.

Return type:

[str]

Gets all current tags for self.

https://www.freedesktop.org/software/systemd/man/udev_device_has_current_tag.html

New in version 238.

get_device_file()
Returns:

The device file for self or None if no device file exists.

Return type:

str or None

Gets the device file for self.

Returns:

A None terminated string array of symlinks. This array is owned by self and should not be freed by the caller.

Return type:

[str]

Gets a list of symlinks (in /dev) that points to the device file for self.

get_device_number()
Returns:

The device number for self or 0 if unknown.

Return type:

int

Gets the device number, if any, for self.

get_device_type()
Returns:

The device number for self or GUdev.DeviceType.NONE if the device does not have a device file.

Return type:

GUdev.DeviceType

Gets the type of the device file, if any, for self.

get_devtype()
Returns:

The devtype for self.

Return type:

str

Gets the device type for self.

get_driver()
Returns:

The name of the driver for self or None if unknown.

Return type:

str or None

Gets the name of the driver used for self.

get_is_initialized()
Returns:

Whether self has been initialized.

Return type:

bool

Gets whether self has been initialized.

New in version 165.

get_name()
Returns:

The name of self.

Return type:

str

Gets the name of self, e.g. “sda3”.

get_number()
Returns:

The number of self.

Return type:

str

Gets the number of self, e.g. “3” if GUdev.Device.get_name() returns “sda3”.

get_parent()
Returns:

A GUdev.Device or None if self has no parent. Free with GObject.Object.unref().

Return type:

GUdev.Device or None

Gets the immediate parent of self, if any.

get_parent_with_subsystem(subsystem, devtype)
Parameters:
  • subsystem (str) – The subsystem of the parent to get.

  • devtype (str or None) – The devtype of the parent to get or None.

Returns:

A GUdev.Device or None if self has no parent with subsystem and devtype. Free with GObject.Object.unref().

Return type:

GUdev.Device or None

Walks up the chain of parents of self and returns the first device encountered where subsystem and devtype matches, if any.

get_property(key)
Parameters:

key (str) – Name of property.

Returns:

The value for key or None if key doesn’t exist on self. Do not free this string, it is owned by self.

Return type:

str or None

Look up the value for key on self.

get_property_as_boolean(key)
Parameters:

key (str) – Name of property.

Returns:

The value for key or False if key doesn’t exist or isn’t a bool.

Return type:

bool

Look up the value for key on self and convert it to an boolean. This is done by doing a case-insensitive string comparison on the string value against “1” and “true”.

get_property_as_double(key)
Parameters:

key (str) – Name of property.

Returns:

The value for key or 0.0 if key doesn’t exist or isn’t a float.

Return type:

float

Look up the value for key on self and convert it to a double precision floating point number using GLib.ascii_strtod().

get_property_as_int(key)
Parameters:

key (str) – Name of property.

Returns:

The value for key or 0 if key doesn’t exist or isn’t an integer.

Return type:

int

Look up the value for key on self and convert it to an integer using strtol().

get_property_as_strv(key)
Parameters:

key (str) – Name of property.

Returns:

The value of key on self split into tokens or None if key doesn’t exist. This array is owned by self and should not be freed by the caller.

Return type:

[str] or None

Look up the value for key on self and return the result of splitting it into non-empty tokens split at white space (only space (’ ‘), form-feed (’\f’), newline (’\n’), carriage return (’\r’), horizontal tab (’\t’), and vertical tab (’\v’) are considered; the locale is not taken into account).

get_property_as_uint64(key)
Parameters:

key (str) – Name of property.

Returns:

The value for key or 0 if key doesn’t exist or isn’t a #guint64.

Return type:

int

Look up the value for key on self and convert it to an unsigned 64-bit integer using GLib.ascii_strtoull().

get_property_keys()
Returns:

A None terminated string array of property keys. This array is owned by self and should not be freed by the caller.

Return type:

[str]

Gets all keys for properties on self.

get_seqnum()
Returns:

A sequence number.

Return type:

int

Gets the most recent sequence number for self.

get_subsystem()
Returns:

The subsystem for self.

Return type:

str

Gets the subsystem for self.

get_sysfs_attr(name)
Parameters:

name (str) – Name of the sysfs attribute.

Returns:

The value of the sysfs attribute or None if there is no such attribute. Do not free this string, it is owned by self.

Return type:

str or None

Look up the sysfs attribute with name on self. The retrieved value is cached in the device. Repeated calls will return the same value and not open the attribute again, unless updated through one of the “uncached” functions.

get_sysfs_attr_as_boolean(name)
Parameters:

name (str) – Name of the sysfs attribute.

Returns:

The value of the sysfs attribute or False if there is no such attribute.

Return type:

bool

Look up the sysfs attribute with name on self and convert it to an boolean. This is done by doing a case-insensitive string comparison on the string value against “1”, “true”, “Y” and “y”. The retrieved value is cached in the device. Repeated calls will return the same value and not open the attribute again, unless updated through one of the “uncached” functions.

get_sysfs_attr_as_boolean_uncached(name)
Parameters:

name (str) – Name of the sysfs attribute.

Returns:

The value of the sysfs attribute or False if there is no such attribute.

Return type:

bool

Look up the sysfs attribute with name on self and convert it to an boolean. This is done by doing a case-insensitive string comparison on the string value against “1”, “true”, “Y” and “y”. This function does blocking I/O, and updates the sysfs attributes cache.

Before version 238 the uncached getters would not strip trailing newlines.

New in version 234.

get_sysfs_attr_as_double(name)
Parameters:

name (str) – Name of the sysfs attribute.

Returns:

The value of the sysfs attribute or 0.0 if there is no such attribute.

Return type:

float

Look up the sysfs attribute with name on self and convert it to a double precision floating point number using GLib.ascii_strtod(). The retrieved value is cached in the device. Repeated calls will return the same value and not open the attribute again, unless updated through one of the “uncached” functions.

get_sysfs_attr_as_double_uncached(name)
Parameters:

name (str) – Name of the sysfs attribute.

Returns:

The value of the sysfs attribute or 0.0 if there is no such attribute.

Return type:

float

Look up the sysfs attribute with name on self and convert it to a double precision floating point number using GLib.ascii_strtod(). This function does blocking I/O, and updates the sysfs attributes cache.

Before version 238 the uncached getters would not strip trailing newlines.

New in version 234.

get_sysfs_attr_as_int(name)
Parameters:

name (str) – Name of the sysfs attribute.

Returns:

The value of the sysfs attribute or 0 if there is no such attribute.

Return type:

int

Look up the sysfs attribute with name on self and convert it to an integer using strtol(). The retrieved value is cached in the device. Repeated calls will return the same value and not open the attribute again, unless updated through one of the “uncached” functions.

get_sysfs_attr_as_int_uncached(name)
Parameters:

name (str) – Name of the sysfs attribute.

Returns:

The value of the sysfs attribute or 0 if there is no such attribute.

Return type:

int

Look up the sysfs attribute with name on self and convert it to an integer using strtol(). This function does blocking I/O, and updates the sysfs attributes cache.

Before version 238 the uncached getters would not strip trailing newlines.

New in version 234.

get_sysfs_attr_as_strv(name)
Parameters:

name (str) – Name of the sysfs attribute.

Returns:

The value of the sysfs attribute split into tokens or None if there is no such attribute. This array is owned by self and should not be freed by the caller.

Return type:

[str] or None

Look up the sysfs attribute with name on self and return the result of splitting it into non-empty tokens split at white space (only space (’ ‘), form-feed (’\f’), newline (’\n’), carriage return (’\r’), horizontal tab (’\t’), and vertical tab (’\v’) are considered; the locale is not taken into account).

The retrieved value is cached in the device. Repeated calls will return the same value and not open the attribute again, unless updated through one of the “uncached” functions.

get_sysfs_attr_as_strv_uncached(name)
Parameters:

name (str) – Name of the sysfs attribute.

Returns:

The value of the sysfs attribute split into tokens or None if there is no such attribute. This array is owned by self and should not be freed by the caller.

Before version 238 the uncached getters would not strip trailing newlines.

Return type:

[str] or None

Look up the sysfs attribute with name on self and return the result of splitting it into non-empty tokens split at white space (only space (’ ‘), form-feed (’\f’), newline (’\n’), carriage return (’\r’), horizontal tab (’\t’), and vertical tab (’\v’) are considered; the locale is not taken into account).

This function does blocking I/O, and updates the sysfs attributes cache.

New in version 234.

get_sysfs_attr_as_uint64(name)
Parameters:

name (str) – Name of the sysfs attribute.

Returns:

The value of the sysfs attribute or 0 if there is no such attribute.

Return type:

int

Look up the sysfs attribute with name on self and convert it to an unsigned 64-bit integer using GLib.ascii_strtoull(). The retrieved value is cached in the device. Repeated calls will return the same value and not open the attribute again, unless updated through one of the “uncached” functions.

get_sysfs_attr_as_uint64_uncached(name)
Parameters:

name (str) – Name of the sysfs attribute.

Returns:

The value of the sysfs attribute or 0 if there is no such attribute.

Return type:

int

Look up the sysfs attribute with name on self and convert it to an unsigned 64-bit integer using GLib.ascii_strtoull(). This function does blocking I/O, and updates the sysfs attributes cache.

Before version 238 the uncached getters would not strip trailing newlines.

New in version 234.

get_sysfs_attr_keys()
Returns:

A None terminated string array of sysfs attribute keys. This array is owned by self and should not be freed by the caller.

Return type:

[str]

Gets all keys for sysfs attributes on self.

get_sysfs_attr_uncached(name)
Parameters:

name (str) – Name of the sysfs attribute.

Returns:

The value of the sysfs attribute or None if there is no such attribute. Do not free this string, it is owned by self.

Return type:

str or None

Look up the sysfs attribute with name on self. This function does blocking I/O, and updates the sysfs attributes cache.

Before version 238 the uncached getters would not strip trailing newlines.

New in version 234.

get_sysfs_path()
Returns:

The sysfs path for self.

Return type:

str

Gets the sysfs path for self.

get_tags()
Returns:

A None terminated string array of tags. This array is owned by self and should not be freed by the caller.

Return type:

[str]

Gets all tags for self.

New in version 165.

get_usec_since_initialized()
Returns:

Number of micro-seconds since self was initialized or 0 if unknown.

Return type:

int

Gets number of micro-seconds since self was initialized.

This only works for devices with properties in the udev database. All other devices return 0.

New in version 165.

has_property(key)
Parameters:

key (str) – Name of property.

Returns:

True only if the value for key exist.

Return type:

bool

Check if a the property with the given key exists.

has_sysfs_attr(key)
Parameters:

key (str) – Name of sysfs attribute.

Returns:

True only if the value for key exist.

Return type:

bool

Check if a the sysfs attribute with the given key exists. The retrieved value is cached in the device. Repeated calls will return the same result and not check for the presence of the attribute again, unless updated through one of the “uncached” functions.

has_sysfs_attr_uncached(key)
Parameters:

key (str) – Name of sysfs attribute.

Returns:

True only if the value for key exist.

Return type:

bool

Check if a the sysfs attribute with the given key exists. The retrieved value is cached in the device. Repeated calls will return the same result and not check for the presence of the attribute again, unless updated through one of the “uncached” functions.

New in version 234.