Aptdaemon comes with a client module which provides a smoother interface on top of the D-Bus interface. It provides GObjects of the daemon and each transaction.
At first you initialize an AptClient instance.
>>> from aptdaemon import client
>>>
>>> apt_client = client.AptClient()
Secondly you call the whished action, e.g. updating the package cache. It will give you a new transaction instance.
>>> transaction = apt_client.update()
The transaction has not been started yet. So you can make some further adjustements to it, e.g. setting a different language:
>>> transaction.set_locale("de_DE")
... or setup the monitoring of the transaction:
>>> transaction.connect("finished", on_transaction_finished)
You can then put the transaction on the queue by calling its run() method:
>>> transaction.run()
If you don’t need the underlying transcation instance of an action, you can alternatively set the wait argument to True. The AptClient method will return after the transaction is done:
>>> apt_client.update_cache(wait=True)
This can also be used with asynchronous programming, see below.
In the above examples simple synchronous calls have been made to the D-Bus. Until these calls return your whole application is blocked/frozen. In the case of password prompts this can be quite long. So aptdaemon supports the following asynchronous styles:
Since the client module is basically a wrapper around D-Bus calls, it provides a pair of reply_handler and error_handler for each method. You are perhaps already familiar with those if you have written a Python D-Bus client before:
>>> def run(trans):
... trans.run(reply_handler=trans_has_started, error_handler=on_error)
...
>>> def trans_has_started():
... pass
...
>>> def on_error(error):
... raise error
...
>>> client = AptClient()
>>> client.update(reply_handler=run, error_handler=on_error)
Aptdaemon uses a simplified version of Twisted deferreds internally, called python-defer. But you can also make use of them in your application.
The inline_callbacks decorator of python-defer allows to write asynchronous code in a synchronous way:
>>> @defer.inline_callbacks
... def update_cache():
... apt_client = client.AptClient()
... try:
... transaction = yield apt_client.update()
... except errors.NotAuthorizedError:
... print "You are not allowed to update the cache!"
... raise StopIteration
... yield transaction.set_locale("de_DE")
... yield transaction.run()
... print "Transaction has started"
It is possible to chain transactions. This allows to add a simple dependency relation, e.g. you want to add a new repository, update the cache and finally install a new package.
>>> client = aptdaemon.client.AptClient()
>>> trans1 = client.add_repository("deb", [...])
>>> trans2 = client.update_cache()
>>> trans3 = client.install_packages(["new-package"])
>>> trans2.run_after(trans1)
>>> trans3.run_after(trans2)
>>> trans1.run()
If a transaction in a chain fails all other ones which follow will fail too with the enums.EXIT_PREVIOUS_FAILED exit state.
Provides a complete client for aptdaemon.
Install a license key to use a piece of proprietary software.
Parameters: |
|
---|---|
Raises : | dbus.DBusException |
Returns: | An AptTransaction instance. |
Create a new transaction to enable a repository.
Parameters: |
|
---|---|
Raises : | dbus.DBusException |
Returns: | An AptTransaction instance. |
Create a new transaction to install the key file of a software vendor. The key is used to authenticate packages of the vendor.
Parameters: |
|
---|---|
Raises : | dbus.DBusException |
Returns: | An AptTransaction instance. |
Create a new transaction to download and install the key of a software vendor. The key is used to authenticate packages of the vendor.
Parameters: |
|
---|---|
Raises : | dbus.DBusException |
Returns: | An AptTransaction instance. |
Remove all downloaded files.
Parameters: |
|
---|---|
Raises : | dbus.DBusException |
Returns: | An AptTransaction instance. |
Create a new transaction to perform a complex package management task which allows to install, remove, upgrade or downgrade several packages at the same time.
The version number and target release of the packages can be specified using the traditional apt-get syntax, e.g. “xterm=281.1” to force installing the version 281.1 of xterm or “xterm/experimental” to force installing xterm from the experimental release.
Parameters: |
|
---|---|
Raises : | dbus.DBusException |
Returns: | An AptTransaction instance. |
Create a new transaction to enable the component of the distribution repository.
Parameters: |
|
---|---|
Raises : | dbus.DBusException |
Returns: | An AptTransaction instance. |
Create a new transaction to fix unsatisfied dependencies of already installed packages.
Corresponds to the apt-get -f install call.
Parameters: |
|
---|---|
Raises : | dbus.DBusException |
Returns: | An AptTransaction instance. |
Create a new transaction to complete a previous interrupted installation.
Corresponds to the dpkg --confgiure -a call.
Parameters: |
|
---|---|
Raises : | dbus.DBusException |
Returns: | An AptTransaction instance. |
Get the list of the installed vendor keys which are used to authenticate packages.
Parameters: |
|
---|---|
Raises : | dbus.DBusException |
Returns: | Fingerprints of all installed vendor keys. |
Create a new transaction to install a local package file.
Parameters: |
|
---|---|
Raises : | dbus.DBusException |
Returns: | An AptTransaction instance. |
Create a new transaction to install the given packages from the reporitories.
The version number and target release of the packages can be specified using the traditional apt-get syntax, e.g. “xterm=281.1” to force installing the version 281.1 of xterm or “xterm/experimental” to force installing xterm from the experimental release.
Parameters: |
|
---|---|
Raises : | dbus.DBusException |
Returns: | An AptTransaction instance. |
Create a new transaction to reconfigure already installed packages.
Corresponds to the dpkg-reconfigure call.
Parameters: |
|
---|---|
Raises : | dbus.DBusException |
Returns: | An AptTransaction instance. |
Create a new transaction to remove installed packages.
Parameters: |
|
---|---|
Raises : | dbus.DBusException |
Returns: | An AptTransaction instance. |
Create a new transaction to remove the key of a software vendor from the list of trusted ones.
The key is used to authenticate the origin of packages.
Parameters: |
|
---|---|
Raises : | dbus.DBusException |
Returns: | An AptTransaction instance. |
Create a new transaction to update the package cache.
The repositories will be queried for installable packages.
Parameters: |
|
---|---|
Raises : | dbus.DBusException |
Returns: | An AptTransaction instance. |
Create a new transaction to upgrade installed packages.
The version number and target release of the packages can be specified using the traditional apt-get syntax, e.g. “xterm=281.1” to force installing the version 281.1 of xterm or “xterm/experimental” to force installing xterm from the experimental release.
Parameters: |
|
---|---|
Raises : | dbus.DBusException |
Returns: | An AptTransaction instance. |
Create a new transaction to apply all avaibale upgrades.
Parameters: |
|
---|---|
Raises : | dbus.DBusException |
Returns: | An AptTransaction instance. |
Represents an aptdaemon transaction.
Note
This class cannot be inherited since it makes use of a metaclass.
The signal is emitted when allow_unauthenticated changed.
Param allow: | If unauthenticated packages are allowed to be installed. |
---|
The signal is emitted when cancellable changed.
Param cancellable: | |
---|---|
If the transaction can be cancelled now. |
The signal is emitted when config_file_conflict changed.
Param cur: | The path to the current configuration file. |
---|---|
Param new: | The path to the new configuration file. |
The signal is emitted when debconf_socket changed.
Param path: | The path to the socket which will be used to forward debconf communication to the user session. |
---|
The signal is emitted when dependencies changed.
Most likely after simulate() was called.
Param installs: | List of package which will be installed. |
---|---|
Param reinstalls: | |
List of package which will be re-installed. | |
Param removals: | List of package which will be removed, |
Param purges: | List of package which will be removed including configuration files. |
Param upgrades: | List of package which will be upgraded. |
Param downgrades: | |
List of package which will be downgraded to an older version. | |
Param kepts: | List of package which will be skipped from upgrading. |
The signal is emitted when download changed.
Param download: | Download size integer in Bytes. |
---|
The signal is emitted when an error occured.
Param error_code: | |
---|---|
The error code enumeration, e.g. aptdaemon.enums.ERROR_NO_CACHE. | |
Param error_details: | |
The error description string. |
The signal is emitted when the transaction is completed or has failed.
Param exit_state: | |
---|---|
The exit status enumeration string. |
The signal is emitted when http_proxy changed.
Param uri: | The URI of the proxy server, e.g. “http://proxy:8080”. |
---|
The signal is emitted when locale changed.
Param locale: | The language which should be used for messages, eg. “de_DE”. |
---|
The signal is emitted when meta_data changed.
Param meta_data: | |
---|---|
The latest meta data dictionary. |
The signal is emitted when required_medium changed.
Param name: | The name of the volume. |
---|---|
Param device: | The path of the device in which the volume should be inserted. |
The signal is emitted when remove_obsoleted_depends changed.
Param remove: | If obsolete dependencies should also be removed. |
---|
The signal is emitted when role changed.
Param role: | The new role enum, e.g. ROLE_UPDATE_CACHE. |
---|
The signal is emitted when space changed. Most likely after simulate() was called.
Param space: | Required disk space integer in Bytes. Can be negative if disk space will be freed. |
---|
The signal is emitted when packages changed.
Param installs: | List of package which will be installed. |
---|---|
Param reinstalls: | |
List of package which will be re-installed. | |
Param removals: | List of package which will be removed, |
Param purges: | List of package which will be removed including configuration files. |
Param upgrades: | List of package which will be upgraded. |
Param downgrades: | |
List of package which will be downgraded to an older version. |
The signal is emitted when progress changed.
Param progress: | The progress integer. |
---|
The signal is emitted when detailed information of the progress is available.
Param current_items: | |
---|---|
The number of already processed items. | |
Param total_items: | |
The number of all items. | |
Param current_bytes: | |
The number of already downloaded byte. | |
Param total_bytes: | |
The number of bytes which have to be downloaded totally. | |
Param current_cps: | |
The current download speed in bytes per second. | |
Param eta: | The elapsed time in seconds to accomplish the task. |
The signal is emitted when progress information about a single download is available.
Param uri: | The URI of the file which is downloaded. |
---|---|
Param status: | The status of the downloade, e.g. DOWNLOAD_AUTH_FAILED. |
Param short_desc: | |
A short description of the file. | |
Param total_size: | |
The size of the file in Bytes. | |
Param current_size: | |
How much of the file in Bytes has already be downloaded. | |
Param msg: | The status or error description. |
The signal is emitted when terminal changed.
Param path: | The path to the slave end of the controlling terminal for the underlying dpkg call. |
---|
The signal is emitted when term_attached changed.
Param attached: | If the controlling terminal can be used. |
---|
The signal is emitted when unauthenticated changed.
Param unauthenticated: | |
---|---|
List of unauthenticated packages. |
If the transaction can be currently cancelled.
If there is a conflict in the configuration file handling during an installation this attribute contains a tuple of the path to the current and the new temporary configuration file.
The resolve_config_file_conflict() can be used to resolve the conflict and continue the processing of the transaction.
List of dependencies lists in the following order: packages to install, to re-install, to remove, to purge, to upgrade, to downgrade and to keep.
You have to call simulate() to calculate the dependencies before the transaction will be executed.
The number of Bytes which have to be downloaed.
You have to call simulate() to calculate the download size before the transaction will be executed.
In the case of a failed transaction this attribute holds the corresponding errors.TransactionFailed instance.
In the case of a failed transaction this attribute is set to the underlying error code, e.g. enums.ERROR_PACKAGE_DOWNLOAD_FAILED.
In the case of a failed transaction this attribute contains a detailed error message in the language of the transaction.
Contains the exit status enum if the transaction has been completed, e.g. enums.EXIT_SUCCESS or enums.EXIT_FAILED.
The URI to the http proxy server which should be used only for this transaction, e.g. “http://proxy:8080”. It is recommended to set the system wide proxy server instead of setting this attribute for every transaction.
See set_http_proxy().
Dictionary of optional meta data which can be set by client applications. See set_meta_data().
List of package lists which will be explicitly changed in the following order: packages to install, to re-install, to remove, to purge, to upgrade, to downgrade.
If the transaction is currently paused, e.g. it is required to insert a medium to install from.
An integer ranging from 0 to 101 to describe the progress of the transaction.
Note
A value of 101 indicates that there cannot be made any assumptions on the progress of the transaction.
If dependencies which have been required by a removed package only should be removed, too.
If a medium should be inserted to continue the fetch phase of a transaction, this attribute contains a tuple of the device path of of the drive which should be used and secondly of the name of the medium.
The provide_medium() method should be used to notify aptdaemon about an inserted medium and to continue processing the transaction.
The kind of action which is performed by the transaction, e.g. enums.ROLE_UPGRADE_SYSTEM.
The required disk space in Bytes. Will be negative if space is freed.
You have to call simulate() to calculate the download size before the transaction will be executed.
The enum of the current status, e.g. enums.STATUS_DOWNLOADING.
A string describing the current status of the transaction.
The unique identifier of the transaction. It is also the D-Bus path of the corresponding transaction object.
If the the package manager can be controlled using the controlling terminal specified by set_terminal().
List of packages which are going to be installed but are not downloaded from an authenticated repository.
You have to call simulate() to calculate the dependencies before the transaction will be executed.
Cancel the running transaction.
Parameters: |
|
---|---|
Raises : | aptdaemon.errors.NotAuthorizedError, dbus.DBusException |
Continue a paused transaction which waits for a medium to install from.
Parameters: |
|
---|---|
Raises : | aptdaemon.errors.ForeignTransaction, dbus.DBusException |
Continue a paused transaction which waits for the resolution of a configuration file conflict.
Parameters: |
|
---|---|
Raises : | aptdaemon.errors.ForeignTransaction, dbus.DBusException |
Queue the transaction for processing.
Parameters: |
|
---|---|
Raises : | aptdaemon.errors.TransactionFailed, dbus.DBusException |
Chain this transaction after the given one. The transaction will fail if the previous one fails.
To start processing of the chain you have to call run() of the first transaction. The others will be queued after it automatically.
Parameters: |
|
---|---|
Raises : | dbus.DBusException |
Allow to install unauthenticated packages.
Unauthenticated packages are from the repository of a vendor whose key hasn’t been installed. By default this is not allowed.
Parameters: |
|
---|---|
Raises : | aptdaemon.errors.ForeignTransaction, dbus.DBusException |
Setup a debconf frontend to answer questions of the maintainer scripts.
Debian allows packages to interact with the user during installation, configuration and removal phase via debconf. Aptdaemon forwards the communication to a debconf instance running as the user of the client application.
Parameters: |
|
---|---|
Raises : | aptdaemon.errors.ForeignTransaction, dbus.DBusException |
Use the given http proxy for downloading packages in this transaction.
Parameters: |
|
---|---|
Raises : | aptdaemon.errors.NotAuthorizedError, dbus.DBusException aptdaemon.errors.ForeignTransaction, |
Set the language for status and error messages.
Parameters: |
|
---|---|
Raises : | aptdaemon.errors.ForeignTransaction, dbus.DBusException |
Store additional meta information of the transaction in the MetaData property of the transaction.
The method accepts key=value pairs. The key has to be prefixed with an underscore separated identifier of the client application.
In the following example Software-Center sets an application name and icon:
>>> Transaction.set_meta_data(sc_icon="shiny", sc_app="xterm")
Parameters: |
|
---|---|
Raises : | aptdaemon.errors.ForeignTransaction, dbus.DBusException |
Include no longer required dependencies which have been installed automatically when removing packages.
Parameters: |
|
---|---|
Raises : | aptdaemon.errors.ForeignTransaction, dbus.DBusException |
Allow to set a controlling terminal for the underlying dpkg call.
See the source code of gtkwidgets.AptTerminal or console.ConsoleClient as example.
>>> master, slave = pty.openpty()
>>> transaction.set_terminal(os.ttyname(slave))
Parameters: |
|
---|---|
Raises : | aptdaemon.errors.ForeignTransaction, dbus.DBusException |
Simulate the transaction to calculate the dependencies, the required download size and the required disk space.
The corresponding properties of the AptTransaction will be updated.
Parameters: |
|
---|---|
Raises : | aptdaemon.errors.TransactionFailed, dbus.DBusException |
Sync the properties of the transaction with the daemon.
This method is called automatically on the creation of the AptTransaction instance.
Parameters: |
|
---|---|
Raises : | dbus.DBusException |
Get an existing transaction by its identifier.
Parameters: |
|
---|---|
Raises : | dbus.DBusException |
Returns: | An AptTransaction instance. |
Get the daemon D-Bus interface.
Parameters: | bus – Optionally the D-Bus on which aptdaemon listens. Defaults to the system bus. |
---|---|
Raises : | dbus.DBusException |
Returns: | An dbus.Interface instance. |