GUdev.Device¶
- Subclasses:
None
Methods¶
- Inherited:
- Structs:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Virtual Methods¶
- Inherited:
Properties¶
None
Signals¶
- Inherited:
Fields¶
- Inherited:
Name |
Type |
Access |
Description |
---|---|---|---|
parent |
r |
Class Details¶
- class GUdev.Device(**kwargs)¶
- Bases:
- Abstract:
No
- Structure:
The
GUdev.Device
class is used to get information about a specific device. Note that you cannot instantiate aGUdev.Device
object yourself. Instead you must useGUdev.Client
to obtainGUdev.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
() andGUdev.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
() andGUdev.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
() andGUdev.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 theGUdev.Device
object was created. To work with changes, you typically connect to theGUdev.Client
::uevent
signal on aGUdev.Client
and get a newGUdev.Device
whenever an event happens.- get_action()¶
- Returns:
An action string.
- Return type:
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()¶
-
Gets the device file for self.
- get_device_file_symlinks()¶
- 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:
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:
Gets the type of the device file, if any, for self.
- get_driver()¶
-
Gets the name of the driver used for self.
- get_is_initialized()¶
- Returns:
Whether self has been initialized.
- Return type:
Gets whether self has been initialized.
New in version 165.
- get_number()¶
- Returns:
The number of self.
- Return type:
Gets the number of self, e.g. “3” if
GUdev.Device.get_name
() returns “sda3”.
- get_parent()¶
- Returns:
A
GUdev.Device
orNone
if self has no parent. Free withGObject.Object.unref
().- Return type:
GUdev.Device
orNone
Gets the immediate parent of self, if any.
- get_parent_with_subsystem(subsystem, devtype)¶
- Parameters:
- Returns:
A
GUdev.Device
orNone
if self has no parent with subsystem and devtype. Free withGObject.Object.unref
().- Return type:
GUdev.Device
orNone
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:
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 abool
.- Return type:
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:
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:
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:
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:
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:
Gets the most recent sequence number 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:
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:
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:
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:
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:
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:
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:
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:
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:
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:
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:
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:
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_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:
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:
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:
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:
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.