Drive#
- class Drive(*args, **kwargs)#
GDrive
represents a piece of hardware connected to the machine.
It’s generally only created for removable hardware or hardware with
removable media. For example, an optical disc drive, or a USB flash drive.
GDrive
is a container class for Volume
objects that stem from
the same piece of media. As such, GDrive
abstracts a drive with
(or without) removable media and provides operations for querying
whether media is available, determining whether media change is
automatically detected and ejecting the media.
If the GDrive
reports that media isn’t automatically detected, one
can poll for media; typically one should not do this periodically
as a poll for media operation is potentially expensive and may
spin up the drive creating noise.
GDrive
supports starting and stopping drives with authentication
support for the former. This can be used to support a diverse set
of use cases including connecting/disconnecting iSCSI devices,
powering down external disk enclosures and starting/stopping
multi-disk devices such as RAID devices. Note that the actual
semantics and side-effects of starting/stopping a GDrive
may vary
according to implementation. To choose the correct verbs in e.g. a
file manager, use get_start_stop_type
.
For porting from GnomeVFS note that there is no
equivalent of GDrive
in that API.
Methods#
- class Drive
-
- eject(flags: MountUnmountFlags, cancellable: Cancellable | None = None, callback: Callable[[Object | None, AsyncResult, Any], None] | None = None, user_data: Any = None) None #
Asynchronously ejects a drive.
When the operation is finished,
callback
will be called. You can then calleject_finish()
to obtain the result of the operation.Deprecated since version 2.22: Use
eject_with_operation()
instead.- Parameters:
flags – flags affecting the unmount if required for eject
cancellable – optional
Cancellable
object,None
to ignore.callback – a
AsyncReadyCallback
, orNone
.user_data – user data to pass to
callback
- eject_finish(result: AsyncResult) bool #
Finishes ejecting a drive.
Deprecated since version 2.22: Use
eject_with_operation_finish()
instead.- Parameters:
result – a
AsyncResult
.
- eject_with_operation(flags: MountUnmountFlags, mount_operation: MountOperation | None = None, cancellable: Cancellable | None = None, callback: Callable[[Object | None, AsyncResult, Any], None] | None = None, user_data: Any = None) None #
Ejects a drive. This is an asynchronous operation, and is finished by calling
eject_with_operation_finish()
with thedrive
andAsyncResult
data returned in thecallback
.Added in version 2.22.
- Parameters:
flags – flags affecting the unmount if required for eject
mount_operation – a
MountOperation
orNone
to avoid user interaction.cancellable – optional
Cancellable
object,None
to ignore.callback – a
AsyncReadyCallback
, orNone
.user_data – user data passed to
callback
.
- eject_with_operation_finish(result: AsyncResult) bool #
Finishes ejecting a drive. If any errors occurred during the operation,
error
will be set to contain the errors andFalse
will be returned.Added in version 2.22.
- Parameters:
result – a
AsyncResult
.
- enumerate_identifiers() list[str] #
Gets the kinds of identifiers that
drive
has. Useget_identifier()
to obtain the identifiers themselves.
- get_identifier(kind: str) str | None #
Gets the identifier of the given kind for
drive
. The only identifier currently available isDRIVE_IDENTIFIER_KIND_UNIX_DEVICE
.- Parameters:
kind – the kind of identifier to return
- get_start_stop_type() DriveStartStopType #
Gets a hint about how a drive can be started/stopped.
Added in version 2.22.
- get_volumes() list[Volume] #
Get a list of mountable volumes for
drive
.The returned list should be freed with
free()
, after its elements have been unreffed withunref()
.
- has_media() bool #
Checks if the
drive
has media. Note that the OS may not be polling the drive for media changes; seeis_media_check_automatic()
for more details.
- is_media_check_automatic() bool #
Checks if
drive
is capable of automatically detecting media changes.
- is_removable() bool #
Checks if the
Drive
and/or its media is considered removable by the user. Seeis_media_removable()
.Added in version 2.50.
- poll_for_media(cancellable: Cancellable | None = None, callback: Callable[[Object | None, AsyncResult, Any], None] | None = None, user_data: Any = None) None #
Asynchronously polls
drive
to see if media has been inserted or removed.When the operation is finished,
callback
will be called. You can then callpoll_for_media_finish()
to obtain the result of the operation.- Parameters:
cancellable – optional
Cancellable
object,None
to ignore.callback – a
AsyncReadyCallback
, orNone
.user_data – user data to pass to
callback
- poll_for_media_finish(result: AsyncResult) bool #
Finishes an operation started with
poll_for_media()
on a drive.- Parameters:
result – a
AsyncResult
.
- start(flags: DriveStartFlags, mount_operation: MountOperation | None = None, cancellable: Cancellable | None = None, callback: Callable[[Object | None, AsyncResult, Any], None] | None = None, user_data: Any = None) None #
Asynchronously starts a drive.
When the operation is finished,
callback
will be called. You can then callstart_finish()
to obtain the result of the operation.Added in version 2.22.
- Parameters:
flags – flags affecting the start operation.
mount_operation – a
MountOperation
orNone
to avoid user interaction.cancellable – optional
Cancellable
object,None
to ignore.callback – a
AsyncReadyCallback
, orNone
.user_data – user data to pass to
callback
- start_finish(result: AsyncResult) bool #
Finishes starting a drive.
Added in version 2.22.
- Parameters:
result – a
AsyncResult
.
- stop(flags: MountUnmountFlags, mount_operation: MountOperation | None = None, cancellable: Cancellable | None = None, callback: Callable[[Object | None, AsyncResult, Any], None] | None = None, user_data: Any = None) None #
Asynchronously stops a drive.
When the operation is finished,
callback
will be called. You can then callstop_finish()
to obtain the result of the operation.Added in version 2.22.
- Parameters:
flags – flags affecting the unmount if required for stopping.
mount_operation – a
MountOperation
orNone
to avoid user interaction.cancellable – optional
Cancellable
object,None
to ignore.callback – a
AsyncReadyCallback
, orNone
.user_data – user data to pass to
callback
- stop_finish(result: AsyncResult) bool #
Finishes stopping a drive.
Added in version 2.22.
- Parameters:
result – a
AsyncResult
.
Signals#
Virtual Methods#
- class Drive
-
- do_eject(flags: MountUnmountFlags, cancellable: Cancellable | None = None, callback: Callable[[Object | None, AsyncResult, Any], None] | None = None, user_data: Any = None) None #
Asynchronously ejects a drive.
When the operation is finished,
callback
will be called. You can then calleject_finish()
to obtain the result of the operation.Deprecated since version 2.22: Use
eject_with_operation()
instead.- Parameters:
flags – flags affecting the unmount if required for eject
cancellable – optional
Cancellable
object,None
to ignore.callback – a
AsyncReadyCallback
, orNone
.user_data – user data to pass to
callback
- do_eject_finish(result: AsyncResult) bool #
Finishes ejecting a drive.
Deprecated since version 2.22: Use
eject_with_operation_finish()
instead.- Parameters:
result – a
AsyncResult
.
- do_eject_with_operation(flags: MountUnmountFlags, mount_operation: MountOperation | None = None, cancellable: Cancellable | None = None, callback: Callable[[Object | None, AsyncResult, Any], None] | None = None, user_data: Any = None) None #
Ejects a drive. This is an asynchronous operation, and is finished by calling
eject_with_operation_finish()
with thedrive
andAsyncResult
data returned in thecallback
.Added in version 2.22.
- Parameters:
flags – flags affecting the unmount if required for eject
mount_operation – a
MountOperation
orNone
to avoid user interaction.cancellable – optional
Cancellable
object,None
to ignore.callback – a
AsyncReadyCallback
, orNone
.user_data – user data passed to
callback
.
- do_eject_with_operation_finish(result: AsyncResult) bool #
Finishes ejecting a drive. If any errors occurred during the operation,
error
will be set to contain the errors andFalse
will be returned.Added in version 2.22.
- Parameters:
result – a
AsyncResult
.
- do_enumerate_identifiers() list[str] #
Gets the kinds of identifiers that
drive
has. Useget_identifier()
to obtain the identifiers themselves.
- do_get_identifier(kind: str) str | None #
Gets the identifier of the given kind for
drive
. The only identifier currently available isDRIVE_IDENTIFIER_KIND_UNIX_DEVICE
.- Parameters:
kind – the kind of identifier to return
- do_get_start_stop_type() DriveStartStopType #
Gets a hint about how a drive can be started/stopped.
Added in version 2.22.
- do_get_volumes() list[Volume] #
Get a list of mountable volumes for
drive
.The returned list should be freed with
free()
, after its elements have been unreffed withunref()
.
- do_has_media() bool #
Checks if the
drive
has media. Note that the OS may not be polling the drive for media changes; seeis_media_check_automatic()
for more details.
- do_is_media_check_automatic() bool #
Checks if
drive
is capable of automatically detecting media changes.
- do_is_removable() bool #
Checks if the
Drive
and/or its media is considered removable by the user. Seeis_media_removable()
.Added in version 2.50.
- do_poll_for_media(cancellable: Cancellable | None = None, callback: Callable[[Object | None, AsyncResult, Any], None] | None = None, user_data: Any = None) None #
Asynchronously polls
drive
to see if media has been inserted or removed.When the operation is finished,
callback
will be called. You can then callpoll_for_media_finish()
to obtain the result of the operation.- Parameters:
cancellable – optional
Cancellable
object,None
to ignore.callback – a
AsyncReadyCallback
, orNone
.user_data – user data to pass to
callback
- do_poll_for_media_finish(result: AsyncResult) bool #
Finishes an operation started with
poll_for_media()
on a drive.- Parameters:
result – a
AsyncResult
.
- do_start(flags: DriveStartFlags, mount_operation: MountOperation | None = None, cancellable: Cancellable | None = None, callback: Callable[[Object | None, AsyncResult, Any], None] | None = None, user_data: Any = None) None #
Asynchronously starts a drive.
When the operation is finished,
callback
will be called. You can then callstart_finish()
to obtain the result of the operation.Added in version 2.22.
- Parameters:
flags – flags affecting the start operation.
mount_operation – a
MountOperation
orNone
to avoid user interaction.cancellable – optional
Cancellable
object,None
to ignore.callback – a
AsyncReadyCallback
, orNone
.user_data – user data to pass to
callback
- do_start_finish(result: AsyncResult) bool #
Finishes starting a drive.
Added in version 2.22.
- Parameters:
result – a
AsyncResult
.
- do_stop(flags: MountUnmountFlags, mount_operation: MountOperation | None = None, cancellable: Cancellable | None = None, callback: Callable[[Object | None, AsyncResult, Any], None] | None = None, user_data: Any = None) None #
Asynchronously stops a drive.
When the operation is finished,
callback
will be called. You can then callstop_finish()
to obtain the result of the operation.Added in version 2.22.
- Parameters:
flags – flags affecting the unmount if required for stopping.
mount_operation – a
MountOperation
orNone
to avoid user interaction.cancellable – optional
Cancellable
object,None
to ignore.callback – a
AsyncReadyCallback
, orNone
.user_data – user data to pass to
callback
- do_stop_finish(result: AsyncResult) bool #
Finishes stopping a drive.
Added in version 2.22.
- Parameters:
result – a
AsyncResult
.