After having introduced you how to match a package inside Entropy Client repositories. Let’s see how to calculate install dependencies in order to prepare the installation on the live system. As usual, Python code will follow.
Let’s say we want to install two packages: media-sound/audacious and app-office/libreoffice. How do we build up an install schedule?
First of all we need to match the two packages against the available repositories and build up a list of package matches.
from entropy.client.interfaces import Client
entropy_client = Client()
package_matches = []
for dep in (“media-sound/audacious”, “app-office/libreoffice”):
pkg_id, repo_id = entropy_client.atom_match(dep)
if pkg_id != -1:
package_matches.append((pkg_id, repo_id))
Now that we filled package_matches, we need to ask Entropy to calculate the install queue (or schedule):
install_queue, conflicts_queue, exit_st = \
entropy_client.get_install_queue(package_matches, False, False)
if exit_st == 0:
print(“This is the queue:”)
for pkg_id, repo_id in install_queue:
repo = entropy_client.open_repository(repo_id)
print(repo.retrieveAtom(pkg_id))
elif exit_st == -2:
print(“conflicts detected in the queue:”)
print(“, “.join(install_queue))
elif exit_st == -3:
print(“dependencies not found:”)
print(“, “.join(install_queue))
else:
print(“unknown error”)
entropy_client.shutdown()
“conflicts_queue” represents a list of package identifiers coming from the installed packages repository that should be removed. This is purely informative, since anything listed there will be removed automatically upon package install, during the execution of the schedule (not yet covered).
The core code is just about 3 lines, the rest is error checking. I’ll show you how to actually install a schedule in the next “quick&dirty” tutorial.
Just in case someone wants to try it…
entropy_client.get_install_queue needs two more parameters: empty and deep (Boolean ones).
Thanks, however, nice tutorial!
thanks! Fixed
I like what you’re doing here lxnay. As a programmer who only dabbles in python here and there, these tutorials could definitely go a long way towards perhaps making myself useful someday to the Entropy cause.
How come you’re using status codes instead of exceptions?
Exceptions are wrapped behind that method. the API is not stable yet and subject to change (and this is probably a good one).
Pingback: Entropy API Tutorial #3: installing packages « On The Other Hand