I am working on the Snap! C++ project which manages many packages with a complex set of dependencies (see picture below).
So as a result I need the build of package A to be complete before I can run the build of package B. I'd like to at least semi-automate the build process and for that I would need to know, programmatically, that package A is done building. I can then verify that the build worked (that I know how to do) and if so, I can send the sources of package B and get that build started.
I found pages about the Launchpad API and I downloaded the python scripts that they offer to access the server. However, I'm not that good in python and I'm not too sure what API call I need to use. I found this huge page with what I would assume are all the calls, but I was not able to find a simple example of how to get the current build status for a specific project. Maybe getBuildQueueSizes
? But looking at the launchpadlib
Python project files, I could not find any such name in the code. So I'm not too sure how that works.
Would you have sample code you would share with us that does at least that much? Or a place where there would be an example on the Launchpad.net website?
At this point, my script connects... what do I do next?
# See API here# https://launchpad.net/+apidoc/devel.htmlfrom launchpadlib.launchpad import Launchpadfrom os.path import expanduserhome = expanduser('~')cachedir = home +'/.launchpadlib/cache/'launchpad = Launchpad.login_anonymously('snapcpp', 'production', cachedir, version='devel')
If possible too, just a URI would be great. From what I can see here and there, it would be possible to simply emit an HTTP GET
to a URI and get a JSON in return with all the necessary info. What I don't see is what that URI would be. I tried several from what I've see in the docs (with super heavy examples... NOT):
https://api.launchpad.net/devel/snapcpp?ws.op=getBuildRecords&source_name=libtld
This one tells me that getBuildRecords
is not a command. In most cases, though, I get a 400 or 404. The project URL works, but all the links shown in the JSON do not help:
https://api.launchpad.net/devel/snapcpp
Testing some more, I found out I could search some builds with:
https://api.launchpad.net/devel/ubuntu/bionic?ws.op=getBuildRecords&source_name=lib
But if I try to use my project names as the source_name=...
parameter (a.k.a. "libtld" or "snapcpp"), it returns an empty list. This last URL also works with just /ubuntu?...
or with an architecture /ubuntu/bionic/amd64?...
. But that doesn't help.
I think this may be a bug so I reported on Launchpad.
Image may be NSFW.
Clik here to view.
Update
This is now implemented¹. If you're interested about the exact implementation, please check the snapbuilder tool.
There is one important point I wanted to bring up here:
The building process is marked as "done" before the packages are made available. So only relying on the API to know whether the build is done, is not sufficient. As a result I've actually added a new stage in the snapbuilder tool: "Packaging". This state is active when the package was marked as successfully built and attempting to download the new packages (I used a HEAD instead of a GET to avoid the actual download from the tool) returns an error. Once both of those flags are true, then I mark my project as "Built".
The code shows you how I do that. More or less, I reuse the same URL and tweak it with the + version + architecture. Nothing too complicated. As long as the HEAD
returns a 404 or similar error, then the package is not yet available.
This is very important if you want to daisy chain builds since the next project will fail building if the packages are not yet available (or use the old version, which we do not want).
¹ Actually, at time of writing, I still have one bug. The name of the package is guessed as being the same the as the name of the project. Instead we need to look at the names in the control file. That's the next and (hopefully) last step.